second commit
This commit is contained in:
+10
-7
@@ -1,9 +1,9 @@
|
||||
import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from "react";
|
||||
import { DEFAULT_SIZES, fitScale, isValidPlacement, clampToRoom } from "./geometry";
|
||||
import { initialState, reducer } from "./store";
|
||||
import type { FurnitureType } from "./types";
|
||||
import { FURNITURE_TYPES, type FurnitureType } from "./types";
|
||||
import { remaining, placedCount } from "./inventory";
|
||||
import { Palette, ChairIcon, TableIcon } from "./components/Palette";
|
||||
import { Palette, TYPE_ICON } from "./components/Palette";
|
||||
import { Room, type Preview } from "./components/Room";
|
||||
import { ScaleBar } from "./components/ScaleBar";
|
||||
import { TypeMenu } from "./components/TypeMenu";
|
||||
@@ -96,10 +96,9 @@ export default function App() {
|
||||
setPaletteDrag({ type, clientX, clientY });
|
||||
};
|
||||
|
||||
const remainingByType = {
|
||||
chair: remaining(state.items, "chair", state.configs.chair.available),
|
||||
table: remaining(state.items, "table", state.configs.table.available),
|
||||
};
|
||||
const remainingByType = Object.fromEntries(
|
||||
FURNITURE_TYPES.map((t) => [t, remaining(state.items, t, state.configs[t].available)]),
|
||||
) as Record<FurnitureType, number>;
|
||||
|
||||
return (
|
||||
<div style={{ display: "flex", height: "100vh", background: "#e9e9e9", cursor: paletteDrag ? "grabbing" : undefined }}>
|
||||
@@ -131,6 +130,7 @@ export default function App() {
|
||||
preview={preview}
|
||||
floorRef={floorRef}
|
||||
onMove={(id, x, y) => dispatch({ kind: "move", id, x, y })}
|
||||
onResize={(id, r) => dispatch({ kind: "resize", id, ...r })}
|
||||
/>
|
||||
<ScaleBar pxPerM={pxPerM} roomWidthPx={state.room.width * pxPerM + WALL_PX * 2} />
|
||||
</main>
|
||||
@@ -145,7 +145,10 @@ export default function App() {
|
||||
opacity: 0.8,
|
||||
}}
|
||||
>
|
||||
{paletteDrag.type === "chair" ? <ChairIcon /> : <TableIcon />}
|
||||
{(() => {
|
||||
const Icon = TYPE_ICON[paletteDrag.type];
|
||||
return <Icon />;
|
||||
})()}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user