Skip to content

Commit

Permalink
Removed localstorage caching mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-Ross committed Dec 29, 2023
1 parent fa6f13f commit 3570ffe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
11 changes: 6 additions & 5 deletions lib/components/MegaMenuLayout/MegaMenuLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface MegaMenuWrapperProps extends React.PropsWithChildren {
menuBarItems?: NavMenuGroup[];
logoOverride?: () => JSX.Element;
sideActionsOverride?: () => JSX.Element;
// TODO: REmove
hidePhone?: boolean;
}

Expand All @@ -29,7 +30,7 @@ const MegaMenuLayout: React.FC<MegaMenuWrapperProps> = ({
const { menuItems } = useMenuItems(menuBarItems);

const Logo = logoOverride;
const SideActions = sideActionsOverride;
const RightSideActions = sideActionsOverride;

return (
<>
Expand Down Expand Up @@ -59,9 +60,9 @@ const MegaMenuLayout: React.FC<MegaMenuWrapperProps> = ({
</div>
<div className="flex items-center xl:hidden">
{!hidePhone && <PhoneButton className="max-sm:hidden" />}
{SideActions && (
{RightSideActions && (
<div className="max-sm:hidden">
<SideActions />
<RightSideActions />
</div>
)}
<Search />
Expand All @@ -88,9 +89,9 @@ const MegaMenuLayout: React.FC<MegaMenuWrapperProps> = ({
/>
</div>
{!hidePhone && <PhoneButton className="pb-4 sm:hidden" />}
{SideActions && (
{RightSideActions && (
<div className="sm:hidden">
<SideActions />
<RightSideActions />
</div>
)}
</>
Expand Down
9 changes: 0 additions & 9 deletions lib/hooks/useMenuItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const refreshData = async () => {

const { menuGroups } = json;

if (window?.localStorage && menuGroups?.length > 0) {
window.localStorage.setItem("megamenu", JSON.stringify(menuGroups));
}

return menuGroups;
};

Expand All @@ -23,13 +19,8 @@ export const useMenuItems = (
const [menuItems, setMenuItems] = useState<NavMenuGroup[] | null>([]);

useEffect(() => {
const cached = JSON.parse(window.localStorage.getItem("megamenu") || "[]");
console.log("cached", cached);

if (menuBarItems) {
setMenuItems(menuBarItems);
} else if (cached?.length > 0) {
setMenuItems(cached);
} else {
refreshData().then((data) => {
setMenuItems(data);
Expand Down

0 comments on commit 3570ffe

Please sign in to comment.