mirror of
https://github.com/unraid/api.git
synced 2026-01-02 22:50:02 -06:00
fix: theme issues when sent from graph (#1424)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -940,14 +940,14 @@ type Theme {
|
|||||||
"""Whether to show the banner gradient"""
|
"""Whether to show the banner gradient"""
|
||||||
showBannerGradient: Boolean!
|
showBannerGradient: Boolean!
|
||||||
|
|
||||||
"""The background color of the header"""
|
|
||||||
headerBackgroundColor: String!
|
|
||||||
|
|
||||||
"""Whether to show the description in the header"""
|
"""Whether to show the description in the header"""
|
||||||
showHeaderDescription: Boolean!
|
showHeaderDescription: Boolean!
|
||||||
|
|
||||||
|
"""The background color of the header"""
|
||||||
|
headerBackgroundColor: String
|
||||||
|
|
||||||
"""The text color of the header"""
|
"""The text color of the header"""
|
||||||
headerPrimaryTextColor: String!
|
headerPrimaryTextColor: String
|
||||||
|
|
||||||
"""The secondary text color of the header"""
|
"""The secondary text color of the header"""
|
||||||
headerSecondaryTextColor: String
|
headerSecondaryTextColor: String
|
||||||
|
|||||||
@@ -28,17 +28,17 @@ export class Theme {
|
|||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
showBannerGradient: boolean = false;
|
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()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsHexColor()
|
@IsHexColor()
|
||||||
headerBackgroundColor?: string;
|
headerBackgroundColor?: string;
|
||||||
|
|
||||||
@Field(() => Boolean, { description: 'Whether to show the description in the header' })
|
@Field(() => String, { description: 'The text color of the header', nullable: true })
|
||||||
@IsBoolean()
|
|
||||||
showHeaderDescription: boolean = true;
|
|
||||||
|
|
||||||
@Field(() => String, { description: 'The text color of the header' })
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsHexColor()
|
@IsHexColor()
|
||||||
|
|||||||
@@ -66,20 +66,34 @@ export const useThemeStore = defineStore('theme', () => {
|
|||||||
if (data) {
|
if (data) {
|
||||||
theme.value = data;
|
theme.value = data;
|
||||||
} else {
|
} else {
|
||||||
const result = await load();
|
try {
|
||||||
if (result) {
|
const result = await load();
|
||||||
if (result.publicTheme) {
|
if (result && result.publicTheme) {
|
||||||
theme.value = {
|
theme.value = {
|
||||||
name: result.publicTheme.name.toLowerCase(),
|
name: result.publicTheme.name?.toLowerCase() || 'white',
|
||||||
banner: result.publicTheme.showBannerImage,
|
banner: result.publicTheme.showBannerImage ?? false,
|
||||||
bannerGradient: result.publicTheme.showBannerGradient,
|
bannerGradient: result.publicTheme.showBannerGradient ?? false,
|
||||||
bgColor: result.publicTheme.headerBackgroundColor,
|
bgColor: result.publicTheme.headerBackgroundColor || '',
|
||||||
descriptionShow: result.publicTheme.showHeaderDescription,
|
descriptionShow: result.publicTheme.showHeaderDescription ?? false,
|
||||||
metaColor: result.publicTheme.headerSecondaryTextColor || '',
|
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: '',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user