2023-12-11 17:05:35 +08:00
|
|
|
import React from 'react';
|
2023-12-01 11:52:37 +08:00
|
|
|
import {Droppable} from "@hello-pangea/dnd";
|
2023-12-11 17:05:35 +08:00
|
|
|
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";
|
2024-03-15 15:22:05 +08:00
|
|
|
import {CatalogGroups} from "./CatalogGroups";
|
2024-02-22 17:26:07 +08:00
|
|
|
import {SearchBar} from "./SearchBar";
|
2024-03-15 15:22:05 +08:00
|
|
|
import {CatalogSearchResult} from "./CatalogSearchResult";
|
2024-02-27 17:23:05 +08:00
|
|
|
import {GradientBottom} from "./GradientBottom";
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
/**
|
2024-03-15 15:22:05 +08:00
|
|
|
* Component that renders the catalog in the aside
|
2023-11-30 17:26:17 +08:00
|
|
|
*/
|
2024-03-15 15:22:05 +08:00
|
|
|
export function Catalog() {
|
2023-12-14 16:29:32 +08:00
|
|
|
// #!render_count
|
2023-12-14 16:09:33 +08:00
|
|
|
const renderCount = useRenderCount();
|
2023-12-14 16:29:32 +08:00
|
|
|
|
2023-12-14 16:09:33 +08:00
|
|
|
const data = useShopStore((state) => state.groups);
|
2024-11-01 17:32:20 +08:00
|
|
|
const _items = useShopStore((state) => state.cards);
|
2024-02-22 17:26:07 +08:00
|
|
|
|
2023-12-14 16:09:33 +08:00
|
|
|
const onClickToggleMobileSideMenu = useShopStore((state) => state.switchSideMenu);
|
|
|
|
const isMobile = useShopStore((state) => state.isMobile);
|
2024-08-01 17:37:43 +08:00
|
|
|
const showSearch = useShopStore((state) => state.listed_cards.length > 0 && state.search_bar_value.length > 0);
|
|
|
|
const noResults = useShopStore((state) => state.listed_cards.length === 0 && state.search_bar_value.length > 0);
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-14 16:29:32 +08:00
|
|
|
// #!render_count
|
2024-03-15 15:22:05 +08:00
|
|
|
console.log("Catalog renders: ", renderCount)
|
2023-12-14 16:29:32 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
return (
|
|
|
|
<Droppable
|
|
|
|
droppableId={data.id}
|
2024-01-02 17:13:50 +08:00
|
|
|
isDropDisabled={false}>
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
{(provided) => (
|
|
|
|
<div
|
2024-03-15 15:22:05 +08:00
|
|
|
className="catalog-container"
|
2023-12-11 17:05:35 +08:00
|
|
|
ref={provided.innerRef}
|
|
|
|
{...provided.droppableProps}>
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2024-03-15 15:22:05 +08:00
|
|
|
<div className="catalog-bar">
|
2024-02-23 15:28:39 +08:00
|
|
|
<SearchBar/>
|
|
|
|
|
|
|
|
{isMobile ? (
|
|
|
|
<div className="mobileCloseMenu">
|
|
|
|
<button onClick={onClickToggleMobileSideMenu}>
|
|
|
|
<img src="/images/shop/icon-close-white.svg" alt="add"/>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
|
2024-08-01 17:37:43 +08:00
|
|
|
{(showSearch && <CatalogSearchResult/>) ||
|
|
|
|
(noResults && <p className="no-results">No results</p>) ||
|
|
|
|
<CatalogGroups/>}
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
{provided.placeholder && (
|
|
|
|
<div style={{display: 'none'}}>
|
|
|
|
{provided.placeholder}
|
2023-11-30 17:26:17 +08:00
|
|
|
</div>
|
2023-12-11 17:05:35 +08:00
|
|
|
)}
|
2024-02-27 17:23:05 +08:00
|
|
|
|
|
|
|
<GradientBottom/>
|
2023-12-11 17:05:35 +08:00
|
|
|
</div>
|
|
|
|
)}
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
</Droppable>
|
|
|
|
);
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
}
|