diff --git a/ui/console-src/modules/dashboard/Dashboard.vue b/ui/console-src/modules/dashboard/Dashboard.vue index fd50baac2..0dc5ba34f 100644 --- a/ui/console-src/modules/dashboard/Dashboard.vue +++ b/ui/console-src/modules/dashboard/Dashboard.vue @@ -6,10 +6,10 @@ import { VPageHeader, } from "@halo-dev/components"; import type { DashboardWidgetDefinition } from "@halo-dev/console-shared"; -import { computed, type ComputedRef, provide, ref } from "vue"; +import { computed, type ComputedRef, provide, ref, toRaw } from "vue"; import WidgetViewItem from "./components/WidgetViewItem.vue"; import { useDashboardExtensionPoint } from "./composables/use-dashboard-extension-point"; -import { useDashboardWidgetsFetch } from "./composables/use-dashboard-widgets-fetch"; +import { useDashboardWidgetsViewFetch } from "./composables/use-dashboard-widgets-fetch"; import "./styles/dashboard.css"; import { internalWidgetDefinitions } from "./widgets"; @@ -19,7 +19,7 @@ function breakpointChangedEvent(breakpoint: string) { currentBreakpoint.value = breakpoint; } -const { layouts, layout } = useDashboardWidgetsFetch(currentBreakpoint); +const { data } = useDashboardWidgetsViewFetch(currentBreakpoint); const { widgetDefinitions } = useDashboardExtensionPoint(); @@ -52,8 +52,8 @@ provide>(
>( :cols="{ lg: 12, md: 12, sm: 6, xs: 4 }" @breakpoint-changed="breakpointChangedEvent" > - +
diff --git a/ui/console-src/modules/dashboard/DashboardDesigner.vue b/ui/console-src/modules/dashboard/DashboardDesigner.vue index ca3df11b0..4cb6e788e 100644 --- a/ui/console-src/modules/dashboard/DashboardDesigner.vue +++ b/ui/console-src/modules/dashboard/DashboardDesigner.vue @@ -254,6 +254,10 @@ async function handleSave() { await queryClient.invalidateQueries({ queryKey: ["core:dashboard:widgets"], }); + + await queryClient.invalidateQueries({ + queryKey: ["core:dashboard:widgets:view"], + }); } catch (error) { console.error("Failed to save dashboard widgets config", error); } finally { diff --git a/ui/console-src/modules/dashboard/composables/use-dashboard-widgets-fetch.ts b/ui/console-src/modules/dashboard/composables/use-dashboard-widgets-fetch.ts index f7a872cfc..03e4792b5 100644 --- a/ui/console-src/modules/dashboard/composables/use-dashboard-widgets-fetch.ts +++ b/ui/console-src/modules/dashboard/composables/use-dashboard-widgets-fetch.ts @@ -43,3 +43,23 @@ export function useDashboardWidgetsFetch(breakpoint: Ref) { isLoading, }; } + +export function useDashboardWidgetsViewFetch(breakpoint: Ref) { + return useQuery({ + queryKey: ["core:dashboard:widgets:view", breakpoint], + queryFn: async () => { + const { data } = await ucApiClient.user.preference.getMyPreference({ + group: "dashboard-widgets", + }); + + const layouts = (data || + DefaultResponsiveLayouts) as DashboardResponsiveLayout; + + return { + layouts, + layout: layouts[breakpoint.value] || layouts.lg || [], + }; + }, + enabled: computed(() => !!breakpoint.value), + }); +}