const PolyList = ({ polys, activePolyId, setActivePolyId, activePoint, setActivePoint, getUser, remove }) => { const listOpenKey = "list-open"; const listOpenInit = localStorage.getItem(listOpenKey); const [listOpen, setListOpen] = React.useState((listOpenInit === null || listOpenInit === 'true')); if (polys === undefined) { return } function isActivePoly(polyId) { return (activePolyId === polyId); } function isActivePoint(point) { return (activePoint !== undefined && activePoint.x === point.x && activePoint.y === point.y); } function listliClick(polyId) { if (isActivePoly(polyId)) { setActivePolyId(""); return } setActivePolyId(polyId); } let newest; if (polys.length > 0) { newest = polys.reduce((a, b) => { return Number(a.id) > Number(b.id) ? a : b }); } let items = polys.filter(poly => { return poly.points.length > 1 || poly.id === newest.id; }).toSorted((a, b) => { const an = Number(a.id); const bn = Number(b.id); // Reversed if (an > bn) return -1; if (bn > an) return 1; return 0; }).map(poly => { let showPoints = (activePolyId === poly.id); let points; // Get list of points, if active for this poly if (showPoints) { points = poly.points.map((point, i) => { const pointClass = isActivePoint(point) ? "pointitem activepoint" : "pointitem" const pointStyle = { "backgroundColor": `color-mix(in srgb, ${biomeColor(point.biome)} 15%, white)`, }; let label = (point.label !== undefined) ?
{point.label.toLowerCase()}
: null; return (
  • setActivePoint(point)}>
    ({point.x}, {point.y})
    {label}
    remove(poly.id, i)}>delete
  • ) }) } const users = getUser(poly.userId); // Return poly return (
  • { listliClick(poly.id) }}>
    {poly.points.length}
    {users && users.length > 0 && users[0].name}
    {poly.kind}
    {showPoints && }
  • ); }); return (
    { localStorage.setItem(listOpenKey, !listOpen); setListOpen(!listOpen); }}>
    ) }