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