From 75ad8381bd4f4045ab1d3aa84e08ecddfba27617 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Fri, 20 Jun 2025 09:50:45 -0400 Subject: [PATCH] fix: theme issues when sent from graph (#1424) ## Summary by CodeRabbit - **Bug Fixes** - Improved error handling and fallback logic when loading themes, ensuring default values are used if loading fails or data is missing. - **Refactor** - Updated theme customization options to improve type accuracy and allow certain color fields to be optional. --- api/generated-schema.graphql | 8 ++--- .../resolvers/customization/theme.model.ts | 12 +++---- web/store/theme.ts | 32 +++++++++++++------ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/api/generated-schema.graphql b/api/generated-schema.graphql index 997ff6372..c50e5705b 100644 --- a/api/generated-schema.graphql +++ b/api/generated-schema.graphql @@ -940,14 +940,14 @@ type Theme { """Whether to show the banner gradient""" showBannerGradient: Boolean! - """The background color of the header""" - headerBackgroundColor: String! - """Whether to show the description in the header""" showHeaderDescription: Boolean! + """The background color of the header""" + headerBackgroundColor: String + """The text color of the header""" - headerPrimaryTextColor: String! + headerPrimaryTextColor: String """The secondary text color of the header""" headerSecondaryTextColor: String diff --git a/api/src/unraid-api/graph/resolvers/customization/theme.model.ts b/api/src/unraid-api/graph/resolvers/customization/theme.model.ts index 060d95d87..ba9ba3454 100644 --- a/api/src/unraid-api/graph/resolvers/customization/theme.model.ts +++ b/api/src/unraid-api/graph/resolvers/customization/theme.model.ts @@ -28,17 +28,17 @@ export class Theme { @IsBoolean() showBannerGradient: boolean = false; - @Field(() => String, { description: 'The background color of the header' }) + @Field(() => Boolean, { description: 'Whether to show the description in the header' }) + @IsBoolean() + showHeaderDescription: boolean = true; + + @Field(() => String, { description: 'The background color of the header', nullable: true }) @IsOptional() @IsString() @IsHexColor() headerBackgroundColor?: string; - @Field(() => Boolean, { description: 'Whether to show the description in the header' }) - @IsBoolean() - showHeaderDescription: boolean = true; - - @Field(() => String, { description: 'The text color of the header' }) + @Field(() => String, { description: 'The text color of the header', nullable: true }) @IsOptional() @IsString() @IsHexColor() diff --git a/web/store/theme.ts b/web/store/theme.ts index 46c3241a0..11110e48d 100644 --- a/web/store/theme.ts +++ b/web/store/theme.ts @@ -66,20 +66,34 @@ export const useThemeStore = defineStore('theme', () => { if (data) { theme.value = data; } else { - const result = await load(); - if (result) { - if (result.publicTheme) { + try { + const result = await load(); + if (result && result.publicTheme) { theme.value = { - name: result.publicTheme.name.toLowerCase(), - banner: result.publicTheme.showBannerImage, - bannerGradient: result.publicTheme.showBannerGradient, - bgColor: result.publicTheme.headerBackgroundColor, - descriptionShow: result.publicTheme.showHeaderDescription, + name: result.publicTheme.name?.toLowerCase() || 'white', + banner: result.publicTheme.showBannerImage ?? false, + bannerGradient: result.publicTheme.showBannerGradient ?? false, + bgColor: result.publicTheme.headerBackgroundColor || '', + descriptionShow: result.publicTheme.showHeaderDescription ?? false, metaColor: result.publicTheme.headerSecondaryTextColor || '', - textColor: result.publicTheme.headerPrimaryTextColor, + textColor: result.publicTheme.headerPrimaryTextColor || '', }; + return; } + } catch (error) { + console.warn('Failed to load theme from server, using default:', error); } + + // Single fallback for both no data and error cases + theme.value = { + name: 'white', + banner: false, + bannerGradient: false, + bgColor: '', + descriptionShow: false, + metaColor: '', + textColor: '', + }; } };