mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
* refactor: consolidate git services into single GitService class Merges GitBranchService, GitCommitService, GitDiffService, GitFetchPullService, GitLogService, GitPushService, and GitStatusService into one cohesive GitService that simplifies architecture and follows SOLID principles. Updates all route handlers and tests to use the new consolidated service. Moves GitBranch interface to shared types location. * Refactor settings dialog to use URL-based state management with tab synchronization * Update social preview image
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { useCallback } from 'react'
|
|
import { useNavigate, useLocation } from 'react-router-dom'
|
|
|
|
type Tab = 'account' | 'general' | 'notifications' | 'voice' | 'git' | 'shortcuts' | 'opencode' | 'providers' | 'menu'
|
|
|
|
interface UseSettingsDialogUrlReturn {
|
|
isOpen: boolean
|
|
open: () => void
|
|
close: () => void
|
|
toggle: () => void
|
|
activeTab: Tab
|
|
setActiveTab: (tab: Tab) => void
|
|
}
|
|
|
|
export function useSettingsDialogUrl(): UseSettingsDialogUrlReturn {
|
|
const navigate = useNavigate()
|
|
const location = useLocation()
|
|
|
|
const searchParams = new URLSearchParams(location.search)
|
|
const isOpen = searchParams.get('settings') === 'open'
|
|
const activeTab = (searchParams.get('tab') as Tab) || 'menu'
|
|
|
|
const open = useCallback(() => {
|
|
const newParams = new URLSearchParams(location.search)
|
|
newParams.set('settings', 'open')
|
|
newParams.set('tab', activeTab)
|
|
navigate({ search: newParams.toString() }, { replace: true })
|
|
}, [activeTab, navigate, location.search])
|
|
|
|
const close = useCallback(() => {
|
|
const newParams = new URLSearchParams(location.search)
|
|
newParams.delete('settings')
|
|
newParams.delete('tab')
|
|
navigate({ search: newParams.toString() }, { replace: true })
|
|
}, [navigate, location.search])
|
|
|
|
const toggle = useCallback(() => {
|
|
if (isOpen) {
|
|
close()
|
|
} else {
|
|
open()
|
|
}
|
|
}, [isOpen, open, close])
|
|
|
|
const setActiveTab = useCallback((tab: Tab) => {
|
|
const newParams = new URLSearchParams(location.search)
|
|
newParams.set('settings', 'open')
|
|
newParams.set('tab', tab)
|
|
navigate({ search: newParams.toString() }, { replace: true })
|
|
}, [navigate, location.search])
|
|
|
|
return {
|
|
isOpen,
|
|
open,
|
|
close,
|
|
toggle,
|
|
activeTab,
|
|
setActiveTab,
|
|
}
|
|
}
|