From b6bbf5e64882ec38507f81e35d85daa0f7f0fb33 Mon Sep 17 00:00:00 2001 From: SelmaBergstrand <78426277+SelmaBergstrand@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:11:15 +0100 Subject: [PATCH] fix(edit): filter line ids before deleting board tile (#1759) --- .../edit/[id]/components/TileCard/actions.ts | 14 ++++++++++++++ .../edit/[id]/components/TileList/index.tsx | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tavla/app/(admin)/edit/[id]/components/TileCard/actions.ts b/tavla/app/(admin)/edit/[id]/components/TileCard/actions.ts index 28ea8741c..037941728 100644 --- a/tavla/app/(admin)/edit/[id]/components/TileCard/actions.ts +++ b/tavla/app/(admin)/edit/[id]/components/TileCard/actions.ts @@ -9,6 +9,7 @@ import { initializeAdminApp, } from 'app/(admin)/utils/firebase' import { redirect } from 'next/navigation' +import { SWITCH_DATE, NEW_LINE_IDS, OLD_LINE_IDS } from '../../compatibility' initializeAdminApp() @@ -16,6 +17,19 @@ export async function deleteTile(bid: TBoardID, tile: TTile) { const access = await hasBoardOwnerAccess(bid) if (!access) return redirect('/') + // TODO: refactor 15. december when new lines are active + if (tile.whitelistedLines) { + if (Date.now() < Date.parse(SWITCH_DATE.toString())) { + tile.whitelistedLines = tile.whitelistedLines.filter( + (line) => !NEW_LINE_IDS.includes(line), + ) + } else { + tile.whitelistedLines = tile.whitelistedLines.filter( + (line) => !OLD_LINE_IDS.includes(line), + ) + } + } + await firestore() .collection('boards') .doc(bid) diff --git a/tavla/app/(admin)/edit/[id]/components/TileList/index.tsx b/tavla/app/(admin)/edit/[id]/components/TileList/index.tsx index 0ba3821a5..dfd2bfdf6 100644 --- a/tavla/app/(admin)/edit/[id]/components/TileList/index.tsx +++ b/tavla/app/(admin)/edit/[id]/components/TileList/index.tsx @@ -16,10 +16,10 @@ function TileList({ bid?: TBoardID setDemoBoard?: Dispatch> }) { - const [array, setArray] = useState(board.tiles) + const [tileArray, setTileArray] = useState(board.tiles) useEffect(() => { - setArray(board.tiles) + setTileArray(board.tiles) }, [board.tiles]) const moveItem = (index: number, direction: string) => { @@ -35,7 +35,7 @@ function TileList({ newArray[newIndex] = newArray[index] as TTile newArray[index] = oldElement as TTile - setArray(newArray) + setTileArray(newArray) if (bid === 'demo' && setDemoBoard) { const newBoard: TBoard = { ...board, tiles: newArray } setDemoBoard(newBoard ?? board) @@ -46,7 +46,7 @@ function TileList({ const debouncedSave = debounce(moveItem, 150) return (
- {array.map((tile, index) => ( + {tileArray.map((tile, index) => (