[release-2.0] fix: ui is not updated after the theme is activated in the production (#753)

This is an automated cherry-pick of #746

/assign ruibaby

```release-note
修复 Console 端激活主题之后页面没有更新数据的问题。
```
pull/755/head
Halo Dev Bot 2022-12-07 11:48:52 +08:00 committed by GitHub
parent 18012cd33b
commit c51a1e4a98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 38 deletions

View File

@ -1,20 +1,14 @@
import { apiClient } from "@/utils/api-client"; import { apiClient } from "@/utils/api-client";
import type { Theme } from "@halo-dev/api-client"; import type { Theme } from "@halo-dev/api-client";
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { ref } from "vue";
interface ThemeStoreState { export const useThemeStore = defineStore("theme", () => {
activatedTheme?: Theme; const activatedTheme = ref<Theme>();
}
export const useThemeStore = defineStore("theme", { async function fetchActivatedTheme() {
state: (): ThemeStoreState => ({
activatedTheme: undefined,
}),
actions: {
async fetchActivatedTheme() {
try { try {
const { data } = const { data } = await apiClient.extension.configMap.getv1alpha1ConfigMap(
await apiClient.extension.configMap.getv1alpha1ConfigMap(
{ {
name: "system", name: "system",
}, },
@ -37,10 +31,11 @@ export const useThemeStore = defineStore("theme", {
} }
); );
this.activatedTheme = themeData; activatedTheme.value = themeData;
} catch (e) { } catch (e) {
console.error("Failed to fetch active theme", e); console.error("Failed to fetch active theme", e);
} }
}, }
},
return { activatedTheme, fetchActivatedTheme };
}); });