Skip to content

Commit 8a3b349

Browse files
committed
fix: fix get share table
1 parent b5bd4ec commit 8a3b349

File tree

2 files changed

+11
-41
lines changed

2 files changed

+11
-41
lines changed

apps/frontend/src/lib/components/blocks/share/share-grid-view.svelte

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
<script lang="ts">
22
import { page } from "$app/stores"
33
import GridViewDataTable from "$lib/components/blocks/grid-view/grid-view-data-table.svelte"
4+
import { preferences } from "$lib/store/persisted.store"
45
import { createRecordsStore, setRecordsStore, type RecordsStore } from "$lib/store/records.store"
56
import { getTable } from "$lib/store/table.store"
67
import { trpc } from "$lib/trpc/client"
78
import { createQuery } from "@tanstack/svelte-query"
89
import { Records, type IRecordsDTO } from "@undb/table"
9-
import ShareTableTools from "$lib/components/blocks/table-tools/share-table-tools.svelte"
1010
import { derived, writable, type Readable } from "svelte/store"
11+
import { queryParam, ssp } from "sveltekit-search-params"
1112
1213
export let viewId: Readable<string>
1314
1415
const t = getTable()
15-
const perPage = writable(50)
16-
const currentPage = writable(1)
16+
const perPage = derived(preferences, ($preferences) => $preferences.gridViewPerPage ?? 50)
17+
const currentPage = queryParam("page", ssp.number())
18+
const q = queryParam("q")
1719
1820
const getRecords = createQuery(
19-
derived([t, perPage, currentPage, page], ([$table, $perPage, $currentPage, $page]) => {
21+
derived([t, perPage, currentPage, page, q], ([$table, $perPage, $currentPage, $page, $q]) => {
2022
return {
21-
queryKey: ["records", $table?.id.value, $currentPage, $perPage],
23+
queryKey: ["records", $table?.id.value, $currentPage, $perPage, $q],
2224
queryFn: () =>
2325
trpc.shareData.records.query({
2426
shareId: $page.params.shareId,
2527
tableId: $table.id.value,
2628
viewId: $viewId,
29+
q: $q,
2730
pagination: {
28-
page: $currentPage,
31+
page: $currentPage ?? 1,
2932
limit: $perPage,
3033
},
3134
}),
35+
enabled: !!$perPage,
3236
}
3337
}),
3438
)
@@ -44,7 +48,6 @@
4448
</script>
4549

4650
{#if store}
47-
<!-- <ShareTableTools /> -->
4851
<GridViewDataTable
4952
{viewId}
5053
readonly

apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/[[viewId]]/+page.svelte

+1-34
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
<script lang="ts">
22
import { page } from "$app/stores"
3-
import GridViewDataTable from "$lib/components/blocks/grid-view/grid-view-data-table.svelte"
43
import { getTable } from "$lib/store/table.store"
5-
import { trpc } from "$lib/trpc/client"
6-
import { createQuery } from "@tanstack/svelte-query"
7-
import { Records, type IRecordsDTO } from "@undb/table"
84
import { onMount, type ComponentType } from "svelte"
9-
import { derived, writable } from "svelte/store"
10-
import { queryParam } from "sveltekit-search-params"
5+
import { derived } from "svelte/store"
116
import { isDataTab, isFormTab } from "$lib/store/tab.store"
127
import ShareTableHeader from "$lib/components/blocks/table-header/share-table-header.svelte"
138
import FormsReadonly from "$lib/components/blocks/forms/forms-readonly.svelte"
14-
import { createRecordsStore, setRecordsStore } from "$lib/store/records.store"
159
import ShareGridView from "$lib/components/blocks/share/share-grid-view.svelte"
1610
import ShareGalleryView from "$lib/components/blocks/share/share-gallery-view.svelte"
1711
import ShareKanbanView from "$lib/components/blocks/share/share-kanban-view.svelte"
@@ -27,33 +21,6 @@
2721
const t = getTable()
2822
2923
$: view = $t.views.getViewById($viewId)
30-
31-
const perPage = writable(50)
32-
const currentPage = writable(1)
33-
const q = queryParam("q")
34-
35-
const getRecords = createQuery(
36-
derived([t, perPage, currentPage, viewId, page, q], ([$table, $perPage, $currentPage, $viewId, $page, $q]) => {
37-
return {
38-
queryKey: ["records", $table?.id.value, $viewId, $currentPage, $perPage, $q],
39-
queryFn: () =>
40-
trpc.shareData.records.query({
41-
shareId: $page.params.shareId,
42-
tableId: $table.id.value,
43-
viewId: $viewId,
44-
q: $q,
45-
}),
46-
}
47-
}),
48-
)
49-
50-
$: records = (($getRecords.data as any)?.records as IRecordsDTO) ?? []
51-
52-
const store = createRecordsStore()
53-
setRecordsStore(store)
54-
$: if ($getRecords.isSuccess) {
55-
store.setRecords(Records.fromJSON($t, records), $getRecords.dataUpdatedAt)
56-
}
5724
</script>
5825

5926
<ShareTableHeader />

0 commit comments

Comments
 (0)