Skip to content

Commit 4173a98

Browse files
committed
fix: rq
1 parent 2073625 commit 4173a98

4 files changed

Lines changed: 51 additions & 9 deletions

File tree

src/components/ColorPicker.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ export function ColorPicker({ username, onColorChange }: ColorPickerProps) {
2323
useEffect(() => {
2424
const loadUserColor = async () => {
2525
try {
26+
console.log(`Loading accent color for ${username}`);
2627
const userColor = await getUserAccentColor(username);
28+
console.log(`Loaded accent color: ${userColor}`);
2729
setAccentColor(userColor);
2830
setCustomColor(userColor);
2931
} catch (error) {
32+
console.error('Error loading user color:', error);
3033
// Keep default color on error
3134
} finally {
3235
setIsLoading(false);
@@ -35,19 +38,36 @@ export function ColorPicker({ username, onColorChange }: ColorPickerProps) {
3538
loadUserColor();
3639
}, [username, setAccentColor]);
3740

38-
// Keep customColor in sync with accentColor
41+
// Keep customColor in sync with accentColor but don't override if it was just changed
3942
useEffect(() => {
40-
setCustomColor(accentColor);
41-
}, [accentColor]);
43+
if (!isSaving) {
44+
setCustomColor(accentColor);
45+
}
46+
}, [accentColor, isSaving]);
4247

4348
const handleColorSelect = async (color: string) => {
49+
console.log(`Selected color: ${color}`);
4450
// Apply color immediately for instant feedback
4551
setAccentColor(color);
52+
setCustomColor(color);
4653
onColorChange?.(color);
4754

4855
setIsSaving(true);
4956
try {
5057
await updateUserAccentColor(username, color);
58+
console.log(`Successfully saved accent color: ${color}`);
59+
} catch (error) {
60+
safeLogError('Error saving accent color:', error);
61+
// Revert color back to previous if save failed
62+
const previousColor = await getUserAccentColor(username);
63+
setAccentColor(previousColor);
64+
setCustomColor(previousColor);
65+
onColorChange?.(previousColor);
66+
alert(t('colorSaveError'));
67+
} finally {
68+
setIsSaving(false);
69+
}
70+
};
5171
} catch (error) {
5272
safeLogError('Error saving accent color:', error);
5373
// Revert color back to previous if save failed
@@ -61,10 +81,12 @@ export function ColorPicker({ username, onColorChange }: ColorPickerProps) {
6181
};
6282

6383
const handleCustomColorChange = (color: string) => {
84+
console.log(`Custom color input changed to: ${color}`);
6485
setCustomColor(color);
6586
};
6687

6788
const handleCustomColorApply = () => {
89+
console.log(`Applying custom color: ${customColor}`);
6890
handleColorSelect(customColor);
6991
};
7092

src/lib/github.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,35 @@ async function createGitHubError(res: Response): Promise<Error> {
7777
}
7878

7979
export async function getFile(path: string) {
80-
const cached = fileCache.get(path);
81-
if (cached) {
82-
return { content: cached.content, sha: cached.sha };
80+
// Don't use cache for user settings files to ensure fresh data
81+
const isSetting = path.includes('users/') && path.endsWith('-settings.md');
82+
83+
if (!isSetting) {
84+
const cached = fileCache.get(path);
85+
if (cached) {
86+
return { content: cached.content, sha: cached.sha };
87+
}
8388
}
8489

8590
try {
8691
const res = await fetch(
8792
`${BASE}/repos/${owner}/${repo}/contents/${path}?ref=${branch}`,
8893
{ headers }
8994
);
90-
if (res.status === 404) return null;
95+
if (res.status === 404) {
96+
console.log(`File not found: ${path}`);
97+
return null;
98+
}
9199
if (!res.ok) {
92100
throw await createGitHubError(res);
93101
}
94102
const data = await res.json();
95103
if (data.content && !Array.isArray(data)) {
96104
const content = b64_to_utf8(data.content.replace(/\n/g, ''));
97105
const fileData = { content, sha: data.sha as string };
98-
fileCache.set(path, fileData);
106+
if (!isSetting) {
107+
fileCache.set(path, fileData);
108+
}
99109
return fileData;
100110
}
101111
return null;

src/lib/theme.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,30 @@ export function ThemeProvider({ children, username }: { children: React.ReactNod
2626
useEffect(() => {
2727
if (username) {
2828
setIsLoadingColor(true);
29+
console.log(`ThemeProvider: Loading accent color for ${username}`);
2930
getUserAccentColor(username)
3031
.then(color => {
32+
console.log(`ThemeProvider: Got accent color: ${color}`);
3133
setAccentColorState(color);
3234
applyAccentColor(color);
3335
})
34-
.catch(() => {
36+
.catch((err) => {
37+
console.error('ThemeProvider: Error loading accent color:', err);
3538
// Keep default color on error
3639
applyAccentColor(DEFAULT_ACCENT_COLOR);
3740
})
3841
.finally(() => {
3942
setIsLoadingColor(false);
4043
});
4144
} else {
45+
console.log('ThemeProvider: No username provided, using default color');
4246
setIsLoadingColor(false);
4347
applyAccentColor(DEFAULT_ACCENT_COLOR);
4448
}
4549
}, [username]);
4650

4751
const setAccentColor = (color: string) => {
52+
console.log(`ThemeProvider: Setting accent color to ${color}`);
4853
setAccentColorState(color);
4954
// Apply color immediately to CSS variables
5055
applyAccentColor(color);

src/lib/userSettings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ export async function loadUserSettings(username: string): Promise<UserSettings |
3131
const file = await getFile(path);
3232

3333
if (!file) {
34+
console.log(`User settings file not found for ${username}`);
3435
return null;
3536
}
3637

3738
const { data } = parseFrontmatter<UserSettings>(file.content);
39+
console.log(`Loaded user settings for ${username}:`, data);
3840
return data;
3941
} catch (error) {
4042
safeLogError('Error loading user settings:', error);
@@ -77,13 +79,16 @@ export async function getUserAccentColor(username: string): Promise<string> {
7779
// Update accent color for user
7880
export async function updateUserAccentColor(username: string, color: string): Promise<void> {
7981
try {
82+
console.log(`Updating accent color for ${username} to ${color}`);
8083
const existingSettings = await loadUserSettings(username);
8184
const settings: UserSettings = {
8285
accentColor: color,
8386
updatedAt: new Date().toISOString(),
8487
...existingSettings,
8588
};
89+
console.log(`Settings to save:`, settings);
8690
await saveUserSettings(username, settings);
91+
console.log(`Successfully updated accent color for ${username}`);
8792
} catch (error) {
8893
safeLogError('Error updating user accent color:', error);
8994
throw error;

0 commit comments

Comments
 (0)