Skip to content

Commit

Permalink
fix(edit): filter line ids before deleting board tile (#1759)
Browse files Browse the repository at this point in the history
  • Loading branch information
SelmaBergstrand authored Dec 11, 2024
1 parent 76e36e3 commit b6bbf5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 14 additions & 0 deletions tavla/app/(admin)/edit/[id]/components/TileCard/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,27 @@ import {
initializeAdminApp,
} from 'app/(admin)/utils/firebase'
import { redirect } from 'next/navigation'
import { SWITCH_DATE, NEW_LINE_IDS, OLD_LINE_IDS } from '../../compatibility'

initializeAdminApp()

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)
Expand Down
8 changes: 4 additions & 4 deletions tavla/app/(admin)/edit/[id]/components/TileList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ function TileList({
bid?: TBoardID
setDemoBoard?: Dispatch<SetStateAction<TBoard>>
}) {
const [array, setArray] = useState<TTile[]>(board.tiles)
const [tileArray, setTileArray] = useState<TTile[]>(board.tiles)

useEffect(() => {
setArray(board.tiles)
setTileArray(board.tiles)
}, [board.tiles])

const moveItem = (index: number, direction: string) => {
Expand All @@ -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)
Expand All @@ -46,7 +46,7 @@ function TileList({
const debouncedSave = debounce(moveItem, 150)
return (
<div className="flex flex-col gap-4">
{array.map((tile, index) => (
{tileArray.map((tile, index) => (
<TileCard
key={tile.uuid}
bid={bid ?? board.id ?? ''}
Expand Down

0 comments on commit b6bbf5e

Please sign in to comment.