From cbcb07d2f1cfb5331c528f5db02fb125bba12c97 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Thu, 5 Sep 2024 20:42:20 -0400 Subject: [PATCH] switched tanstack query --- .../AddAnimeServiceToTable.svelte | 38 ++-- .../src/helperComponents/AnimeTable.svelte | 199 +++++++++++++----- frontend/src/helperComponents/Header.svelte | 1 - frontend/src/routes/Anime.svelte | 108 +++++----- 4 files changed, 215 insertions(+), 131 deletions(-) diff --git a/frontend/src/helperComponents/AddAnimeServiceToTable.svelte b/frontend/src/helperComponents/AddAnimeServiceToTable.svelte index 9197fac..3e4e433 100644 --- a/frontend/src/helperComponents/AddAnimeServiceToTable.svelte +++ b/frontend/src/helperComponents/AddAnimeServiceToTable.svelte @@ -2,32 +2,20 @@ import type {TableItem} from "../helperTypes/TableTypes"; import { tableItems } from "./GlobalVariablesAndHelperFunctions.svelte" - export function AddAnimeServiceToTable(tableItem: TableItem) { - let tableLoaded: TableItem[] - tableItems.subscribe(value => tableLoaded = value) - console.log(tableLoaded.length) - if(tableLoaded.length === 0) { - tableItems.update(table => { - table.push(tableItem) - return table - }) - return - } - - for (const [index, entry] of tableLoaded.entries()) { - console.log(entry) - if (entry.service === tableItem.service) { - tableItems.update(value => { - value[index] = tableItem - return value - }) + export function AddAnimeServiceToTable(animeItem: TableItem) { + tableItems.update((table) => { + if (table.length === 0) { + table.push(animeItem) } else { - tableItems.update(table => { - table.push(tableItem) - return table - }) + for (const [index, tableItem] of table.entries()) { + if(tableItem.service === animeItem.service) { + table[index] = animeItem + return table + } + } + table.push(animeItem) } - } - return + return table + }) } \ No newline at end of file diff --git a/frontend/src/helperComponents/AnimeTable.svelte b/frontend/src/helperComponents/AnimeTable.svelte index ee22c9b..f0fa3e2 100644 --- a/frontend/src/helperComponents/AnimeTable.svelte +++ b/frontend/src/helperComponents/AnimeTable.svelte @@ -1,68 +1,151 @@ - - - sortTable('id')}>ID - sortTable('service')}>Service - sortTable('progress')}>Episode Progress - sortTable('status')}>Status - sortTable('startedAt')}>Date Started - sortTable('completedAt')}>Date Completed - sortTable('score')}>Rating - sortTable('repeat')}>Rewatches - Notes - - - {#each $sortItems as item} - - {item.id} - {item.service} - {item.progress} - {item.status} - {item.startedAt} - {item.completedAt} - {item.score} - {item.repeat} - {item.notes} - +
+
+ + {#each $table.getHeaderGroups() as headerGroup} + + {#each headerGroup.headers as header} + + {/each} + {/each} - -
+ {#if !header.isPlaceholder} + + {/if} +
\ No newline at end of file + + + {#each $table.getRowModel().rows as row} + + {#each row.getVisibleCells() as cell} + + + + {/each} + + {/each} + + + + diff --git a/frontend/src/helperComponents/Header.svelte b/frontend/src/helperComponents/Header.svelte index d0a738a..53d309d 100644 --- a/frontend/src/helperComponents/Header.svelte +++ b/frontend/src/helperComponents/Header.svelte @@ -34,7 +34,6 @@ let currentLocation: any location.subscribe(value => currentLocation = value) - console.log(currentLocation)