Skip to content

Commit

Permalink
refactor(sidebarMenu): created util for isExpanded inital value
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukeybooi committed Jul 6, 2023
1 parent 2d6058f commit a462693
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 2 additions & 3 deletions shesha-reactjs/src/providers/sidebarMenu/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { IFlagsSetters } from '../../interfaces/flagsSetters';
import { IFlagsState } from '../../interfaces/flagsState';
import { ISidebarMenuItem } from '../../interfaces/sidebar';
import { IHeaderAction } from './models';
import { getLocalStorage } from 'utils/storage';
import { SIDEBAR_COLLAPSE } from 'components/mainLayout/constant';
import { getInitIsExpanded } from './util';

export type IFlagProgressFlags = 'fetchFileInfo' /* NEW_IN_PROGRESS_FLAG_GOES_HERE */;
export type IFlagSucceededFlags = 'fetchFileInfo' /* NEW_SUCCEEDED_FLAG_GOES_HERE */;
Expand Down Expand Up @@ -32,7 +31,7 @@ export const SIDEBAR_MENU_CONTEXT_INITIAL_STATE: ISidebarMenuStateContext = {
succeeded: {},
error: {},
actioned: {},
isExpanded: !JSON.parse(getLocalStorage()?.getItem(SIDEBAR_COLLAPSE)),
isExpanded: getInitIsExpanded(),
};

export const SidebarMenuStateContext = createContext<ISidebarMenuStateContext>(SIDEBAR_MENU_CONTEXT_INITIAL_STATE);
Expand Down
13 changes: 13 additions & 0 deletions shesha-reactjs/src/providers/sidebarMenu/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SIDEBAR_COLLAPSE } from 'components/mainLayout/constant';
import { isJsonParseable } from 'utils/multitenancy';
import { getLocalStorage } from 'utils/storage';

export const getInitIsExpanded = () => {
try {
const value = getLocalStorage()?.getItem(SIDEBAR_COLLAPSE);
const result = isJsonParseable(value) ? JSON.parse(value) : true;
return !result;
} catch (_e) {
return false;
}
};

0 comments on commit a462693

Please sign in to comment.