Skip to content

Commit

Permalink
fix: load default preset
Browse files Browse the repository at this point in the history
  • Loading branch information
goldenmaya committed Feb 14, 2025
1 parent a9c25a7 commit 3cc13c9
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions client-app/core/composables/useThemeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,37 @@ function _useThemeContext() {
throw new Error("Can't get theme context");
}

const defaultThemePreset = themeContext.value?.preset;
const themePreset = await fetchThemePreset(themeConfig, themePresetName);

themeContext.value = {
...store,
settings: themeConfig.settings,
preset: themePreset ?? defaultThemePreset,
preset: themePreset,
storeSettings: store.settings,
};
}

async function fetchThemePreset(themeConfig: IThemeConfig, themePresetName?: string): Promise<IThemeConfigPreset> {
const preset = themePresetName ?? themeConfig.current;
const defaultThemePreset = themeContext.value?.preset;

if (typeof preset === "string") {
const presetFileName = preset.toLowerCase().replace(" ", "-");

const module = (await import(`@/assets/presets/${presetFileName}.json`)) as {
default: IThemeConfigPreset;
};
try {
const module = (await import(`@/assets/presets/${presetFileName}.json`)) as {
default: IThemeConfigPreset;
};

return module.default;
return module?.default;
} catch {
if (defaultThemePreset) {
return defaultThemePreset;
}
}
}

return preset;
return preset as IThemeConfigPreset;
}

function getThemeConfig() {
Expand Down

0 comments on commit 3cc13c9

Please sign in to comment.