Skip to content

Commit

Permalink
fix(app): table cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cor committed May 31, 2024
1 parent b23fd8a commit 6fa13eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 7 additions & 12 deletions app/src/routes/explorer/(components)/table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ import { createVirtualizer } from "@tanstack/svelte-virtual"
import * as Card from "$lib/components/ui/card/index.ts"
export let columns: Array<ColumnDef<any>>
// https://github.com/TanStack/table/issues/4241
// @ts-ignore
export let blocksStore: Writable<Array<any>>
export let dataStore: Writable<Array<any>>
const options = writable<TableOptions<any>>({
data: $blocksStore,
data: $dataStore,
enableHiding: true,
enableFilters: true,
// https://github.com/TanStack/table/issues/4241
// @ts-ignore
columns,
autoResetPageIndex: true, // Automatically update pagination when data or page size changes
autoResetPageIndex: true,
enableColumnFilters: true,
enableColumnResizing: true,
enableMultiRowSelection: true,
Expand All @@ -39,10 +38,6 @@ const options = writable<TableOptions<any>>({
let virtualListElement: HTMLDivElement
const rerender = () => {
options.update(options => ({ ...options, data: $blocksStore as unknown as Array<T> }))
}
const table = createSvelteTable(options)
const rows = derived(table, $t => $t.getRowModel().rows)
Expand All @@ -53,10 +48,10 @@ $: virtualizer = createVirtualizer<HTMLDivElement, HTMLTableRowElement>({
getScrollElement: () => virtualListElement
})
$: blocksStore.subscribe(() => {
if (!$blocksStore) return
$table.setPageSize($blocksStore.length)
rerender()
$: dataStore.subscribe(() => {
if (!$dataStore) return
$table.setPageSize($dataStore.length)
options.update(options => ({ ...options, data: $dataStore as unknown as Array<T> }))
})
</script>

Expand Down
2 changes: 1 addition & 1 deletion app/src/routes/explorer/blocks/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ const columns = [
<title>Union - Explorer</title>
</svelte:head>

<Table columns={columns} bind:blocksStore={blocksStore}/>
<Table columns={columns} bind:dataStore={blocksStore}/>
{JSON.stringify($blocksStore, null, 2)}

0 comments on commit 6fa13eb

Please sign in to comment.