diff --git a/client/src/stores/dashboard.ts b/client/src/stores/dashboard.ts index dbcdcae3..69be8744 100644 --- a/client/src/stores/dashboard.ts +++ b/client/src/stores/dashboard.ts @@ -4,12 +4,17 @@ import type { DashboardConfigType, } from "@/gql/graphql"; import type { DashboardCourseConfigType } from "@/services/dashboard"; -import { fetchDashboardConfigv2, fetchStatisticData } from "@/services/dashboard"; +import { + fetchDashboardConfig, + fetchDashboardConfigv2, + fetchStatisticData, +} from "@/services/dashboard"; import { defineStore } from "pinia"; import type { Ref } from "vue"; import { ref } from "vue"; export const useDashboardStore = defineStore("dashboard", () => { + const dashboardConfigs: Ref = ref([]); const dashboardConfigsv2: Ref = ref([]); const currentDashboardConfig: Ref = ref(); const dashBoardDataCache: Record< @@ -25,6 +30,15 @@ export const useDashboardStore = defineStore("dashboard", () => { await loadDashboardDetails(); }; + const loadDashboardConfig = async () => { + if (dashboardConfigs.value.length > 0) return; + const configData = await fetchDashboardConfig(); + if (configData && configData.length > 0) { + dashboardConfigs.value = configData; + await switchAndLoadDashboardConfig(configData[0]); + } + }; + const loadDashboardDetails = async () => { loading.value = true; dashboardConfigsv2.value = await fetchDashboardConfigv2(); @@ -45,9 +59,11 @@ export const useDashboardStore = defineStore("dashboard", () => { }; return { + dashboardConfigs, dashboardConfigsv2, currentDashboardConfig, switchAndLoadDashboardConfig, + loadDashboardConfig, loadDashboardDetails, currentDashBoardData, loading,