From 8e1473c3d801e01f9180129186285090cfd33c8d Mon Sep 17 00:00:00 2001 From: David <42793498+dncc89@users.noreply.github.com> Date: Tue, 4 Jul 2023 05:26:00 +0900 Subject: [PATCH] feature: ChatGPT style show/hide panel button, panel state saving in local storage (#575) * Add nav bar state saving to local storage * Add ChatGPT style hide side panel button --- client/src/components/Nav/NewChat.jsx | 2 +- client/src/components/Nav/index.jsx | 56 ++++++++++++++------------- client/src/components/svg/Panel.jsx | 8 ++-- client/src/mobile.css | 14 +++++-- client/src/routes/Root.jsx | 25 ++++++++---- 5 files changed, 61 insertions(+), 44 deletions(-) diff --git a/client/src/components/Nav/NewChat.jsx b/client/src/components/Nav/NewChat.jsx index 811ff1528c..5effd970a5 100644 --- a/client/src/components/Nav/NewChat.jsx +++ b/client/src/components/Nav/NewChat.jsx @@ -13,7 +13,7 @@ export default function NewChat() { return ( { if (isMobile()) { setNavVisible(false); - } else { - setNavVisible(true); } }, [conversationId, setNavVisible]); @@ -181,10 +180,19 @@ export default function Nav({ navVisible, setNavVisible }) {
- {!navVisible && ( )} diff --git a/client/src/components/svg/Panel.jsx b/client/src/components/svg/Panel.jsx index c82a2ec461..561ea5ed39 100644 --- a/client/src/components/svg/Panel.jsx +++ b/client/src/components/svg/Panel.jsx @@ -4,8 +4,8 @@ export default function Panel({ open = false, className }) { const openPanel = ( { + const savedNavVisible = localStorage.getItem('navVisible'); + return savedNavVisible !== null ? JSON.parse(savedNavVisible) : false; + }); const setIsSearchEnabled = useSetRecoilState(store.isSearchEnabled); const setEndpointsConfig = useSetRecoilState(store.endpointsConfig); @@ -24,6 +29,10 @@ export default function Root() { const endpointsQuery = useGetEndpointsQuery(); const presetsQuery = useGetPresetsQuery({ enabled: !!user }); + useEffect(() => { + localStorage.setItem('navVisible', JSON.stringify(navVisible)); + }, [navVisible]); + useEffect(() => { if (endpointsQuery.data) { setEndpointsConfig(endpointsQuery.data);