-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: persist sidebar open/close state #17559
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## new-navigation #17559 +/- ##
==================================================
- Coverage 46.50% 46.32% -0.18%
==================================================
Files 768 770 +2
Lines 25020 25140 +120
Branches 5745 5756 +11
==================================================
+ Hits 11635 11646 +11
- Misses 11927 12031 +104
- Partials 1458 1463 +5 |
src/script/page/LeftSidebar/panels/Conversations/Conversations.tsx
Outdated
Show resolved
Hide resolved
setIsSidebarOpen(!mdBreakpoint); | ||
}, [mdBreakpoint, setIsSidebarOpen]); | ||
if (sideBarOpenStatus !== SidebarOpenStatus.MANUAL_OPEN && sideBarOpenStatus !== SidebarOpenStatus.MANUAL_CLOSED) { | ||
setSidebarOpenStatus(mdBreakpoint ? SidebarOpenStatus.CLOSED : SidebarOpenStatus.OPEN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we don't care if status was SidebarOpenStatus.CLOSED
or SidebarOpenStatus.OPEN
, so if we will use instead of those two one SidebarOpenStatus.AUTO
to persist status and true/false for openStatus
, we can write here
if (sideBarOpenStatus === SidebarOpenStatus.AUTO) {
setSidebarOpenStatus(!mdBreakpoint);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep agreed. Actually a useEffect
is not even needed here since there are no effects in there.
The entire code should be something like
const mdBreaking = ...
const sideBarOpen = sidebarStatus === AUTO ? mdBreaking : sidebarStatus === OPEN;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in f83d6e8
isOpen: boolean; | ||
setIsOpen: (isOpen: boolean) => void; | ||
toggleIsOpen: () => void; | ||
openStatus: SidebarOpenStatus; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openStatus
is never set to MANUAL_...
statuses, right? - then I'd set it to boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in f83d6e8
export const SidebarOpenStatus = { | ||
OPEN: 'OPEN', | ||
CLOSED: 'CLOSED', | ||
MANUAL_OPEN: 'MANUAL_OPEN', | ||
MANUAL_CLOSED: 'MANUAL_CLOSED', | ||
} as const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @svitovyda suggested, this can be simplified to
{
OPEN, // When the user has decided to open manually
CLOSED, // when the user has decided to manually close
AUTO, // Will automatically adapt to the screen size
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in f83d6e8
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks solid 😎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
Persist Sidebar Open/Close State
This pull request introduces a feature to persist the open/close state of the sidebar across sessions. The state is saved to
localStorage
using Zustand'spersist
middleware. This ensures that the sidebar retains its state even after a page refresh or browser restart.Changes
Define Sidebar Open Status Constants:
SidebarOpenStatus
as an object withOPEN
,CLOSED
,MANUAL_OPEN
, andMANUAL_CLOSED
states.SidebarOpenStatus
for better TypeScript support.Update Zustand Store:
openStatus
to track the sidebar's state.openStatus
.persist
middleware to store theopenStatus
inlocalStorage
.Update Sidebar Component:
useEffect
hook to respect the manually setopenStatus
.openStatus
and screen size breakpoint.Screenshots/Screencast (for UI changes)
REC-20240612162615.mp4