mirror of
https://github.com/johndoe6345789/low-code-react-app-b.git
synced 2026-04-28 07:34:56 +00:00
Refactor app layout structure
This commit is contained in:
15
src/hooks/use-app-navigation.ts
Normal file
15
src/hooks/use-app-navigation.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useEffect } from 'react'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
|
||||
import { useRouterNavigation } from '@/hooks/use-router-navigation'
|
||||
|
||||
export default function useAppNavigation() {
|
||||
const location = useLocation()
|
||||
const { currentPage, navigateToPage } = useRouterNavigation()
|
||||
|
||||
useEffect(() => {
|
||||
console.log('[APP_ROUTER] 📍 Route changed to:', location.pathname, '- Page:', currentPage)
|
||||
}, [currentPage, location.pathname])
|
||||
|
||||
return { currentPage, navigateToPage }
|
||||
}
|
||||
147
src/hooks/use-app-project.ts
Normal file
147
src/hooks/use-app-project.ts
Normal file
@@ -0,0 +1,147 @@
|
||||
import { useMemo } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import appStrings from '@/data/app-shortcuts.json'
|
||||
import { useFileOperations } from '@/hooks/use-file-operations'
|
||||
import { useProjectState } from '@/hooks/use-project-state'
|
||||
import type { Project } from '@/types/project'
|
||||
export default function useAppProject() {
|
||||
const projectState = useProjectState()
|
||||
const {
|
||||
files,
|
||||
models,
|
||||
components,
|
||||
componentTrees,
|
||||
workflows,
|
||||
lambdas,
|
||||
theme,
|
||||
playwrightTests,
|
||||
storybookStories,
|
||||
unitTests,
|
||||
flaskConfig,
|
||||
nextjsConfig,
|
||||
npmSettings,
|
||||
featureToggles,
|
||||
setFiles,
|
||||
setModels,
|
||||
setComponents,
|
||||
setComponentTrees,
|
||||
setWorkflows,
|
||||
setLambdas,
|
||||
setTheme,
|
||||
setPlaywrightTests,
|
||||
setStorybookStories,
|
||||
setUnitTests,
|
||||
setFlaskConfig,
|
||||
setNextjsConfig,
|
||||
setNpmSettings,
|
||||
setFeatureToggles,
|
||||
} = projectState
|
||||
|
||||
const fileOps = useFileOperations(files, setFiles)
|
||||
const currentProject = useMemo<Project>(
|
||||
() => ({
|
||||
name: nextjsConfig.appName,
|
||||
files,
|
||||
models,
|
||||
components,
|
||||
componentTrees,
|
||||
workflows,
|
||||
lambdas,
|
||||
theme,
|
||||
playwrightTests,
|
||||
storybookStories,
|
||||
unitTests,
|
||||
flaskConfig,
|
||||
nextjsConfig,
|
||||
npmSettings,
|
||||
featureToggles,
|
||||
}),
|
||||
[
|
||||
componentTrees,
|
||||
components,
|
||||
featureToggles,
|
||||
files,
|
||||
flaskConfig,
|
||||
lambdas,
|
||||
models,
|
||||
nextjsConfig,
|
||||
npmSettings,
|
||||
playwrightTests,
|
||||
storybookStories,
|
||||
theme,
|
||||
unitTests,
|
||||
workflows,
|
||||
]
|
||||
)
|
||||
const handleProjectLoad = (project: Project) => {
|
||||
if (project.files) setFiles(project.files)
|
||||
if (project.models) setModels(project.models)
|
||||
if (project.components) setComponents(project.components)
|
||||
if (project.componentTrees) setComponentTrees(project.componentTrees)
|
||||
if (project.workflows) setWorkflows(project.workflows)
|
||||
if (project.lambdas) setLambdas(project.lambdas)
|
||||
if (project.theme) setTheme(project.theme)
|
||||
if (project.playwrightTests) setPlaywrightTests(project.playwrightTests)
|
||||
if (project.storybookStories) setStorybookStories(project.storybookStories)
|
||||
if (project.unitTests) setUnitTests(project.unitTests)
|
||||
if (project.flaskConfig) setFlaskConfig(project.flaskConfig)
|
||||
if (project.nextjsConfig) setNextjsConfig(project.nextjsConfig)
|
||||
if (project.npmSettings) setNpmSettings(project.npmSettings)
|
||||
if (project.featureToggles) setFeatureToggles(project.featureToggles)
|
||||
toast.success(appStrings.messages.projectLoaded)
|
||||
}
|
||||
const stateContext = {
|
||||
files,
|
||||
models,
|
||||
components,
|
||||
componentTrees,
|
||||
workflows,
|
||||
lambdas,
|
||||
theme,
|
||||
playwrightTests,
|
||||
storybookStories,
|
||||
unitTests,
|
||||
flaskConfig,
|
||||
nextjsConfig,
|
||||
npmSettings,
|
||||
featureToggles,
|
||||
activeFileId: fileOps.activeFileId,
|
||||
}
|
||||
const actionContext = {
|
||||
handleFileChange: fileOps.handleFileChange,
|
||||
setActiveFileId: fileOps.setActiveFileId,
|
||||
handleFileClose: fileOps.handleFileClose,
|
||||
handleFileAdd: fileOps.handleFileAdd,
|
||||
setModels,
|
||||
setComponents,
|
||||
setComponentTrees,
|
||||
setWorkflows,
|
||||
setLambdas,
|
||||
setTheme,
|
||||
setPlaywrightTests,
|
||||
setStorybookStories,
|
||||
setUnitTests,
|
||||
setFlaskConfig,
|
||||
setNextjsConfig,
|
||||
setNpmSettings,
|
||||
setFeatureToggles,
|
||||
}
|
||||
|
||||
return {
|
||||
files,
|
||||
models,
|
||||
components,
|
||||
componentTrees,
|
||||
workflows,
|
||||
lambdas,
|
||||
playwrightTests,
|
||||
storybookStories,
|
||||
unitTests,
|
||||
featureToggles,
|
||||
fileOps,
|
||||
currentProject,
|
||||
handleProjectLoad,
|
||||
stateContext,
|
||||
actionContext,
|
||||
}
|
||||
}
|
||||
71
src/hooks/use-app-shortcuts.ts
Normal file
71
src/hooks/use-app-shortcuts.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { useState } from 'react'
|
||||
|
||||
import appStrings from '@/data/app-shortcuts.json'
|
||||
import { getPageShortcuts } from '@/config/page-loader'
|
||||
import { useKeyboardShortcuts } from '@/hooks/use-keyboard-shortcuts'
|
||||
import type { FeatureToggles } from '@/types/project'
|
||||
|
||||
interface UseAppShortcutsParams {
|
||||
featureToggles: FeatureToggles
|
||||
navigateToPage: (page: string) => void
|
||||
}
|
||||
|
||||
export default function useAppShortcuts({
|
||||
featureToggles,
|
||||
navigateToPage,
|
||||
}: UseAppShortcutsParams) {
|
||||
const [searchOpen, setSearchOpen] = useState(false)
|
||||
const [shortcutsOpen, setShortcutsOpen] = useState(false)
|
||||
const [previewOpen, setPreviewOpen] = useState(false)
|
||||
|
||||
const shortcuts = getPageShortcuts(featureToggles)
|
||||
|
||||
useKeyboardShortcuts([
|
||||
...shortcuts.map(s => ({
|
||||
key: s.key,
|
||||
ctrl: s.ctrl,
|
||||
shift: s.shift,
|
||||
description: s.description,
|
||||
action: () => {
|
||||
console.log('[APP_ROUTER] ⌨️ Shortcut triggered, navigating to:', s.action)
|
||||
navigateToPage(s.action)
|
||||
},
|
||||
})),
|
||||
{
|
||||
key: 'k',
|
||||
ctrl: true,
|
||||
description: appStrings.shortcuts.search,
|
||||
action: () => {
|
||||
console.log('[APP_ROUTER] ⌨️ Search shortcut triggered')
|
||||
setSearchOpen(true)
|
||||
},
|
||||
},
|
||||
{
|
||||
key: '/',
|
||||
ctrl: true,
|
||||
description: appStrings.shortcuts.shortcuts,
|
||||
action: () => {
|
||||
console.log('[APP_ROUTER] ⌨️ Shortcuts dialog triggered')
|
||||
setShortcutsOpen(true)
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'p',
|
||||
ctrl: true,
|
||||
description: appStrings.shortcuts.preview,
|
||||
action: () => {
|
||||
console.log('[APP_ROUTER] ⌨️ Preview shortcut triggered')
|
||||
setPreviewOpen(true)
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
return {
|
||||
searchOpen,
|
||||
setSearchOpen,
|
||||
shortcutsOpen,
|
||||
setShortcutsOpen,
|
||||
previewOpen,
|
||||
setPreviewOpen,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user