Added fallback for token statuses empty values and duplicates
This commit is contained in:
parent
2f9a55f176
commit
34fcff9052
src/components/token
@ -59,15 +59,14 @@ function TokenMenu({
|
||||
if (!tokenState) {
|
||||
return;
|
||||
}
|
||||
const statuses = tokenState.statuses;
|
||||
let newStatuses = [];
|
||||
if (statuses.includes(status)) {
|
||||
newStatuses = statuses.filter((s) => s !== status);
|
||||
const statuses = new Set(tokenState.statuses.filter((s) => s));
|
||||
if (statuses.has(status)) {
|
||||
statuses.delete(status);
|
||||
} else {
|
||||
newStatuses = [...statuses, status];
|
||||
statuses.add(status);
|
||||
}
|
||||
onTokenStateChange({
|
||||
[tokenState.id]: { ...tokenState, statuses: newStatuses },
|
||||
[tokenState.id]: { ...tokenState, statuses: [...statuses] },
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,11 @@ import { Circle, Group } from "react-konva";
|
||||
import colors from "../../helpers/colors";
|
||||
|
||||
function TokenStatus({ tokenState, width, height }) {
|
||||
// Ensure statuses is an array and filter empty values
|
||||
const statuses = [...new Set((tokenState?.statuses || []).filter((s) => s))];
|
||||
return (
|
||||
<Group x={width} y={height} offsetX={width / 2} offsetY={height / 2}>
|
||||
{tokenState.statuses.map((status, index) => (
|
||||
{statuses.map((status, index) => (
|
||||
<Circle
|
||||
key={status}
|
||||
width={width}
|
||||
|
Loading…
Reference in New Issue
Block a user