2023-12-11 17:05:35 +08:00
|
|
|
import React from 'react';
|
|
|
|
import {useShopStore} from "./shop_store";
|
2023-12-14 16:29:32 +08:00
|
|
|
|
|
|
|
// #!render_count
|
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:29:32 +08:00
|
|
|
// #!render_count
|
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);
|
2024-01-05 17:22:53 +08:00
|
|
|
const showNoDestination = useShopStore(state => state.showNoDestination);
|
2023-12-14 16:09:33 +08:00
|
|
|
|
2023-12-14 16:29:32 +08:00
|
|
|
// #!render_count
|
2023-12-14 16:09:33 +08:00
|
|
|
console.log("Layout renders: ", renderCount)
|
2023-12-11 17:05:35 +08:00
|
|
|
|
|
|
|
return (
|
2024-01-05 17:22:53 +08:00
|
|
|
<div className="layout">
|
2023-12-11 17:05:35 +08:00
|
|
|
|
2024-01-05 17:22:53 +08:00
|
|
|
<aside className={'aside ' + (mobileSideMenuShouldOpen ? 'menu-opened' : '')}>{aside}</aside>
|
2023-12-11 17:05:35 +08:00
|
|
|
|
2024-01-05 17:22:53 +08:00
|
|
|
{mobileSideMenuShouldOpen ? (
|
|
|
|
<section className="main" onClick={onClickToggleMobileSideMenu}>{main}</section>
|
|
|
|
) : (
|
|
|
|
<section className="main">{main}</section>
|
|
|
|
)}
|
2023-12-11 17:05:35 +08:00
|
|
|
|
2024-01-05 17:22:53 +08:00
|
|
|
{showCardAddedFeedback ? (
|
|
|
|
!showNoDestination ?
|
|
|
|
(<div className="feedback-add-success">
|
2023-12-11 17:05:35 +08:00
|
|
|
✓ added
|
2024-01-05 17:22:53 +08:00
|
|
|
</div>)
|
|
|
|
: (<div className="feedback-add-failure">
|
|
|
|
No cards added: all crates are closed
|
|
|
|
</div>)
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
2023-12-11 17:05:35 +08:00
|
|
|
}
|