2023-12-11 17:05:35 +08:00
|
|
|
import React from 'react';
|
|
|
|
import {useShopStore} from "./shop_store";
|
2023-12-14 16:09:33 +08:00
|
|
|
import {useRenderCount} from "@uidotdev/usehooks";
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that provides a base layout (aside/main) for the page.
|
|
|
|
*/
|
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
|
|
|
|
export function Layout({aside, main}) {
|
2023-12-14 16:09:33 +08:00
|
|
|
const renderCount = useRenderCount();
|
|
|
|
|
|
|
|
const mobileSideMenuShouldOpen = useShopStore(state => state.sideMenuIsOpen);
|
|
|
|
const onClickToggleMobileSideMenu = useShopStore(state => state.switchSideMenu);
|
|
|
|
const showCardAddedFeedback = useShopStore(state => state.showCardAddedFeedback);
|
|
|
|
|
|
|
|
console.log("Layout renders: ", renderCount)
|
2023-12-11 17:05:35 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="layout">
|
|
|
|
|
|
|
|
<aside className={'aside ' + (mobileSideMenuShouldOpen ? 'menu-opened' : '')}>{aside}</aside>
|
|
|
|
|
|
|
|
{mobileSideMenuShouldOpen ? (
|
|
|
|
<section className="main" onClick={onClickToggleMobileSideMenu}>{main}</section>
|
|
|
|
) : (
|
|
|
|
<section className="main">{main}</section>
|
|
|
|
)}
|
|
|
|
|
2023-12-13 15:17:14 +08:00
|
|
|
{showCardAddedFeedback ? (
|
2023-12-11 17:05:35 +08:00
|
|
|
<div className="feedback-add-success">
|
|
|
|
✓ added
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|