From 7aa4a156e7944a16f1ac96c59c20e6901350c07f Mon Sep 17 00:00:00 2001 From: Joshua Seigler <2583159+seigler@users.noreply.github.com> Date: Sat, 5 Apr 2025 17:12:27 -0700 Subject: [PATCH] pin and unpin working --- src/App.tsx | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8c48f5b..b07defe 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -76,15 +76,37 @@ function App() { }; const handlePinUnpin = () => { - if (store.selected.every((x) => x <= store.pinnedCount)) { + if (store.selected.every((x) => x < store.pinnedCount)) { // we are unpinning + const puzzleStart = Array.from({ length: store.pinnedCount }, (_, i) => i) + .filter((x) => !store.selected.includes(x)) + .map((x) => store.puzzle[x]); + const puzzleMiddle = store.selected.map((x) => store.puzzle[x]); + const puzzleEnd = store.puzzle.slice(store.pinnedCount); + const newPuzzle = [...puzzleStart, ...puzzleMiddle, ...puzzleEnd]; setStore({ pinnedCount: store.pinnedCount - store.selected.length, selected: [], - }) + puzzle: newPuzzle, + }); return; } // we are pinning + const puzzleStart = store.puzzle.slice(0, store.pinnedCount); + const puzzleMid = store.selected + .filter((x) => x >= store.pinnedCount) + .map((x) => store.puzzle[x]); + const puzzleEnd = Array.from( + { length: 16 - store.pinnedCount }, + (_, i) => i + store.pinnedCount + ) + .filter((x) => !store.selected.includes(x)) + .map((x) => store.puzzle[x]); + setStore({ + pinnedCount: puzzleStart.length + puzzleMid.length, + selected: [], + puzzle: [...puzzleStart, ...puzzleMid, ...puzzleEnd] + }) }; return ( @@ -106,12 +128,14 @@ function App() {
{[0, 1, 2, 3].map((col) => { const index = 4 * row + col; + const answer = getFromPuzzle(index).answer; return ( ); @@ -131,8 +155,13 @@ function App() {
-