-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UI): janhq#1404 make left side bar collapsible by hot key (janhq…
…#1420) Signed-off-by: James <[email protected]> Co-authored-by: James <[email protected]>
- Loading branch information
Showing
6 changed files
with
160 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use client' | ||
|
||
import { Fragment, ReactNode, useEffect } from 'react' | ||
|
||
import { atom, useSetAtom } from 'jotai' | ||
|
||
import { MainViewState } from '@/constants/screens' | ||
|
||
import { useMainViewState } from '@/hooks/useMainViewState' | ||
|
||
type Props = { | ||
children: ReactNode | ||
} | ||
|
||
export const showLeftSideBarAtom = atom<boolean>(true) | ||
export const showSelectModelModalAtom = atom<boolean>(false) | ||
export const showCommandSearchModalAtom = atom<boolean>(false) | ||
|
||
export default function KeyListener({ children }: Props) { | ||
const setShowLeftSideBar = useSetAtom(showLeftSideBarAtom) | ||
const setShowSelectModelModal = useSetAtom(showSelectModelModalAtom) | ||
const { setMainViewState } = useMainViewState() | ||
const showCommandSearchModal = useSetAtom(showCommandSearchModalAtom) | ||
|
||
useEffect(() => { | ||
const onKeyDown = (e: KeyboardEvent) => { | ||
e.preventDefault() | ||
const prefixKey = isMac ? e.metaKey : e.ctrlKey | ||
|
||
if (e.key === 'b' && prefixKey) { | ||
setShowLeftSideBar((showLeftSideBar) => !showLeftSideBar) | ||
return | ||
} | ||
|
||
if (e.key === 'e' && prefixKey) { | ||
setShowSelectModelModal((show) => !show) | ||
return | ||
} | ||
|
||
if (e.key === ',' && prefixKey) { | ||
setMainViewState(MainViewState.Settings) | ||
return | ||
} | ||
|
||
if (e.key === 'k' && prefixKey) { | ||
showCommandSearchModal((show) => !show) | ||
return | ||
} | ||
} | ||
document.addEventListener('keydown', onKeyDown) | ||
return () => document.removeEventListener('keydown', onKeyDown) | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []) | ||
|
||
return <Fragment>{children}</Fragment> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.