Skip to content

Commit f87cc32

Browse files
committed
fix: fix share view
1 parent 8f9f178 commit f87cc32

File tree

7 files changed

+74
-34
lines changed

7 files changed

+74
-34
lines changed

apps/frontend/src/lib/components/blocks/gallery-view/gallery-view.svelte

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,31 @@
2323
const currentPage = writable(1)
2424
const q = queryParam("q")
2525
26-
const getRecords = createQuery(
26+
const getRecords = () => {
27+
if (shareId) {
28+
return trpc.shareData.records.query({
29+
shareId,
30+
tableId: $table?.id.value,
31+
viewId: $viewId,
32+
q: $q ?? undefined,
33+
pagination: { limit: $perPage, page: $currentPage },
34+
})
35+
}
36+
return trpc.record.list.query({
37+
tableId: $table?.id.value,
38+
viewId: $viewId,
39+
q: $q ?? undefined,
40+
pagination: { limit: $perPage, page: $currentPage },
41+
})
42+
}
43+
44+
const getRecordsQuery = createQuery(
2745
derived([table, viewId, perPage, currentPage, q], ([$table, $viewId, $perPage, $currentPage, $q]) => {
2846
const view = $table.views.getViewById($viewId)
2947
return {
3048
queryKey: ["records", $table?.id.value, $viewId, $q, $currentPage, $perPage],
3149
enabled: view?.type === "gallery",
32-
queryFn: () =>
33-
trpc.record.list.query({
34-
tableId: $table?.id.value,
35-
viewId: $viewId,
36-
q: $q ?? undefined,
37-
pagination: { limit: $perPage, page: $currentPage },
38-
}),
50+
queryFn: getRecords,
3951
}
4052
}),
4153
)
@@ -44,12 +56,12 @@
4456
setRecordsStore(recordsStore)
4557
4658
// $: records = (($getRecords.data as any)?.records as IRecordsDTO) ?? []
47-
let records = derived([getRecords], ([$getRecords]) => {
59+
let records = derived([getRecordsQuery], ([$getRecords]) => {
4860
return (($getRecords.data as any)?.records as IRecordsDTO) ?? []
4961
})
50-
$: recordsStore.setRecords(Records.fromJSON($table, $records), $getRecords.dataUpdatedAt)
62+
$: recordsStore.setRecords(Records.fromJSON($table, $records), $getRecordsQuery.dataUpdatedAt)
5163
52-
$: total = ($getRecords.data as any)?.total
64+
$: total = ($getRecordsQuery.data as any)?.total
5365
</script>
5466

5567
<TableTools />

apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-lane.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
if (shareId) {
6666
return trpc.shareData.records.query({
6767
shareId,
68+
tableId,
69+
viewId: $viewId,
6870
q: $q,
6971
filters: {
7072
conjunction: "and",

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
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 { createRecordsStore, setRecordsStore } from "$lib/store/records.store"
4+
import { createRecordsStore, setRecordsStore, type RecordsStore } from "$lib/store/records.store"
55
import { getTable } from "$lib/store/table.store"
66
import { trpc } from "$lib/trpc/client"
77
import { createQuery } from "@tanstack/svelte-query"
88
import { Records, type IRecordsDTO } from "@undb/table"
9+
import { onMount } from "svelte"
10+
import ShareTableTools from "$lib/components/blocks/table-tools/share-table-tools.svelte"
911
import { derived, writable, type Readable } from "svelte/store"
1012
1113
export let viewId: Readable<string>
@@ -21,6 +23,8 @@
2123
queryFn: () =>
2224
trpc.shareData.records.query({
2325
shareId: $page.params.shareId,
26+
tableId: $table.id.value,
27+
viewId: $viewId,
2428
pagination: {
2529
page: $currentPage,
2630
limit: $perPage,
@@ -32,18 +36,22 @@
3236
3337
$: records = (($getRecords.data as any)?.records as IRecordsDTO) ?? []
3438
39+
let store = createRecordsStore()
40+
setRecordsStore(store)
41+
3542
$: if ($getRecords.isSuccess) {
36-
const store = createRecordsStore()
3743
store.setRecords(Records.fromJSON($t, records), $getRecords.dataUpdatedAt)
38-
setRecordsStore(store)
3944
}
4045
</script>
4146

42-
<GridViewDataTable
43-
{viewId}
44-
readonly
45-
{perPage}
46-
{currentPage}
47-
isLoading={$getRecords.isLoading}
48-
total={$getRecords.data?.total ?? 0}
49-
/>
47+
{#if store}
48+
<ShareTableTools />
49+
<GridViewDataTable
50+
{viewId}
51+
readonly
52+
{perPage}
53+
{currentPage}
54+
isLoading={$getRecords.isLoading}
55+
total={$getRecords.data?.total ?? 0}
56+
/>
57+
{/if}

apps/frontend/src/routes/(share)/s/b/[shareId]/+layout.gql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ query GetShareBaseData($shareId: ID!) {
2929
views {
3030
id
3131
name
32+
type
3233
isDefault
34+
kanban {
35+
field
36+
}
37+
gallery {
38+
field
39+
}
3340
}
3441
}
3542
}

apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/+layout.gql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ query GetBaseTableShareData($shareId: ID!, $tableId: ID!) {
2626
name
2727
isDefault
2828
fields
29+
type
30+
kanban {
31+
field
32+
}
33+
gallery {
34+
field
35+
}
2936
}
3037
schema {
3138
constraint

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
const table = writable<TableDo>()
1616
$: {
1717
if (!fetching && tableDTO) {
18+
// @ts-ignore
1819
table.set(new TableCreator().fromJSON(tableDTO))
1920
setTable(table)
2021
}

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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 ShareTableTools from "$lib/components/blocks/table-tools/share-table-tools.svelte"
54
import { getTable } from "$lib/store/table.store"
65
import { trpc } from "$lib/trpc/client"
76
import { createQuery } from "@tanstack/svelte-query"
@@ -13,16 +12,22 @@
1312
import ShareTableHeader from "$lib/components/blocks/table-header/share-table-header.svelte"
1413
import FormsReadonly from "$lib/components/blocks/forms/forms-readonly.svelte"
1514
import { createRecordsStore, setRecordsStore } from "$lib/store/records.store"
15+
import ShareGridView from "$lib/components/blocks/share/share-grid-view.svelte"
16+
import ShareGalleryView from "$lib/components/blocks/share/share-gallery-view.svelte"
17+
import ShareKanbanView from "$lib/components/blocks/share/share-kanban-view.svelte"
1618
1719
let RecordDetailSheet: ComponentType
1820
1921
let viewId = derived(page, (page) => page.params.viewId)
22+
let shareId = derived(page, (page) => page.params.shareId)
2023
onMount(async () => {
2124
RecordDetailSheet = (await import("$lib/components/blocks/record-detail/share-record-detail-sheet.svelte")).default
2225
})
2326
2427
const t = getTable()
2528
29+
$: view = $t.views.getViewById($viewId)
30+
2631
const perPage = writable(50)
2732
const currentPage = writable(1)
2833
const q = queryParam("q")
@@ -44,26 +49,24 @@
4449
4550
$: records = (($getRecords.data as any)?.records as IRecordsDTO) ?? []
4651
52+
const store = createRecordsStore()
53+
setRecordsStore(store)
4754
$: if ($getRecords.isSuccess) {
48-
const store = createRecordsStore()
4955
store.setRecords(Records.fromJSON($t, records), $getRecords.dataUpdatedAt)
50-
setRecordsStore(store)
5156
}
5257
</script>
5358

5459
<div class="flex flex-1 flex-col">
5560
<ShareTableHeader />
56-
<ShareTableTools />
5761

5862
{#if $isDataTab}
59-
<GridViewDataTable
60-
{viewId}
61-
readonly
62-
{perPage}
63-
{currentPage}
64-
isLoading={$getRecords.isLoading}
65-
total={$getRecords.data?.total ?? 0}
66-
/>
63+
{#if view?.type === "grid"}
64+
<ShareGridView {viewId} />
65+
{:else if view.type === "kanban"}
66+
<ShareKanbanView {viewId} shareId={$shareId} />
67+
{:else if view.type === "gallery"}
68+
<ShareGalleryView {viewId} shareId={$shareId} />
69+
{/if}
6770
{:else if $isFormTab}
6871
<FormsReadonly />
6972
{/if}

0 commit comments

Comments
 (0)