2023-12-07 17:08:22 +08:00
|
|
|
import React from 'react';
|
2023-12-12 18:21:09 +08:00
|
|
|
import {Cart} from "./Cart";
|
|
|
|
import {CrateMode} from "./CrateMode";
|
|
|
|
import {CrateWarnings} from "./CrateWarnings";
|
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-01-25 17:10:14 +08:00
|
|
|
import {CrateFanTray} from "./CrateFanTray";
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-14 16:29:32 +08:00
|
|
|
|
2023-11-30 17:26:17 +08:00
|
|
|
/**
|
|
|
|
* Component that displays the main crate with reminder rules.
|
|
|
|
* It includes <Cart> and rules
|
|
|
|
*/
|
2023-12-11 17:05:35 +08:00
|
|
|
export function Crate({crate_index}) {
|
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 crate = useShopStore((state) => state.crates[crate_index],
|
2024-01-15 13:01:27 +08:00
|
|
|
(a, b) => a.length === b.length && a.id === b.id);
|
|
|
|
const modes_order = useShopStore((state) => state.modes_order);
|
2023-12-14 16:09:33 +08:00
|
|
|
const onDeleteCrate = useShopStore((state) => state.delCrate);
|
2023-12-11 17:05:35 +08:00
|
|
|
|
2023-12-14 16:29:32 +08:00
|
|
|
// #!render_count
|
2023-12-14 16:09:33 +08:00
|
|
|
console.log("Crate renders: ", renderCount)
|
2023-12-14 16:29:32 +08:00
|
|
|
|
2023-12-07 17:08:22 +08:00
|
|
|
return (
|
|
|
|
<div className="crate">
|
2024-01-15 13:01:27 +08:00
|
|
|
{
|
|
|
|
modes_order.includes(crate.crate_mode) ? (
|
|
|
|
<div className="crate-bar d-inline-flex justify-content-between">
|
|
|
|
<CrateMode crate_index={crate_index}/>
|
|
|
|
|
|
|
|
<div className="delete-crate align-self-start align-content-start justify-content-end" onClick={() => onDeleteCrate(crate.id)}>
|
|
|
|
Delete crate <img src="/images/shop/icon-remove.svg" alt="remove"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : <></>
|
|
|
|
}
|
2023-12-07 17:50:33 +08:00
|
|
|
|
2023-12-07 17:08:22 +08:00
|
|
|
<div className="crate-products">
|
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
<Cart crate_index={crate_index}/>
|
2023-12-07 17:08:22 +08:00
|
|
|
|
2023-12-12 16:09:29 +08:00
|
|
|
<CrateWarnings crate_index={crate_index} />
|
2024-01-25 17:10:14 +08:00
|
|
|
|
|
|
|
<CrateFanTray crate_index={crate_index}/>
|
2023-12-07 17:08:22 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
}
|