Skip to content

Commit 566ebbc

Browse files
fix format and linting issue
1 parent d14fef5 commit 566ebbc

File tree

5 files changed

+38
-37
lines changed

5 files changed

+38
-37
lines changed

src/components/theme/theme-switcher.tsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
"use client";
22

33
import React, { useState } from "react";
4-
import {
5-
Search,
6-
Palette,
7-
Shuffle,
8-
Moon,
9-
Sun,
10-
Plus,
11-
X,
12-
ExternalLink,
13-
} from "lucide-react";
4+
import type { ThemePreset } from "@/contexts/theme/types";
5+
import { Search, Palette, Shuffle, Moon, Sun, Plus } from "lucide-react";
146

157
import { Button } from "@/components/ui/button";
168
import { Input } from "@/components/ui/input";
@@ -62,8 +54,8 @@ export function ThemeSwitcher({
6254
const [showImportDialog, setShowImportDialog] = useState(false);
6355

6456
// Use controlled or uncontrolled state
65-
const isOpen = controlledOpen !== undefined ? controlledOpen : internalOpen;
66-
const setIsOpen = onOpenChange || setInternalOpen;
57+
const isOpen = controlledOpen ?? internalOpen;
58+
const setIsOpen = onOpenChange ?? setInternalOpen;
6759

6860
// Filter themes based on search
6961
const filteredThemes = allThemes.filter((theme) =>
@@ -215,7 +207,7 @@ export function ThemeSwitcher({
215207
{!isLoading && filteredThemes.length === 0 && searchQuery && (
216208
<div className="flex items-center justify-center py-8">
217209
<div className="text-muted-foreground text-sm">
218-
No themes found matching "{searchQuery}"
210+
No themes found matching &quot;{searchQuery}&quot;
219211
</div>
220212
</div>
221213
)}
@@ -244,7 +236,7 @@ export function ThemeSwitcher({
244236
}
245237

246238
interface ThemeCardProps {
247-
theme: any;
239+
theme: ThemePreset;
248240
onSelect: () => void;
249241
previewColors: string[];
250242
}
@@ -262,7 +254,9 @@ function ThemeCard({ theme, onSelect, previewColors }: ThemeCardProps) {
262254
<div className="space-y-2">
263255
<div className="flex items-center justify-between">
264256
<span className="text-sm font-medium">{theme.name}</span>
265-
{!theme.isBuiltIn && <Badge variant="secondary">Custom</Badge>}
257+
{!(theme.isBuiltIn ?? false) && (
258+
<Badge variant="secondary">Custom</Badge>
259+
)}
266260
</div>
267261

268262
{/* Color Preview */}
@@ -298,7 +292,7 @@ function ImportThemeDialog({ open, onOpenChange }: ImportThemeDialogProps) {
298292

299293
try {
300294
setError("");
301-
await importTheme(url.trim());
295+
importTheme(url.trim());
302296
setUrl("");
303297
onOpenChange(false);
304298
} catch (err) {

src/contexts/theme/storage.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ export function loadThemeFromStorage(): ThemeState {
2929
parsed &&
3030
typeof parsed === "object" &&
3131
parsed.currentMode &&
32-
parsed.cssVars &&
33-
parsed.cssVars.theme &&
34-
parsed.cssVars.light &&
35-
parsed.cssVars.dark
32+
parsed.cssVars?.theme &&
33+
parsed.cssVars?.light &&
34+
parsed.cssVars?.dark
3635
) {
3736
return parsed;
3837
}

src/contexts/theme/theme-script.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"use client";
22

3-
import { applyThemeToElement, getPreferredColorScheme } from "./apply-theme";
43
import { DEFAULT_THEME } from "./default-theme";
5-
import type { ThemeState } from "./types";
64

75
/**
86
* Inline script component that runs before React hydration to prevent theme flash.

src/contexts/theme/theme-utils.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ function normalizeThemeUrl(url: string): string {
4545
/**
4646
* Gets the theme name from the data or generates a fallback
4747
*/
48-
function getThemeName(themeData: any): string {
49-
return themeData.name
50-
? themeData.name
51-
.replace(/[-_]/g, " ")
52-
.replace(/\b\w/g, (l: string) => l.toUpperCase())
53-
: "Custom Theme";
48+
function getThemeName(themeData: Record<string, unknown>): string {
49+
if (typeof themeData.name === "string") {
50+
return themeData.name
51+
.replace(/[-_]/g, " ")
52+
.replace(/\b\w/g, (l: string) => l.toUpperCase());
53+
}
54+
return "Custom Theme";
5455
}
5556

5657
/**
@@ -65,16 +66,26 @@ export async function fetchThemeFromUrl(url: string): Promise<FetchedTheme> {
6566
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
6667
}
6768

68-
const themeData = await response.json();
69+
const themeData = (await response.json()) as Record<string, unknown>;
6970
const themeName = getThemeName(themeData);
7071
const isBuiltIn = THEME_URLS.includes(url);
7172

73+
// Type-safe access to cssVars
74+
const cssVarsRaw = themeData.cssVars as
75+
| Record<string, Record<string, string>>
76+
| undefined;
77+
const cssVars = {
78+
theme: cssVarsRaw?.theme ?? {},
79+
light: cssVarsRaw?.light ?? {},
80+
dark: cssVarsRaw?.dark ?? {},
81+
};
82+
7283
return {
7384
name: themeName,
7485
preset: {
7586
name: themeName,
7687
isBuiltIn,
77-
cssVars: themeData.cssVars || { theme: {}, light: {}, dark: {} },
88+
cssVars,
7889
},
7990
url,
8091
type: isBuiltIn ? "built-in" : "custom",

src/contexts/theme/use-theme-management.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import type { ThemePreset } from "./types";
1717
* Hook for managing themes including fetching, applying, and custom imports
1818
*/
1919
export function useThemeManagement() {
20-
const { themeState, setThemeState, toggleMode, applyTheme, resetToDefault } =
21-
useTheme();
20+
const { themeState, toggleMode, applyTheme, resetToDefault } = useTheme();
2221
const queryClient = useQueryClient();
2322
const [customThemeUrls, setCustomThemeUrls] = useState<string[]>([]);
2423

@@ -92,7 +91,7 @@ export function useThemeManagement() {
9291
}
9392
return { theme: fetchedTheme.preset, url, name: fetchedTheme.name };
9493
},
95-
onSuccess: ({ theme, url, name }) => {
94+
onSuccess: async ({ theme, url, name }) => {
9695
applyTheme(theme);
9796

9897
// Add to custom themes if not already there
@@ -101,7 +100,7 @@ export function useThemeManagement() {
101100
}
102101

103102
// Invalidate queries to refresh the lists
104-
queryClient.invalidateQueries({ queryKey: ["themes"] });
103+
await queryClient.invalidateQueries({ queryKey: ["themes"] });
105104

106105
toast.success(`Applied theme: ${name}`);
107106
},
@@ -132,9 +131,9 @@ export function useThemeManagement() {
132131
};
133132

134133
// Remove custom theme URL
135-
const removeCustomTheme = (url: string) => {
134+
const removeCustomTheme = async (url: string) => {
136135
setCustomThemeUrls((prev) => prev.filter((u) => u !== url));
137-
queryClient.invalidateQueries({ queryKey: ["themes", "custom"] });
136+
await queryClient.invalidateQueries({ queryKey: ["themes", "custom"] });
138137
toast.success("Removed custom theme");
139138
};
140139

@@ -170,6 +169,6 @@ export function useThemeManagement() {
170169
getThemePreview,
171170

172171
// Errors
173-
error: builtInError || customError,
172+
error: builtInError ?? customError,
174173
};
175174
}

0 commit comments

Comments
 (0)