diff --git a/apps/frontend/src/lib/components/blocks/aggregate/aggregate.svelte b/apps/frontend/src/lib/components/blocks/aggregate/aggregate.svelte index 75f24897f..8f4084d85 100644 --- a/apps/frontend/src/lib/components/blocks/aggregate/aggregate.svelte +++ b/apps/frontend/src/lib/components/blocks/aggregate/aggregate.svelte @@ -7,8 +7,7 @@ import { TriangleAlertIcon } from "lucide-svelte" import * as Tooltip from "$lib/components/ui/tooltip" import type { TableDo } from "@undb/table" - import { getDataService, getIsLocal } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" export let tableId: string | undefined export let table: TableDo | undefined @@ -22,8 +21,7 @@ $: isValid = isValidWidget(widget) && !!tableId - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const getAggregate = createQuery({ queryKey: ["aggregate", widget.id], @@ -43,7 +41,6 @@ ignoreView, }) } - const dataService = await getDataService(isLocal, isPlayground) return dataService.records.getAggregates({ tableId: tableId!, viewId, diff --git a/apps/frontend/src/lib/components/blocks/bulk-update-records/bulk-update-records.svelte b/apps/frontend/src/lib/components/blocks/bulk-update-records/bulk-update-records.svelte index cf38522f9..261c5c663 100644 --- a/apps/frontend/src/lib/components/blocks/bulk-update-records/bulk-update-records.svelte +++ b/apps/frontend/src/lib/components/blocks/bulk-update-records/bulk-update-records.svelte @@ -28,9 +28,7 @@ import autoAnimate from "@formkit/auto-animate" import type { Readable } from "svelte/store" import { LL } from "@undb/i18n/client" - import { getDataService, getIsLocal } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - + import { getDataService } from "$lib/store/data-service.store" const table = getTable() export let viewId: Readable @@ -44,17 +42,15 @@ export let filter: IViewFilterGroup | undefined = undefined export let onSuccess: (data: IBulkUpdateRecordsCommandOutput) => void = () => {} - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() - let selectedFieldIds: string[] = [] $: selectedFields = selectedFieldIds.map((id) => $table.schema.getFieldById(new FieldIdVo(id)).unwrap()) const client = useQueryClient() + const dataService = getDataService() + const updateRecordMutation = createMutation({ mutationFn: async (command: IBulkUpdateRecordsCommand) => { - const dataService = await getDataService(isLocal, isPlayground) return dataService.records.updateRecords(command) }, onSuccess: async (data) => { diff --git a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-date-remove-button.svelte b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-date-remove-button.svelte index c78830001..e9b68b94c 100644 --- a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-date-remove-button.svelte +++ b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-date-remove-button.svelte @@ -8,8 +8,7 @@ import { useQueryClient } from "@tanstack/svelte-query" import { cn } from "$lib/utils" import { calendarStore } from "$lib/store/calendar.store" - import { getDataService, getIsLocal } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" import { type IUpdateRecordCommand } from "@undb/commands" export let view: CalendarView @@ -21,12 +20,10 @@ let field = fieldId ? $t.schema.getFieldById(new FieldIdVo(fieldId)).into(undefined) : undefined - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const updateRecord = createMutation({ mutationFn: async (command: IUpdateRecordCommand) => { - const dataService = await getDataService(isLocal, isPlayground) return dataService.records.updateRecord(command) }, }) diff --git a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-field-form.svelte b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-field-form.svelte index c410fc062..0af576ea5 100644 --- a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-field-form.svelte +++ b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-field-form.svelte @@ -6,15 +6,13 @@ import { defaults, superForm } from "sveltekit-superforms" import { zodClient } from "sveltekit-superforms/adapters" import CreateFieldButton from "../create-field/create-field-button.svelte" - import { trpc } from "$lib/trpc/client" import { createMutation } from "@tanstack/svelte-query" import { toast } from "svelte-sonner" import { invalidate } from "$app/navigation" import { hasPermission } from "$lib/store/space-member.store" import { CircleCheckBigIcon } from "lucide-svelte" import { LL } from "@undb/i18n/client" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" import { type IUpdateViewCommand } from "@undb/commands" export let readonly = false @@ -52,12 +50,10 @@ const { enhance, form: formData } = form - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const updateViewMutation = createMutation({ mutationFn: async (command: IUpdateViewCommand) => { - const dataService = await getDataService(isLocal, isPlayground) return dataService.table.view.updateView(command) }, mutationKey: ["updateView"], diff --git a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-timescale-picker.svelte b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-timescale-picker.svelte index 8f97ff3e5..7e1af333b 100644 --- a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-timescale-picker.svelte +++ b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-timescale-picker.svelte @@ -10,13 +10,10 @@ import { LL } from "@undb/i18n/client" import { calendarTimeScales, type CalendarTimeScale, type CalendarView } from "@undb/table" import { createMutation } from "@tanstack/svelte-query" - import { trpc } from "$lib/trpc/client" - import { toast } from "svelte-sonner" import { getTable } from "$lib/store/table.store" import { invalidate } from "$app/navigation" import { type ICalendarViewDTO } from "@undb/table" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" import { type IUpdateViewCommand } from "@undb/commands" export let view: CalendarView @@ -41,12 +38,10 @@ }) } - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const updateViewMutation = createMutation({ mutationFn: async (command: IUpdateViewCommand) => { - const dataService = await getDataService(isLocal, isPlayground) return dataService.table.view.updateView(command) }, mutationKey: ["updateView"], diff --git a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-day-timeline.svelte b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-day-timeline.svelte index 2ac271aa1..d504d6c1d 100644 --- a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-day-timeline.svelte +++ b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-day-timeline.svelte @@ -29,8 +29,7 @@ import { CREATE_RECORD_MODAL, openModal } from "$lib/store/modal.store" import { tick } from "svelte" import { hasPermission } from "$lib/store/space-member.store" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" import { type IUpdateRecordCommand } from "@undb/commands" export let viewId: Readable @@ -106,8 +105,7 @@ const t = getTable() const q = queryParam("q") - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const getRecords = createQuery( derived([t, viewId, q, date], ([$table, $viewId, $q, $date]) => { @@ -116,7 +114,6 @@ queryKey: ["records", $table?.id.value, $viewId, $q, $date.toISOString()], enabled: view?.type === "calendar" && !disableRecordQuery, queryFn: async () => { - const dataService = await getDataService(isLocal, isPlayground) const value = format($date, "yyyy-MM-dd") if (shareId) { return trpc.shareData.records.query({ @@ -258,10 +255,7 @@ let overMinutes: number | undefined = undefined const updateRecord = createMutation({ - mutationFn: async (command: IUpdateRecordCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.records.updateRecord(command) - }, + mutationFn: dataService.records.updateRecord, }) const client = useQueryClient() diff --git a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-date.svelte b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-date.svelte index 9fa8a3c49..96dc10473 100644 --- a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-date.svelte +++ b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-date.svelte @@ -10,16 +10,13 @@ import { isToday } from "date-fns/isToday" import { isWeekend } from "date-fns/isWeekend" import { createMutation, useQueryClient } from "@tanstack/svelte-query" - import { trpc } from "$lib/trpc/client" import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter" import { format } from "date-fns/format" import { cn } from "$lib/utils" import { CREATE_RECORD_MODAL, openModal } from "$lib/store/modal.store" import { defaultRecordValues } from "$lib/store/records.store" import { type Readable } from "svelte/store" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - import { type IUpdateRecordCommand } from "@undb/commands" + import { getDataService } from "$lib/store/data-service.store" export let field: DateField | DateRangeField export let date: Date @@ -36,8 +33,7 @@ const isSelected = calendarStore.isSelected const getIsSameMonth = calendarStore.getIsSameMonth - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() $: color = $viewId ? $table.views.getViewById($viewId)?.color.into(undefined) : undefined @@ -90,10 +86,7 @@ } const updateRecord = createMutation({ - mutationFn: async (command: IUpdateRecordCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.records.updateRecord(command) - }, + mutationFn: dataService.records.updateRecord, }) const client = useQueryClient() diff --git a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-records.svelte b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-records.svelte index ffdc89e82..e44deb7fd 100644 --- a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-records.svelte +++ b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-records.svelte @@ -20,8 +20,7 @@ import { CalendarView } from "@undb/table" import { type MaybeConditionGroup, type IViewFilterOptionSchema } from "@undb/table" import { LL } from "@undb/i18n/client" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" export let viewId: Readable export let view: CalendarView @@ -31,8 +30,8 @@ export let readonly = false const t = getTable() - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + + const dataService = getDataService() let defaultField = $t.schema.getDefaultDisplayField().into(undefined) @@ -102,7 +101,6 @@ return { queryKey: ["records", $table?.id.value, $viewId, $scope, dateString, $search], queryFn: async ({ pageParam = 1 }) => { - const dataService = await getDataService(isLocal, isPlayground) if (shareId) { return trpc.shareData.records.query({ shareId, diff --git a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month.svelte b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month.svelte index f02d2b0f1..d61720548 100644 --- a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month.svelte +++ b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month.svelte @@ -9,11 +9,9 @@ import { createQuery } from "@tanstack/svelte-query" import { queryParam } from "sveltekit-search-params" import CalendarDateRemoveButton from "./calendar-date-remove-button.svelte" - import CalendarViewMiniMonth from "./calendar-view-mini-month.svelte" import CalendarViewMonthRecords from "./calendar-view-month-records.svelte" import CalendarViewMonthDate from "./calendar-view-month-date.svelte" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" export let viewId: Readable export let view: CalendarView @@ -28,8 +26,7 @@ const t = getTable() const q = queryParam("q") - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const getRecords = createQuery( derived([t, viewId, q, startTimestamp, endTimestamp], ([$table, $viewId, $q, $startTimestamp, $endTimestamp]) => { @@ -45,7 +42,6 @@ ], enabled: view?.type === "calendar" && !!$startTimestamp && !!$endTimestamp && !disableRecordQuery, queryFn: async () => { - const dataService = await getDataService(isLocal, isPlayground) if (shareId) { return trpc.shareData.records.query({ shareId, diff --git a/apps/frontend/src/lib/components/blocks/calendar-view/select-calendar-field-form.svelte b/apps/frontend/src/lib/components/blocks/calendar-view/select-calendar-field-form.svelte index a31a1d158..0c1e82e44 100644 --- a/apps/frontend/src/lib/components/blocks/calendar-view/select-calendar-field-form.svelte +++ b/apps/frontend/src/lib/components/blocks/calendar-view/select-calendar-field-form.svelte @@ -14,9 +14,7 @@ import { CircleCheckBigIcon } from "lucide-svelte" import * as Form from "$lib/components/ui/form" import { LL } from "@undb/i18n/client" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - import { type IUpdateViewCommand } from "@undb/commands" + import { getDataService } from "$lib/store/data-service.store" export let readonly = false @@ -64,14 +62,10 @@ const { enhance, form: formData, validateForm } = form - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const updateViewMutation = createMutation({ - mutationFn: async (command: IUpdateViewCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.view.updateView(command) - }, + mutationFn: dataService.table.view.updateView, mutationKey: ["updateView"], async onSuccess(data, variables, context) { toast.success($LL.table.view.updated()) diff --git a/apps/frontend/src/lib/components/blocks/create-base/create-base.svelte b/apps/frontend/src/lib/components/blocks/create-base/create-base.svelte index 924d9afdc..96318819c 100644 --- a/apps/frontend/src/lib/components/blocks/create-base/create-base.svelte +++ b/apps/frontend/src/lib/components/blocks/create-base/create-base.svelte @@ -11,17 +11,14 @@ import { LoaderCircleIcon } from "lucide-svelte" import { getNextName } from "@undb/utils" import { LL } from "@undb/i18n/client" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" + import { getDataService } from "$lib/store/data-service.store" import { getIsPlayground } from "$lib/store/playground.svelte" - const isLocal = getIsLocal() const isPlayground = getIsPlayground() + const dataService = getDataService() const mutation = createMutation({ - mutationFn: async (command: ICreateBaseCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.base.createBase(command) - }, + mutationFn: dataService.base.createBase, async onSuccess(data) { form.reset() if (isPlayground) { diff --git a/apps/frontend/src/lib/components/blocks/create-field/create-field.svelte b/apps/frontend/src/lib/components/blocks/create-field/create-field.svelte index 2f77d843d..ca1c50cfb 100644 --- a/apps/frontend/src/lib/components/blocks/create-field/create-field.svelte +++ b/apps/frontend/src/lib/components/blocks/create-field/create-field.svelte @@ -15,9 +15,7 @@ import FieldTypePicker from "../field-picker/field-type-picker.svelte" import { LL } from "@undb/i18n/client" import { BetweenVerticalStartIcon, LoaderCircleIcon } from "lucide-svelte" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - import { type ICreateFieldCommand } from "@undb/commands" + import { getDataService } from "$lib/store/data-service.store" const table = getTable() @@ -25,17 +23,13 @@ let name = "" - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const client = useQueryClient() const createFieldMutation = createMutation( derived([table], ([$table]) => ({ mutationKey: ["table", $table.id.value, "createField"], - mutationFn: async (command: ICreateFieldCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.field.createField(command) - }, + mutationFn: dataService.table.field.createField, async onSuccess() { toast.success($LL.table.field.created()) reset() diff --git a/apps/frontend/src/lib/components/blocks/create-record/create-record.svelte b/apps/frontend/src/lib/components/blocks/create-record/create-record.svelte index 5c8d61e41..a5c30963b 100644 --- a/apps/frontend/src/lib/components/blocks/create-record/create-record.svelte +++ b/apps/frontend/src/lib/components/blocks/create-record/create-record.svelte @@ -16,9 +16,7 @@ import type { ICreateRecordCommand, ICreateRecordCommandOutput } from "@undb/commands" import { onMount } from "svelte" import { LL } from "@undb/i18n/client" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - + import { getDataService } from "$lib/store/data-service.store" // beforeNavigate(({ cancel }) => { // if ($tainted) { @@ -42,15 +40,11 @@ const client = useQueryClient() const mediaQuery = useMediaQuery("(max-width: 768px)") - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const createRecordMutation = createMutation( derived([table], ([$table]) => ({ - mutationFn: async (command: ICreateRecordCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.records.createRecord(command) - }, + mutationFn: dataService.records.createRecord, mutationKey: [$table.id.value, "createRecord"], onSuccess: (data: ICreateRecordCommandOutput) => { client.invalidateQueries({ diff --git a/apps/frontend/src/lib/components/blocks/create-table/create-table.svelte b/apps/frontend/src/lib/components/blocks/create-table/create-table.svelte index f0d171610..4c13ace71 100644 --- a/apps/frontend/src/lib/components/blocks/create-table/create-table.svelte +++ b/apps/frontend/src/lib/components/blocks/create-table/create-table.svelte @@ -13,20 +13,15 @@ import { CREATE_TABLE_MODAL, closeModal } from "$lib/store/modal.store" import { baseId, currentBase, currentBaseId } from "$lib/store/base.store" import { getNextName } from "@undb/utils" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const schema = createTableCommand.omit({ baseId: true }) export let tableNames: string[] const mutation = createMutation({ - mutationFn: async (command: ICreateTableCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.createTable(command) - }, + mutationFn: dataService.table.createTable, mutationKey: ["createTable"], async onSuccess(data) { if (isPlayground) { diff --git a/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte b/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte index ca9718433..8d30dab56 100644 --- a/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte +++ b/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte @@ -4,10 +4,8 @@ import Widget from "../widget/widget.svelte" import { setTable } from "$lib/store/table.store" import { writable } from "svelte/store" - import { getIsLocal } from "$lib/store/data-service.store" import { getDataService } from "$lib/store/data-service.store" import { createQuery } from "@tanstack/svelte-query" - import { getIsPlayground } from "$lib/store/playground.svelte" export let tableId: string | undefined export let shareId: string | undefined = undefined @@ -16,8 +14,7 @@ export let movePointerDown: ((e: Event) => void) | undefined = undefined export let resizePointerDown: ((e: Event) => void) | undefined = undefined - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const shareStore = new GetDashboardWidgetShareTableStore() @@ -28,10 +25,7 @@ } const getTable = createQuery({ - queryFn: async () => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.getTable({ tableId: tableId! }) - }, + queryFn: () => dataService.table.getTable({ tableId: tableId! }), queryKey: ["dashboard-widget-table", tableId], enabled: !!tableId && !shareId, }) diff --git a/apps/frontend/src/lib/components/blocks/delete-table/delete-table-dialog.svelte b/apps/frontend/src/lib/components/blocks/delete-table/delete-table-dialog.svelte index aae924105..9d0b8381f 100644 --- a/apps/frontend/src/lib/components/blocks/delete-table/delete-table-dialog.svelte +++ b/apps/frontend/src/lib/components/blocks/delete-table/delete-table-dialog.svelte @@ -10,13 +10,11 @@ import { Label } from "$lib/components/ui/label" import { LL } from "@undb/i18n/client" import { type IDeleteTableCommand } from "@undb/commands" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" export let table = getTable() - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() // const foreignTableStore = new GetTableForeignTablesStore() // $: $isModalOpen(DELETE_TABLE_MODAL) && @@ -27,10 +25,7 @@ // $: foreignTables = $foreignTableStore.data?.tableForeignTables ?? [] const deleteTableMutation = createMutation({ - mutationFn: async (command: IDeleteTableCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.deleteTable(command) - }, + mutationFn: dataService.table.deleteTable, async onSuccess(data, variables, context) { await goto("/") await invalidateAll() diff --git a/apps/frontend/src/lib/components/blocks/field-control/button-control.svelte b/apps/frontend/src/lib/components/blocks/field-control/button-control.svelte index 308893d56..47dbd9b03 100644 --- a/apps/frontend/src/lib/components/blocks/field-control/button-control.svelte +++ b/apps/frontend/src/lib/components/blocks/field-control/button-control.svelte @@ -8,7 +8,7 @@ import { getTable } from "$lib/store/table.store" import { gridViewStore } from "../grid-view/grid-view.store" import { getRecordsStore } from "$lib/store/records.store" - import { getIsLocal } from "$lib/store/data-service.store" + import { getDataService, getIsLocal } from "$lib/store/data-service.store" import { getIsPlayground } from "$lib/store/playground.svelte" import { type IUpdateRecordCommand } from "@undb/commands" @@ -22,16 +22,14 @@ const client = useQueryClient() const recordsStore = getRecordsStore() + const dataService = getDataService() + const isLocal = getIsLocal() const isPlayground = getIsPlayground() - const updateCell = createMutation({ mutationKey: ["record", tableId, field.id.value, recordId], - mutationFn: async (command: IUpdateRecordCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.records.updateRecord(command) - }, + mutationFn: dataService.records.updateRecord, async onSuccess(data, variables, context) { gridViewStore.exitEditing() await recordsStore?.invalidateRecord(isLocal, isPlayground, $table, recordId) diff --git a/apps/frontend/src/lib/components/blocks/field-options/create-reference-field-optioin.svelte b/apps/frontend/src/lib/components/blocks/field-options/create-reference-field-optioin.svelte index 4823d5205..2818dd225 100644 --- a/apps/frontend/src/lib/components/blocks/field-options/create-reference-field-optioin.svelte +++ b/apps/frontend/src/lib/components/blocks/field-options/create-reference-field-optioin.svelte @@ -19,8 +19,7 @@ import autoAnimate from "@formkit/auto-animate" import { isEqual } from "radash" import { LL } from "@undb/i18n/client" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" import { createQuery } from "@tanstack/svelte-query" export let disabled = false @@ -34,16 +33,12 @@ condition: undefined, } - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() let allowCondition: boolean = !!option.condition const getForeignTable = createQuery({ - queryFn: async () => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.getTable({ tableId: option.foreignTableId! }) - }, + queryFn: () => dataService.table.getTable({ tableId: option.foreignTableId! }), queryKey: ["getForeignTable", option.foreignTableId], enabled: !!option.foreignTableId, }) diff --git a/apps/frontend/src/lib/components/blocks/field-options/rollup-field-option.svelte b/apps/frontend/src/lib/components/blocks/field-options/rollup-field-option.svelte index e48bfcdc1..bccfabcc9 100644 --- a/apps/frontend/src/lib/components/blocks/field-options/rollup-field-option.svelte +++ b/apps/frontend/src/lib/components/blocks/field-options/rollup-field-option.svelte @@ -14,12 +14,10 @@ import Label from "$lib/components/ui/label/label.svelte" import autoAnimate from "@formkit/auto-animate" import { LL } from "@undb/i18n/client" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" import { createQuery } from "@tanstack/svelte-query" - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() export let disabled: boolean = false @@ -36,7 +34,6 @@ const getForeignTable = createQuery({ queryFn: async () => { - const dataService = await getDataService(isLocal, isPlayground) return dataService.table.getTable({ tableId: foreignTableId! }) }, queryKey: ["getForeignTable", foreignTableId], diff --git a/apps/frontend/src/lib/components/blocks/field-options/update-reference-field-optioin.svelte b/apps/frontend/src/lib/components/blocks/field-options/update-reference-field-optioin.svelte index cca7356b0..a8c010c5a 100644 --- a/apps/frontend/src/lib/components/blocks/field-options/update-reference-field-optioin.svelte +++ b/apps/frontend/src/lib/components/blocks/field-options/update-reference-field-optioin.svelte @@ -21,8 +21,7 @@ import { onMount } from "svelte" import { isEqual } from "radash" import { LL } from "@undb/i18n/client" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" import { createQuery } from "@tanstack/svelte-query" export let constraint: IReferenceFieldConstraint | undefined = { @@ -37,12 +36,10 @@ let allowCondition: boolean = !!option.condition - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const getForeignTable = createQuery({ queryFn: async () => { - const dataService = await getDataService(isLocal, isPlayground) return dataService.table.getTable({ tableId: option.foreignTableId! }) }, queryKey: ["getForeignTable", option.foreignTableId], diff --git a/apps/frontend/src/lib/components/blocks/field/field-menu.svelte b/apps/frontend/src/lib/components/blocks/field/field-menu.svelte index a97c90009..9358ed386 100644 --- a/apps/frontend/src/lib/components/blocks/field/field-menu.svelte +++ b/apps/frontend/src/lib/components/blocks/field/field-menu.svelte @@ -18,15 +18,12 @@ import { preferences } from "$lib/store/persisted.store" import { hasPermission } from "$lib/store/space-member.store" import { LL } from "@undb/i18n/client" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - import { type IDeleteFieldCommand, type IDuplicateFieldCommand } from "@undb/commands" + import { getDataService } from "$lib/store/data-service.store" export let field: Field const table = getTable() - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() export let update = false export let open = false @@ -34,10 +31,7 @@ const client = useQueryClient() const getForeignTable = createQuery({ - queryFn: async () => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.getTable({ tableId: (field as ReferenceField).foreignTableId }) - }, + queryFn: () => dataService.table.getTable({ tableId: $table.id.value }), queryKey: ["getForeignTable", $table.baseId], enabled: field.type === "reference", }) @@ -60,10 +54,7 @@ }) const deleteField = createMutation({ - mutationFn: async (command: IDeleteFieldCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.field.deleteField(command) - }, + mutationFn: dataService.table.field.deleteField, async onSuccess() { toast.success($LL.table.field.deleted()) await invalidate(`undb:table:${$table.id.value}`) @@ -77,10 +68,7 @@ }) const duplicateField = createMutation({ - mutationFn: async (command: IDuplicateFieldCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.field.duplicateField(command) - }, + mutationFn: dataService.table.field.duplicateField, async onSuccess() { toast.success("Duplicate field success") await invalidate(`undb:table:${$table.id.value}`) diff --git a/apps/frontend/src/lib/components/blocks/gallery-view/gallery-view-field-form.svelte b/apps/frontend/src/lib/components/blocks/gallery-view/gallery-view-field-form.svelte index 80db9f510..e4e4542f5 100644 --- a/apps/frontend/src/lib/components/blocks/gallery-view/gallery-view-field-form.svelte +++ b/apps/frontend/src/lib/components/blocks/gallery-view/gallery-view-field-form.svelte @@ -12,8 +12,7 @@ import { invalidate } from "$app/navigation" import { CircleCheckBigIcon } from "lucide-svelte" import { LL } from "@undb/i18n/client" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" import { type IUpdateViewCommand } from "@undb/commands" const table = getTable() @@ -50,14 +49,10 @@ const { enhance, form: formData } = form - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const updateViewMutation = createMutation({ - mutationFn: async (command: IUpdateViewCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.view.updateView(command) - }, + mutationFn: dataService.table.view.updateView, mutationKey: ["updateView"], async onSuccess(data, variables, context) { toast.success($LL.table.view.updated()) 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 a1d8675a5..69b6c568c 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 @@ -13,8 +13,7 @@ import { cn } from "$lib/utils" import GalleryViewLoading from "./gallery-view-loading.svelte" import GalleryViewOptionButton from "./gallery-option-button.svelte" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" const table = getTable() export let viewId: Readable @@ -31,8 +30,8 @@ const perPage = writable(50) const currentPage = writable(1) const q = queryParam("q") - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + + const dataService = getDataService() const getRecords = async () => { if (shareId) { @@ -44,7 +43,6 @@ pagination: { limit: $perPage, page: $currentPage }, }) } - const dataService = await getDataService(isLocal, isPlayground) return dataService.records.getRecords({ tableId: $table?.id.value, viewId: $viewId, diff --git a/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/attachment-cell.svelte b/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/attachment-cell.svelte index 0c15a15f6..fbb045ff3 100644 --- a/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/attachment-cell.svelte +++ b/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/attachment-cell.svelte @@ -9,9 +9,7 @@ import * as Dialog from "$lib/components/ui/dialog" import * as AlertDialog from "$lib/components/ui/alert-dialog" import { AspectRatio } from "$lib/components/ui/aspect-ratio" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - import { type IUpdateRecordCommand } from "@undb/commands" + import { getDataService } from "$lib/store/data-service.store" export let tableId: string export let value: IAttachmentFieldValue | undefined = undefined @@ -23,15 +21,11 @@ $: max = field.max $: disabled = value?.length ?? 0 >= max - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const updateCell = createMutation({ mutationKey: ["record", tableId, field.id.value, recordId], - mutationFn: async (command: IUpdateRecordCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.records.updateRecord(command) - }, + mutationFn: dataService.records.updateRecord, onError(error: Error) { toast.error(error.message) }, diff --git a/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/checkbox-cell.svelte b/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/checkbox-cell.svelte index bac7b976a..13ca891f9 100644 --- a/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/checkbox-cell.svelte +++ b/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/checkbox-cell.svelte @@ -5,9 +5,7 @@ import { createMutation } from "@tanstack/svelte-query" import type { CheckboxField } from "@undb/table" import { toast } from "svelte-sonner" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - import { type IUpdateRecordCommand } from "@undb/commands" + import { getDataService } from "$lib/store/data-service.store" export let tableId: string export let field: CheckboxField @@ -16,15 +14,11 @@ export let readonly = false export let onValueChange: (value: boolean) => void - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const updateCell = createMutation({ mutationKey: ["record", tableId, field.id.value, recordId], - mutationFn: async (command: IUpdateRecordCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.records.updateRecord(command) - }, + mutationFn: dataService.records.updateRecord, onError(error: Error) { toast.error(error.message) }, diff --git a/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/currency-cell.svelte b/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/currency-cell.svelte index 9e89d128b..33e466b61 100644 --- a/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/currency-cell.svelte +++ b/apps/frontend/src/lib/components/blocks/grid-view/editable-cell/currency-cell.svelte @@ -1,14 +1,11 @@
@@ -28,8 +32,12 @@
{/each} {:else} - {#each templates as template} - - {/each} + {#await registry.register(isLocal, isPlayground)} + loading + {:then dataService} + {#each templates as template} + + {/each} + {/await} {/if} diff --git a/apps/frontend/src/lib/components/blocks/template/template-preview.svelte b/apps/frontend/src/lib/components/blocks/template/template-preview.svelte index 7416a3349..74b87d581 100644 --- a/apps/frontend/src/lib/components/blocks/template/template-preview.svelte +++ b/apps/frontend/src/lib/components/blocks/template/template-preview.svelte @@ -10,16 +10,13 @@ import RecordDetailSheet from "$lib/components/blocks/record-detail/record-detail-sheet.svelte" import View from "$lib/components/blocks/view/view.svelte" import { onMount } from "svelte" - import { registry } from "$lib/registry.svelte" - import { setIsLocal } from "$lib/store/data-service.store" - import { type DataService, getDataService } from "@undb/data-service" + import { getDataService, setIsLocal } from "$lib/store/data-service.store" import { createQuery } from "@tanstack/svelte-query" import { preferences } from "$lib/store/persisted.store" import { RecordDO } from "@undb/table" import { templateStore } from "$lib/store/template.store.svelte" import { setDashboard } from "$lib/store/dashboard.store" import DashboardWidgets from "$lib/components/blocks/dashboard/dashboard-widgets.svelte" - import { getIsPlayground } from "$lib/store/playground.svelte" export let template: ITemplateDTO @@ -43,14 +40,13 @@ let r = writable(null) - const isPlayground = getIsPlayground() + let dataService = getDataService() const record = createQuery( derived([currentTable, r, preferences], ([$table, $recordId, $preferences]) => ({ queryKey: [$recordId, "get", $preferences.showHiddenFields], enabled: !!$table && !!$recordId, queryFn: async () => { - const dataService = getDataService(true, isPlayground) return dataService.records.getRecordById({ tableId: $table?.id.value, id: $recordId!, @@ -78,17 +74,13 @@ } : {} - let dataService: DataService let saved = false onMount(async () => { - await registry.register(true) - if (templateStore.isTemplateSaved(template.id)) { saved = true return } - dataService = getDataService(true, isPlayground) await dataService.template.save(t, true) templateStore.saveTemplate(template.id, t) saved = true diff --git a/apps/frontend/src/lib/components/blocks/update-field/update-field.svelte b/apps/frontend/src/lib/components/blocks/update-field/update-field.svelte index dbbfd546a..afc6004b6 100644 --- a/apps/frontend/src/lib/components/blocks/update-field/update-field.svelte +++ b/apps/frontend/src/lib/components/blocks/update-field/update-field.svelte @@ -28,8 +28,7 @@ import { LoaderCircleIcon, PencilIcon } from "lucide-svelte" import { LL } from "@undb/i18n/client" import { getIsFieldCanCastTo } from "@undb/table" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" import { type IUpdateFieldCommand } from "@undb/commands" const table = getTable() @@ -43,17 +42,13 @@ $: isTypeChanged = type !== updatedType - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const client = useQueryClient() const updateFieldMutation = createMutation( derived([table], ([$table]) => ({ mutationKey: ["table", $table.id.value, "updateField"], - mutationFn: async (command: IUpdateFieldCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.field.updateField(command) - }, + mutationFn: dataService.table.field.updateField, async onSuccess() { onSuccess() toast.success($LL.table.field.updated()) diff --git a/apps/frontend/src/lib/components/blocks/view-color-editor/view-color-editor.svelte b/apps/frontend/src/lib/components/blocks/view-color-editor/view-color-editor.svelte index 7215b8358..91b82e428 100644 --- a/apps/frontend/src/lib/components/blocks/view-color-editor/view-color-editor.svelte +++ b/apps/frontend/src/lib/components/blocks/view-color-editor/view-color-editor.svelte @@ -4,7 +4,6 @@ import { FilterXIcon, PaintBucketIcon } from "lucide-svelte" import FiltersEditor from "../filters-editor/filters-editor.svelte" import { getTable } from "$lib/store/table.store" - import { trpc } from "$lib/trpc/client" import { createMutation } from "@tanstack/svelte-query" import { invalidate } from "$app/navigation" import { writable } from "svelte/store" @@ -20,15 +19,12 @@ import { hasPermission } from "$lib/store/space-member.store" import type { Readable } from "svelte/store" import { LL } from "@undb/i18n/client" - import type { ISetViewColorCommand } from "@undb/commands" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" export let readonly = false export let viewId: Readable - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const table = getTable() $: color = $table.views.getViewById($viewId).color.into(undefined) @@ -43,10 +39,7 @@ const mutation = createMutation({ mutationKey: ["table", $table.id.value, "setColor"], - mutationFn: async (command: ISetViewColorCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.view.setColor(command) - }, + mutationFn: dataService.table.view.setColor, onSuccess: async () => { await invalidate(`undb:table:${$table.id.value}`) open = false diff --git a/apps/frontend/src/lib/components/blocks/view-fields/view-fields.svelte b/apps/frontend/src/lib/components/blocks/view-fields/view-fields.svelte index f9a73d21b..8c9dcd8bd 100644 --- a/apps/frontend/src/lib/components/blocks/view-fields/view-fields.svelte +++ b/apps/frontend/src/lib/components/blocks/view-fields/view-fields.svelte @@ -19,9 +19,7 @@ import CreateFieldButton from "../create-field/create-field-button.svelte" import { LL } from "@undb/i18n/client" import { EyeIcon, EyeOffIcon } from "lucide-svelte" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - import { type ISetViewFieldsCommand, type ISetViewOptionCommand } from "@undb/commands" + import { getDataService } from "$lib/store/data-service.store" export let readonly = false export let viewId: Readable @@ -44,15 +42,11 @@ return field && field.name.value.toLowerCase().includes($q.toLowerCase()) }) - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const client = useQueryClient() const setViewFieldsMutation = createMutation({ - mutationFn: async (command: ISetViewFieldsCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.view.setFields(command) - }, + mutationFn: dataService.table.view.setFields, mutationKey: ["table", $table.id.value, "setFields"], async onSuccess(data, variables, context) { await invalidate(`undb:table:${$table.id.value}`) @@ -84,10 +78,7 @@ $: viewOption = $table.getViewOption($viewId) const setViewOptionMutation = createMutation({ - mutationFn: async (command: ISetViewOptionCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.view.setOption(command) - }, + mutationFn: dataService.table.view.setOption, mutationKey: ["table", $table.id.value, "setOption"], async onSuccess(data, variables, context) { await invalidate(`undb:table:${$table.id.value}`) diff --git a/apps/frontend/src/lib/components/blocks/view-filter-editor/view-filter-editor.svelte b/apps/frontend/src/lib/components/blocks/view-filter-editor/view-filter-editor.svelte index 4958af0b2..26e57ce8c 100644 --- a/apps/frontend/src/lib/components/blocks/view-filter-editor/view-filter-editor.svelte +++ b/apps/frontend/src/lib/components/blocks/view-filter-editor/view-filter-editor.svelte @@ -19,9 +19,7 @@ import { hasPermission } from "$lib/store/space-member.store" import type { Readable } from "svelte/store" import { LL } from "@undb/i18n/client" - import { getDataService, getIsLocal } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - import type { ISetViewFilterCommand } from "@undb/commands" + import { getDataService } from "$lib/store/data-service.store" export let readonly = false export let viewId: Readable @@ -36,20 +34,15 @@ $: $table, value.set(filter?.toMaybeConditionGroup()) - $: visibleFields = $table.getOrderedVisibleFields() let open = false const client = useQueryClient() - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const mutation = createMutation({ mutationKey: ["table", $table.id.value, "setFilters"], - mutationFn: async (command: ISetViewFilterCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.view.setFilter(command) - }, + mutationFn: dataService.table.view.setFilter, onSuccess: async () => { await invalidate(`undb:table:${$table.id.value}`) await client.invalidateQueries({ queryKey: ["records", $table.id.value] }) diff --git a/apps/frontend/src/lib/components/blocks/view-sort/view-sort.svelte b/apps/frontend/src/lib/components/blocks/view-sort/view-sort.svelte index fc991f2e9..cc139ad9a 100644 --- a/apps/frontend/src/lib/components/blocks/view-sort/view-sort.svelte +++ b/apps/frontend/src/lib/components/blocks/view-sort/view-sort.svelte @@ -28,9 +28,7 @@ import { hasPermission } from "$lib/store/space-member.store" import { LL } from "@undb/i18n/client" import SortPicker from "./sort-picker.svelte" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - import type { ISetViewSortCommand } from "@undb/commands" + import { getDataService } from "$lib/store/data-service.store" export let readonly = false export let viewId: Readable @@ -54,8 +52,7 @@ let open = false - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() function addSort() { if (disabled) { @@ -67,10 +64,7 @@ const client = useQueryClient() const setViewSortMutation = createMutation({ mutationKey: ["table", $table.id.value, "setSort"], - mutationFn: async (command: ISetViewSortCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.view.setSort(command) - }, + mutationFn: dataService.table.view.setSort, async onSettled() { await invalidate(`undb:table:${$table.id.value}`) await client.invalidateQueries({ queryKey: ["records", $table.id.value] }) diff --git a/apps/frontend/src/lib/components/blocks/view/create-view-button.svelte b/apps/frontend/src/lib/components/blocks/view/create-view-button.svelte index 901106ad0..d54a218f3 100644 --- a/apps/frontend/src/lib/components/blocks/view/create-view-button.svelte +++ b/apps/frontend/src/lib/components/blocks/view/create-view-button.svelte @@ -21,8 +21,7 @@ import * as Tooltip from "$lib/components/ui/tooltip" import { CircleHelpIcon } from "lucide-svelte" import { LL } from "@undb/i18n/client" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" + import { getDataService } from "$lib/store/data-service.store" import { type ICreateViewCommand } from "@undb/commands" let open = false @@ -32,14 +31,10 @@ export let tableId: string export let viewNames: string[] - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const createViewMutation = createMutation({ - mutationFn: async (command: ICreateViewCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.view.createView(command) - }, + mutationFn: dataService.table.view.createView, mutationKey: ["table", tableId, "createView"], async onSuccess(data) { viewNames = [...viewNames, $formData.name] diff --git a/apps/frontend/src/lib/components/blocks/view/delete-view-dialog.svelte b/apps/frontend/src/lib/components/blocks/view/delete-view-dialog.svelte index 93622177d..d7bca187c 100644 --- a/apps/frontend/src/lib/components/blocks/view/delete-view-dialog.svelte +++ b/apps/frontend/src/lib/components/blocks/view/delete-view-dialog.svelte @@ -5,23 +5,17 @@ import { getTable } from "$lib/store/table.store" import { toast } from "svelte-sonner" import { goto, invalidate } from "$app/navigation" - import { getIsLocal, getDataService } from "$lib/store/data-service.store" - import { getIsPlayground } from "$lib/store/playground.svelte" - import type { IDeleteViewCommand } from "@undb/commands" + import { getDataService } from "$lib/store/data-service.store" import { type Readable } from "svelte/store" const table = getTable() export let viewId: Readable - const isLocal = getIsLocal() - const isPlayground = getIsPlayground() + const dataService = getDataService() const deleteViewMutation = createMutation({ mutationKey: ["table", $viewId, "deleteView"], - mutationFn: async (command: IDeleteViewCommand) => { - const dataService = await getDataService(isLocal, isPlayground) - return dataService.table.view.deleteView(command) - }, + mutationFn: dataService.table.view.deleteView, async onSuccess(data, variables, context) { await invalidate(`undb:table:${$table.id.value}`) if (isPlayground) { diff --git a/apps/frontend/src/lib/components/blocks/view/duplicate-view.svelte b/apps/frontend/src/lib/components/blocks/view/duplicate-view.svelte index abcd50e2e..9e77cd988 100644 --- a/apps/frontend/src/lib/components/blocks/view/duplicate-view.svelte +++ b/apps/frontend/src/lib/components/blocks/view/duplicate-view.svelte @@ -1,6 +1,5 @@