refactor: extract hooks from App.tsx to improve code health (#62)

Extract vault management (useVaultSwitcher), git history loading
(useGitHistory), dialog state (useDialogs), and keyboard/command
setup (useAppCommands) into dedicated hooks. App.tsx code health
improves from 8.95 to 10.0 — all extracted hooks also score 10.0.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Luca Rossi
2026-02-25 13:31:19 +01:00
committed by GitHub
parent 131fe7dcd6
commit 558f50e610
5 changed files with 215 additions and 150 deletions

View File

@@ -3,25 +3,29 @@ import { useState, useCallback } from 'react'
export function useDialogs() {
const [showCreateTypeDialog, setShowCreateTypeDialog] = useState(false)
const [showQuickOpen, setShowQuickOpen] = useState(false)
const [showCommitDialog, setShowCommitDialog] = useState(false)
const [showCommandPalette, setShowCommandPalette] = useState(false)
const [showAIChat, setShowAIChat] = useState(false)
const [showSettings, setShowSettings] = useState(false)
const [showGitHubVault, setShowGitHubVault] = useState(false)
const openCreateType = useCallback(() => setShowCreateTypeDialog(true), [])
const closeCreateType = useCallback(() => setShowCreateTypeDialog(false), [])
const openQuickOpen = useCallback(() => setShowQuickOpen(true), [])
const closeQuickOpen = useCallback(() => setShowQuickOpen(false), [])
const openCommitDialog = useCallback(() => setShowCommitDialog(true), [])
const closeCommitDialog = useCallback(() => setShowCommitDialog(false), [])
const openCommandPalette = useCallback(() => setShowCommandPalette(true), [])
const closeCommandPalette = useCallback(() => setShowCommandPalette(false), [])
const openSettings = useCallback(() => setShowSettings(true), [])
const closeSettings = useCallback(() => setShowSettings(false), [])
const openGitHubVault = useCallback(() => setShowGitHubVault(true), [])
const closeGitHubVault = useCallback(() => setShowGitHubVault(false), [])
const toggleAIChat = useCallback(() => setShowAIChat((c) => !c), [])
return {
showCreateTypeDialog, openCreateType, closeCreateType,
showQuickOpen, openQuickOpen, closeQuickOpen,
showCommitDialog, openCommitDialog, closeCommitDialog,
showCommandPalette, openCommandPalette, closeCommandPalette,
showAIChat, toggleAIChat,
showSettings, openSettings, closeSettings,
showGitHubVault, openGitHubVault, closeGitHubVault,
}
}