Skip to content

Commit

Permalink
fix: fix always refetch data
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Sep 17, 2024
1 parent cb97465 commit 1d0faf1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions apps/frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Audit {
type Base {
id: ID!
name: String!
option: JSON
share: Share
tables: [Table]!
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { CREATE_TABLE_MODAL, IMPORT_TABLE_MODAL, toggleModal } from "$lib/store/modal.store"
import { CREATE_TABLE_MODAL, IMPORT_TABLE_MODAL, openModal, toggleModal } from "$lib/store/modal.store"
import { DatabaseIcon, ImportIcon, PlusCircleIcon, PlusIcon } from "lucide-svelte"
import * as Table from "$lib/components/ui/table"
import { goto } from "$app/navigation"
Expand Down Expand Up @@ -28,7 +28,7 @@
class="flex h-32 w-80 flex-col justify-between rounded-lg border bg-gray-100 px-4 py-7 text-left transition-all hover:bg-gray-200/50 hover:shadow-lg"
on:click={() => {
baseId.set(base.id)
toggleModal(CREATE_TABLE_MODAL)
openModal(CREATE_TABLE_MODAL)
}}
>
<PlusCircleIcon class="text-muted-foreground" />
Expand All @@ -40,7 +40,7 @@
class="flex h-32 w-80 flex-col justify-between rounded-lg border bg-gray-100 px-4 py-7 text-left transition-all hover:bg-gray-200/50 hover:shadow-lg"
on:click={() => {
baseId.set(base.id)
toggleModal(IMPORT_TABLE_MODAL)
openModal(IMPORT_TABLE_MODAL)
}}
>
<ImportIcon class="text-muted-foreground" />
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/lib/store/base.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { GetIndexQuery$result } from "$houdini"
import { derived, writable } from "svelte/store"
import { queryParam, ssp } from "sveltekit-search-params"

export const baseId = queryParam("baseId", ssp.string())
export const baseId = queryParam("baseId", ssp.string(), { pushHistory: false })

export const bases = writable<GetIndexQuery$result["bases"]>()

Expand Down
6 changes: 6 additions & 0 deletions apps/frontend/src/lib/store/modal.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export const isModalOpen = derived(modal, ($modal) => {
return (type: ModalType) => $modal?.includes(type) ?? false
})

export const openModal = (type: ModalType) => {
modal.update(($modal) => {
return $modal?.includes(type) ? $modal : [...($modal ?? []), type]
})
}

export const closeModal = (type: ModalType) => {
modal.update(($modal) => {
return $modal?.filter((m) => m !== type) ?? null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ query GetBaseQuery($baseId: ID!) {
base(id: $baseId) {
id
name
option

share {
enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export let data: PageData
$: getBaseStore = data.getBaseStore
let getBaseStore = data.getBaseStore
$: base = $getBaseStore.data?.base
</script>

Expand Down
6 changes: 3 additions & 3 deletions apps/frontend/src/routes/(authed)/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import type { LayoutLoad } from "./$types"
export const ssr = false

export const load: LayoutLoad = async (event) => {
const redirectURL = encodeURIComponent(event.url.pathname)
// const redirectURL = encodeURIComponent(event.url.pathname)

const search = new URLSearchParams({ redirect: redirectURL })
// const search = new URLSearchParams({ redirect: redirectURL })

const me = await event.fetch("/api/me?" + search.toString())
const me = await event.fetch("/api/me")
if (me.redirected) {
throw redirect(301, me.url)
}
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export class Graphql {
type Base {
id: ID!
name: String!
option: JSON
share: Share
tables: [Table]!
Expand Down

0 comments on commit 1d0faf1

Please sign in to comment.