2023-12-07 17:08:22 +08:00
|
|
|
import React from 'react';
|
2023-12-11 17:05:35 +08:00
|
|
|
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 displays crate modes
|
|
|
|
*/
|
2023-12-11 17:05:35 +08:00
|
|
|
export function CrateMode({crate_index}) {
|
2023-12-14 16:09:33 +08:00
|
|
|
const renderCount = useRenderCount();
|
|
|
|
|
|
|
|
const modes_order = useShopStore((state) => state.modes_order);
|
|
|
|
const crate_modes = useShopStore((state) => state.crate_modes);
|
|
|
|
const crate = useShopStore((state) => state.crates[crate_index],
|
|
|
|
(a, b) => a.id === b.id && a.crate_mode === b.crate_mode);
|
|
|
|
const setMode = useShopStore((state) => state.setCrateMode);
|
|
|
|
|
|
|
|
console.log("CrateMode renders: ", renderCount)
|
2023-12-07 17:08:22 +08:00
|
|
|
return (
|
|
|
|
<div className="crate-mode">
|
2023-12-11 17:05:35 +08:00
|
|
|
{modes_order.map((mode_name, _) => (
|
2023-12-07 17:08:22 +08:00
|
|
|
<a
|
2023-12-11 17:05:35 +08:00
|
|
|
key={mode_name}
|
|
|
|
className={crate.crate_mode === mode_name ? 'active' : ''}
|
|
|
|
onClick={() => setMode(crate.id, mode_name)}
|
2023-12-07 17:08:22 +08:00
|
|
|
href="#"
|
2023-12-11 17:05:35 +08:00
|
|
|
role="button">{crate_modes[mode_name].name}</a>
|
2023-12-07 17:08:22 +08:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
2023-12-13 12:39:15 +08:00
|
|
|
}
|