fix: address code review feedback

- Fix git+ssh URL to git+https for @electron/node-gyp (build compatibility)
- Remove duplicate @fontsource packages from root package.json
- Refactor font state initialization to reduce code duplication
This commit is contained in:
Stefan de Vogelaere
2026-01-17 02:17:26 +01:00
parent 1a7bf27ead
commit b771b51842
3 changed files with 15 additions and 50 deletions

View File

@@ -43,40 +43,28 @@ export function ProjectThemeSection({ project }: ProjectThemeSectionProps) {
const [activeTab, setActiveTab] = useState<'dark' | 'light'>(isLightTheme ? 'light' : 'dark'); const [activeTab, setActiveTab] = useState<'dark' | 'light'>(isLightTheme ? 'light' : 'dark');
// Helper to validate fonts against available options // Helper to validate fonts against available options
const isValidSansFont = (font: string | undefined): boolean => { const isValidSansFont = (font?: string): boolean =>
if (!font) return false; !!font && UI_SANS_FONT_OPTIONS.some((opt) => opt.value === font);
return UI_SANS_FONT_OPTIONS.some((opt) => opt.value === font); const isValidMonoFont = (font?: string): boolean =>
}; !!font && UI_MONO_FONT_OPTIONS.some((opt) => opt.value === font);
const isValidMonoFont = (font: string | undefined): boolean => {
if (!font) return false; // Helper to get initial font value with validation
return UI_MONO_FONT_OPTIONS.some((opt) => opt.value === font); const getInitialFontValue = (font: string | undefined, validator: (f?: string) => boolean) =>
}; font && validator(font) ? font : DEFAULT_FONT_VALUE;
// Font local state - tracks what's selected when using custom fonts // Font local state - tracks what's selected when using custom fonts
// Falls back to default if stored font is not in available options // Falls back to default if stored font is not in available options
const [fontSansLocal, setFontSansLocal] = useState<string>( const [fontSansLocal, setFontSansLocal] = useState<string>(() =>
project.fontFamilySans && isValidSansFont(project.fontFamilySans) getInitialFontValue(project.fontFamilySans, isValidSansFont)
? project.fontFamilySans
: DEFAULT_FONT_VALUE
); );
const [fontMonoLocal, setFontMonoLocal] = useState<string>( const [fontMonoLocal, setFontMonoLocal] = useState<string>(() =>
project.fontFamilyMono && isValidMonoFont(project.fontFamilyMono) getInitialFontValue(project.fontFamilyMono, isValidMonoFont)
? project.fontFamilyMono
: DEFAULT_FONT_VALUE
); );
// Sync state when project changes // Sync state when project changes
useEffect(() => { useEffect(() => {
setFontSansLocal( setFontSansLocal(getInitialFontValue(project.fontFamilySans, isValidSansFont));
project.fontFamilySans && isValidSansFont(project.fontFamilySans) setFontMonoLocal(getInitialFontValue(project.fontFamilyMono, isValidMonoFont));
? project.fontFamilySans
: DEFAULT_FONT_VALUE
);
setFontMonoLocal(
project.fontFamilyMono && isValidMonoFont(project.fontFamilyMono)
? project.fontFamilyMono
: DEFAULT_FONT_VALUE
);
// Also sync the active tab based on current theme // Also sync the active tab based on current theme
const currentIsLight = lightThemes.some((t) => t.value === (project.theme || globalTheme)); const currentIsLight = lightThemes.some((t) => t.value === (project.theme || globalTheme));
setActiveTab(currentIsLight ? 'light' : 'dark'); setActiveTab(currentIsLight ? 'light' : 'dark');

18
package-lock.json generated
View File

@@ -13,13 +13,6 @@
"libs/*" "libs/*"
], ],
"dependencies": { "dependencies": {
"@fontsource/cascadia-code": "^5.2.3",
"@fontsource/iosevka": "^5.2.5",
"@fontsource/lato": "^5.2.7",
"@fontsource/montserrat": "^5.2.8",
"@fontsource/playfair-display": "^5.2.8",
"@fontsource/raleway": "^5.2.8",
"@fontsource/source-sans-3": "^5.2.9",
"cross-spawn": "7.0.6", "cross-spawn": "7.0.6",
"rehype-sanitize": "6.0.0", "rehype-sanitize": "6.0.0",
"tree-kill": "1.2.2" "tree-kill": "1.2.2"
@@ -1503,7 +1496,7 @@
}, },
"node_modules/@electron/node-gyp": { "node_modules/@electron/node-gyp": {
"version": "10.2.0-electron.1", "version": "10.2.0-electron.1",
"resolved": "git+ssh://git@github.com/electron/node-gyp.git#06b29aafb7708acef8b3669835c8a7857ebc92d2", "resolved": "git+https://github.com/electron/node-gyp.git#06b29aafb7708acef8b3669835c8a7857ebc92d2",
"integrity": "sha512-4MSBTT8y07YUDqf69/vSh80Hh791epYqGtWHO3zSKhYFwQg+gx9wi1PqbqP6YqC4WMsNxZ5l9oDmnWdK5pfCKQ==", "integrity": "sha512-4MSBTT8y07YUDqf69/vSh80Hh791epYqGtWHO3zSKhYFwQg+gx9wi1PqbqP6YqC4WMsNxZ5l9oDmnWdK5pfCKQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
@@ -2927,15 +2920,6 @@
"url": "https://github.com/sponsors/ayuhito" "url": "https://github.com/sponsors/ayuhito"
} }
}, },
"node_modules/@fontsource/playfair-display": {
"version": "5.2.8",
"resolved": "https://registry.npmjs.org/@fontsource/playfair-display/-/playfair-display-5.2.8.tgz",
"integrity": "sha512-fUEhib70SszNhQVsGbUMSsWJhr7Je0rdeuZdtGpDNu0GKF1xJM8QhpI/y0pckU25GcChXm9TLOmeZupkvvZo2g==",
"license": "OFL-1.1",
"funding": {
"url": "https://github.com/sponsors/ayuhito"
}
},
"node_modules/@fontsource/poppins": { "node_modules/@fontsource/poppins": {
"version": "5.2.7", "version": "5.2.7",
"resolved": "https://registry.npmjs.org/@fontsource/poppins/-/poppins-5.2.7.tgz", "resolved": "https://registry.npmjs.org/@fontsource/poppins/-/poppins-5.2.7.tgz",

View File

@@ -62,13 +62,6 @@
] ]
}, },
"dependencies": { "dependencies": {
"@fontsource/cascadia-code": "^5.2.3",
"@fontsource/iosevka": "^5.2.5",
"@fontsource/lato": "^5.2.7",
"@fontsource/montserrat": "^5.2.8",
"@fontsource/playfair-display": "^5.2.8",
"@fontsource/raleway": "^5.2.8",
"@fontsource/source-sans-3": "^5.2.9",
"cross-spawn": "7.0.6", "cross-spawn": "7.0.6",
"rehype-sanitize": "6.0.0", "rehype-sanitize": "6.0.0",
"tree-kill": "1.2.2" "tree-kill": "1.2.2"