diff --git a/apps/client/src/common/hooks/useScrollIntoView.tsx b/apps/client/src/common/hooks/useScrollIntoView.tsx new file mode 100644 index 000000000..1bbcdc26f --- /dev/null +++ b/apps/client/src/common/hooks/useScrollIntoView.tsx @@ -0,0 +1,15 @@ +import { useEffect, useRef } from 'react'; + +export default function useScrollIntoView(name: string, location?: string) { + const ref = useRef(null); + + useEffect(() => { + if (location && ref.current) { + if (location === name) { + ref.current.scrollIntoView({ behavior: 'smooth', block: 'center' }); + } + } + }, [location, name]); + + return ref; +} diff --git a/apps/client/src/features/app-settings/AppSettings.tsx b/apps/client/src/features/app-settings/AppSettings.tsx index 2087e198e..a8fecf708 100644 --- a/apps/client/src/features/app-settings/AppSettings.tsx +++ b/apps/client/src/features/app-settings/AppSettings.tsx @@ -12,32 +12,27 @@ import ProjectSettingsPanel from './panel/project-settings-panel/ProjectSettings import SourcesPanel from './panel/sources-panel/SourcesPanel'; import PanelContent from './panel-content/PanelContent'; import PanelList from './panel-list/PanelList'; -import { useSettingsStore } from './settingsStore'; +import useAppSettingsNavigation from './useAppSettingsNavigation'; import style from './AppSettings.module.scss'; export default function AppSettings() { - const setShowSettings = useSettingsStore((state) => state.setShowSettings); - const selectedPanel = useSettingsStore((state) => state.showSettings); - - const closeSettings = () => { - setShowSettings(null); - }; - useKeyDown(closeSettings, 'Escape'); + const { close, panel, location } = useAppSettingsNavigation(); + useKeyDown(close, 'Escape'); return (
- - - {selectedPanel === 'project' && } - {selectedPanel === 'general' && } - {selectedPanel === 'project_settings' && } - {selectedPanel === 'sources' && } - {selectedPanel === 'interface' && } - {selectedPanel === 'integrations' && } - {selectedPanel === 'about' && } - {selectedPanel === 'log' && } + + + {panel === 'project' && } + {panel === 'general' && } + {panel === 'project_settings' && } + {panel === 'sources' && } + {panel === 'interface' && } + {panel === 'integrations' && } + {panel === 'about' && } + {panel === 'log' && }
diff --git a/apps/client/src/features/app-settings/panel-list/PanelList.module.scss b/apps/client/src/features/app-settings/panel-list/PanelList.module.scss index 83f8d5d37..a0faf09e2 100644 --- a/apps/client/src/features/app-settings/panel-list/PanelList.module.scss +++ b/apps/client/src/features/app-settings/panel-list/PanelList.module.scss @@ -58,4 +58,8 @@ ul { color: $secondary-text-gray; border-left: 1px solid $white-10; font-size: $inner-section-text-size; + + &.active { + color: $blue-400; + } } diff --git a/apps/client/src/features/app-settings/panel-list/PanelList.tsx b/apps/client/src/features/app-settings/panel-list/PanelList.tsx index 90799b91c..34c939227 100644 --- a/apps/client/src/features/app-settings/panel-list/PanelList.tsx +++ b/apps/client/src/features/app-settings/panel-list/PanelList.tsx @@ -2,16 +2,18 @@ import { Fragment } from 'react'; import { isKeyEnter } from '../../../common/utils/keyEvent'; import { cx } from '../../../common/utils/styleUtils'; -import { settingPanels, SettingsOption, useSettingsStore } from '../settingsStore'; +import { PanelBaseProps, settingPanels, useSettingsStore } from '../settingsStore'; +import useAppSettingsNavigation from '../useAppSettingsNavigation'; import style from './PanelList.module.scss'; -export default function PanelList() { - const { showSettings, setShowSettings, hasUnsavedChanges } = useSettingsStore(); +interface PanelListProps extends PanelBaseProps { + selectedPanel: string; +} - const handleSelect = (panel: SettingsOption) => { - setShowSettings(panel.id); - }; +export default function PanelList({ selectedPanel, location }: PanelListProps) { + const { setLocation } = useAppSettingsNavigation(); + const { hasUnsavedChanges } = useSettingsStore(); return (