Skip to content

Commit 985beb2

Browse files
committed
feat(preferences): implement persistent font size control with database storage
- Add font size preference persistence to user profiles - Connect FontSizeControl component to appState and database - Update setTestUser to load full profile data including preferences - Regenerate database types to include new preferences column - Add async profile loading with proper type casting
1 parent 5f3af45 commit 985beb2

File tree

5 files changed

+1069
-460
lines changed

5 files changed

+1069
-460
lines changed

src/lib/components/layouts/Footer.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
// ========== TESTING ONLY - REMOVE WHEN DONE ==========
2020
const getTestUsers = getContext<() => Profile[]>('getTestUsers');
21-
const setTestUser = getContext<(userId: string, userName: string) => void>('setTestUser');
21+
const setTestUser = getContext<(userId: string, userName: string) => Promise<void>>('setTestUser');
2222
2323
const sortedTestUsers = $derived(
2424
[...(getTestUsers() || [])]
@@ -32,8 +32,8 @@
3232
let dropdownExpanded = $state(false);
3333
let selectedUserId = $state<string | null>(null);
3434
35-
function handleUserSelect(userId: string, userName: string) {
36-
setTestUser(userId, userName);
35+
async function handleUserSelect(userId: string, userName: string) {
36+
await setTestUser(userId, userName);
3737
selectedUserId = userId;
3838
console.log('Test user selected:', userName, userId);
3939

src/lib/components/ui/FontSizeControl.svelte

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
<script lang="ts">
2+
import { getContext } from 'svelte';
3+
import type { AppState, Profile } from '$lib/types/appState';
4+
import { updateProfile } from '$lib/services/database/profiles';
25
import Tooltip from './Tooltip.svelte';
36
4-
// Font size state
7+
// Get app state from context
8+
const getApp = getContext<() => AppState>('getApp');
9+
const setProfile = getContext<(newProfile: Profile) => void>('setProfile');
10+
const app = $derived(getApp());
11+
12+
// Font size state - read from appState preferences or default to medium
513
let fontSize = $state<'extra-small' | 'small' | 'medium' | 'large' | 'extra-large'>('medium');
14+
15+
// Keep fontSize in sync with appState preferences
16+
$effect(() => {
17+
fontSize = app.profile.preferences?.fontSize || 'medium';
18+
});
619
let showModal = $state(false);
720
821
const fontSizeLabels = {
@@ -13,18 +26,47 @@
1326
'extra-large': 'Extra Large'
1427
};
1528
29+
// Helper function to update both local state and appState preferences
30+
const updateFontSize = async (newSize: typeof fontSize) => {
31+
fontSize = newSize;
32+
33+
// Update appState preferences immediately for UI responsiveness
34+
const updatedProfile = {
35+
...app.profile,
36+
preferences: {
37+
...app.profile.preferences,
38+
fontSize: newSize
39+
}
40+
};
41+
setProfile(updatedProfile);
42+
43+
// Save to database if user is logged in
44+
if (app.profile.id) {
45+
try {
46+
const result = await updateProfile(app.profile.id, {
47+
preferences: updatedProfile.preferences
48+
});
49+
if (result.error) {
50+
console.error('Database error saving font size preference:', result.error);
51+
}
52+
} catch (error) {
53+
console.error('Failed to save font size preference:', error);
54+
}
55+
}
56+
};
57+
1658
const increaseFontSize = () => {
17-
if (fontSize === 'extra-small') fontSize = 'small';
18-
else if (fontSize === 'small') fontSize = 'medium';
19-
else if (fontSize === 'medium') fontSize = 'large';
20-
else if (fontSize === 'large') fontSize = 'extra-large';
59+
if (fontSize === 'extra-small') updateFontSize('small');
60+
else if (fontSize === 'small') updateFontSize('medium');
61+
else if (fontSize === 'medium') updateFontSize('large');
62+
else if (fontSize === 'large') updateFontSize('extra-large');
2163
};
2264
2365
const decreaseFontSize = () => {
24-
if (fontSize === 'extra-large') fontSize = 'large';
25-
else if (fontSize === 'large') fontSize = 'medium';
26-
else if (fontSize === 'medium') fontSize = 'small';
27-
else if (fontSize === 'small') fontSize = 'extra-small';
66+
if (fontSize === 'extra-large') updateFontSize('large');
67+
else if (fontSize === 'large') updateFontSize('medium');
68+
else if (fontSize === 'medium') updateFontSize('small');
69+
else if (fontSize === 'small') updateFontSize('extra-small');
2870
};
2971
3072
const toggleModal = () => {

0 commit comments

Comments
 (0)