2023-12-07 17:08:22 +08:00
|
|
|
import React from "react";
|
2023-12-12 16:09:29 +08:00
|
|
|
import {LevelUI} from "./warnings";
|
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";
|
|
|
|
|
|
|
|
const compareArrays = (a, b) =>
|
|
|
|
a.length === b.length &&
|
|
|
|
a.every((element, index) => element.id === b[index].id);
|
2023-12-07 17:08:22 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
export function CrateWarnings({crate_index}) {
|
2023-12-14 16:09:33 +08:00
|
|
|
const renderCount = useRenderCount();
|
|
|
|
const crate_warnings = useShopStore(state => (state.crates[crate_index].warnings), compareArrays)
|
|
|
|
console.log("CrateWarnings renders: ", renderCount)
|
2023-12-11 17:05:35 +08:00
|
|
|
// TODO UI/colors
|
2023-12-07 17:08:22 +08:00
|
|
|
return (
|
|
|
|
<div className="crate-info">
|
2023-12-11 17:05:35 +08:00
|
|
|
{crate_warnings.map((rule, index) => (
|
2023-12-12 16:09:29 +08:00
|
|
|
<p key={index} className="rule" style={{'color': LevelUI(rule.level).color}}>
|
|
|
|
<img src={LevelUI(rule.level).icon} /> <i>{rule.message}</i>
|
2023-12-07 17:08:22 +08:00
|
|
|
</p>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|