Skip to content

Commit

Permalink
fix persistence issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cemms1 committed Jan 8, 2025
1 parent f3ffb26 commit 82c31e0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions dotcom-rendering/src/components/ShowHideButton.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const getContainerStates = (): ContainerStates => {
* Component to toggle the visibility of a front container. Used within FrontSection.
**/
export const ShowHideButton = ({ sectionId }: Props) => {
const [isExpanded, setIsExpanded] = useState(true);
const [containerStates, setContainerStates] = useState<ContainerStates>({});
const [isExpanded, setIsExpanded] = useState(true);
const textShowHide = isExpanded ? 'Hide' : 'Show';
const isSignedIn = useIsSignedIn();

Expand All @@ -58,12 +58,21 @@ export const ShowHideButton = ({ sectionId }: Props) => {
}

storage.local.set(`gu.prefs.container-states`, containerStates);
setIsExpanded(!isExpanded);
};

useEffect(() => {
const section: Element | null =
window.document.getElementById(sectionId);

setContainerStates(getContainerStates());
}, []);

const isClosed = containerStates[sectionId] === 'closed';
setIsExpanded(!isClosed);

isClosed
? section?.classList.add('hidden')
: section?.classList.remove('hidden');
}, [containerStates, sectionId]);

return (
isSignedIn === true && (
Expand Down

0 comments on commit 82c31e0

Please sign in to comment.