File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,6 +129,7 @@ export default function Sidebar({
129129 label = { label }
130130 icon = { < IconComponent /> }
131131 count = { checkedValues . length }
132+ id = { accessorKey }
132133 >
133134 { filterCriteria [ accessorKey as FilterCriteriaFields ]
134135 ?. map ( String )
Original file line number Diff line number Diff line change 11/* eslint-disable linebreak-style */
22/* eslint-disable react-hooks/rules-of-hooks */
33/* eslint-disable linebreak-style */
4- import { useRouter } from 'next/router' ;
54import React , {
65 type ReactElement ,
76 type ReactNode ,
87 useEffect ,
98 useState ,
9+ useRef ,
1010} from 'react' ;
1111import {
1212 Collapsible ,
@@ -20,21 +20,35 @@ interface DropdownMenuProps {
2020 icon : ReactElement ;
2121 count ?: number ;
2222 testMode ?: boolean ;
23+ id ?: string ;
2324}
2425
2526export default function DropdownMenu ( {
2627 children,
2728 label,
2829 icon,
2930 count = 0 ,
31+ id,
3032} : DropdownMenuProps ) {
3133 const [ isDropdownOpen , setIsDropdownOpen ] = useState ( false ) ;
32- const router = useRouter ( ) ;
33-
34+ const isFirstRun = useRef ( true ) ;
3435 useEffect ( ( ) => {
35- setIsDropdownOpen ( false ) ;
36- } , [ router ] ) ;
37-
36+ if ( id ) {
37+ const storedState = localStorage . getItem ( `sidebar_open_${ id } ` ) ;
38+ if ( storedState ) {
39+ setIsDropdownOpen ( storedState === 'true' ) ;
40+ }
41+ }
42+ } , [ id ] ) ;
43+ useEffect ( ( ) => {
44+ if ( id ) {
45+ if ( isFirstRun . current ) {
46+ isFirstRun . current = false ;
47+ return ;
48+ }
49+ localStorage . setItem ( `sidebar_open_${ id } ` , String ( isDropdownOpen ) ) ;
50+ }
51+ } , [ id , isDropdownOpen ] ) ;
3852 return (
3953 < div className = 'my-2 bg-slate-200 dark:bg-slate-900 p-2 rounded cursor-pointer transition-all duration-200 group' >
4054 < Collapsible open = { isDropdownOpen } onOpenChange = { setIsDropdownOpen } >
You can’t perform that action at this time.
0 commit comments