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-12 18:21:09 +08:00
|
|
|
import {ProductItem} from "./ProductItem";
|
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";
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that renders the backlog in the aside
|
|
|
|
*/
|
2023-12-11 17:05:35 +08:00
|
|
|
export function Backlog() {
|
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);
|
|
|
|
const items = useShopStore((state) => state.cards);
|
|
|
|
const onClickToggleMobileSideMenu = useShopStore((state) => state.switchSideMenu);
|
|
|
|
const isMobile = useShopStore((state) => state.isMobile);
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-14 16:29:32 +08:00
|
|
|
// #!render_count
|
2023-12-14 16:09:33 +08:00
|
|
|
console.log("Backlog renders: ", renderCount)
|
2023-12-14 16:29:32 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
const ordered_groups = data.categories.map(groupItem => ({
|
|
|
|
name: groupItem.name,
|
|
|
|
items: groupItem.itemIds.map(itemId => items[itemId])
|
|
|
|
}));
|
|
|
|
let item_index = -1;
|
|
|
|
const groups = ordered_groups.map((group, g_index) => {
|
|
|
|
return (
|
|
|
|
<div className="accordion-item" key={`${group.name}`}>
|
|
|
|
<h2 className="accordion-header">
|
|
|
|
<button className="accordion-button collapsed" type="button" data-bs-toggle="collapse"
|
|
|
|
data-bs-target={`#collapse${g_index}`} aria-expanded="true"
|
|
|
|
aria-controls={`collapse${g_index}`}>
|
|
|
|
{group.name}
|
|
|
|
</button>
|
|
|
|
</h2>
|
|
|
|
<div id={`collapse${g_index}`} className="accordion-collapse collapse" aria-labelledby="headingOne"
|
|
|
|
data-bs-parent="#accordion_categories">
|
|
|
|
<div className="accordion-body">
|
|
|
|
{group.items.map(item => {
|
|
|
|
item_index++;
|
|
|
|
return (
|
2023-12-13 15:17:14 +08:00
|
|
|
<ProductItem card_index={item_index} key={item.id} />
|
2023-12-11 17:05:35 +08:00
|
|
|
)
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
return (
|
|
|
|
<Droppable
|
|
|
|
droppableId={data.id}
|
|
|
|
isDropDisabled={true}>
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
{(provided) => (
|
|
|
|
<div
|
|
|
|
className="backlog-container"
|
|
|
|
ref={provided.innerRef}
|
|
|
|
{...provided.droppableProps}>
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
{isMobile ? (
|
|
|
|
<div className="mobileCloseMenu">
|
|
|
|
<button onClick={onClickToggleMobileSideMenu}>
|
|
|
|
<img src="/images/shop/icon-close-white.svg" alt="add"/>
|
2023-11-30 17:26:17 +08:00
|
|
|
</button>
|
|
|
|
</div>
|
2023-12-11 17:05:35 +08:00
|
|
|
) : null}
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
<div className="accordion accordion-flush" id="accordion_categories">
|
|
|
|
{groups}
|
|
|
|
</div>
|
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
|
|
|
)}
|
|
|
|
</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
|
|
|
|
|
|
|
}
|