From f87cc32e887b5238104f9b13c6b98f0dd381acfb Mon Sep 17 00:00:00 2001 From: nichenqin Date: Fri, 13 Sep 2024 12:00:19 +0800 Subject: [PATCH] fix: fix share view --- .../blocks/gallery-view/gallery-view.svelte | 34 +++++++++++++------ .../kanban-view/select-kanban-lane.svelte | 2 ++ .../blocks/share/share-grid-view.svelte | 30 ++++++++++------ .../routes/(share)/s/b/[shareId]/+layout.gql | 7 ++++ .../s/b/[shareId]/t/[tableId]/+layout.gql | 7 ++++ .../s/b/[shareId]/t/[tableId]/+layout.svelte | 1 + .../t/[tableId]/[[viewId]]/+page.svelte | 27 ++++++++------- 7 files changed, 74 insertions(+), 34 deletions(-) diff --git a/apps/frontend/src/lib/components/blocks/gallery-view/gallery-view.svelte b/apps/frontend/src/lib/components/blocks/gallery-view/gallery-view.svelte index 4e6de42e0..3be4aa708 100644 --- a/apps/frontend/src/lib/components/blocks/gallery-view/gallery-view.svelte +++ b/apps/frontend/src/lib/components/blocks/gallery-view/gallery-view.svelte @@ -23,19 +23,31 @@ const currentPage = writable(1) const q = queryParam("q") - const getRecords = createQuery( + const getRecords = () => { + if (shareId) { + return trpc.shareData.records.query({ + shareId, + tableId: $table?.id.value, + viewId: $viewId, + q: $q ?? undefined, + pagination: { limit: $perPage, page: $currentPage }, + }) + } + return trpc.record.list.query({ + tableId: $table?.id.value, + viewId: $viewId, + q: $q ?? undefined, + pagination: { limit: $perPage, page: $currentPage }, + }) + } + + const getRecordsQuery = createQuery( derived([table, viewId, perPage, currentPage, q], ([$table, $viewId, $perPage, $currentPage, $q]) => { const view = $table.views.getViewById($viewId) return { queryKey: ["records", $table?.id.value, $viewId, $q, $currentPage, $perPage], enabled: view?.type === "gallery", - queryFn: () => - trpc.record.list.query({ - tableId: $table?.id.value, - viewId: $viewId, - q: $q ?? undefined, - pagination: { limit: $perPage, page: $currentPage }, - }), + queryFn: getRecords, } }), ) @@ -44,12 +56,12 @@ setRecordsStore(recordsStore) // $: records = (($getRecords.data as any)?.records as IRecordsDTO) ?? [] - let records = derived([getRecords], ([$getRecords]) => { + let records = derived([getRecordsQuery], ([$getRecords]) => { return (($getRecords.data as any)?.records as IRecordsDTO) ?? [] }) - $: recordsStore.setRecords(Records.fromJSON($table, $records), $getRecords.dataUpdatedAt) + $: recordsStore.setRecords(Records.fromJSON($table, $records), $getRecordsQuery.dataUpdatedAt) - $: total = ($getRecords.data as any)?.total + $: total = ($getRecordsQuery.data as any)?.total diff --git a/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-lane.svelte b/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-lane.svelte index b2fb92c87..a28a96348 100644 --- a/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-lane.svelte +++ b/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-lane.svelte @@ -65,6 +65,8 @@ if (shareId) { return trpc.shareData.records.query({ shareId, + tableId, + viewId: $viewId, q: $q, filters: { conjunction: "and", diff --git a/apps/frontend/src/lib/components/blocks/share/share-grid-view.svelte b/apps/frontend/src/lib/components/blocks/share/share-grid-view.svelte index d01744d48..3ac3f9464 100644 --- a/apps/frontend/src/lib/components/blocks/share/share-grid-view.svelte +++ b/apps/frontend/src/lib/components/blocks/share/share-grid-view.svelte @@ -1,11 +1,13 @@ - +{#if store} + + +{/if} diff --git a/apps/frontend/src/routes/(share)/s/b/[shareId]/+layout.gql b/apps/frontend/src/routes/(share)/s/b/[shareId]/+layout.gql index a4f55e009..7e074ce65 100644 --- a/apps/frontend/src/routes/(share)/s/b/[shareId]/+layout.gql +++ b/apps/frontend/src/routes/(share)/s/b/[shareId]/+layout.gql @@ -29,7 +29,14 @@ query GetShareBaseData($shareId: ID!) { views { id name + type isDefault + kanban { + field + } + gallery { + field + } } } } diff --git a/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/+layout.gql b/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/+layout.gql index c39771733..d0dd6d470 100644 --- a/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/+layout.gql +++ b/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/+layout.gql @@ -26,6 +26,13 @@ query GetBaseTableShareData($shareId: ID!, $tableId: ID!) { name isDefault fields + type + kanban { + field + } + gallery { + field + } } schema { constraint diff --git a/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/+layout.svelte b/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/+layout.svelte index 7ef299ce5..d23c6d5f6 100644 --- a/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/+layout.svelte +++ b/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/+layout.svelte @@ -15,6 +15,7 @@ const table = writable() $: { if (!fetching && tableDTO) { + // @ts-ignore table.set(new TableCreator().fromJSON(tableDTO)) setTable(table) } diff --git a/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/[[viewId]]/+page.svelte b/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/[[viewId]]/+page.svelte index 0d94d1df9..49e017b15 100644 --- a/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/[[viewId]]/+page.svelte +++ b/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/[[viewId]]/+page.svelte @@ -1,7 +1,6 @@
- {#if $isDataTab} - + {#if view?.type === "grid"} + + {:else if view.type === "kanban"} + + {:else if view.type === "gallery"} + + {/if} {:else if $isFormTab} {/if}