add: themes for wishlists and dashboards
This commit is contained in:
@@ -17,6 +17,11 @@ export const load: PageServerLoad = async (event) => {
|
||||
};
|
||||
}
|
||||
|
||||
// Fetch user with theme
|
||||
const user = await db.query.users.findFirst({
|
||||
where: eq(users.id, session.user.id)
|
||||
});
|
||||
|
||||
const userWishlists = await db.query.wishlists.findMany({
|
||||
where: eq(wishlists.userId, session.user.id),
|
||||
with: {
|
||||
@@ -57,7 +62,7 @@ export const load: PageServerLoad = async (event) => {
|
||||
}));
|
||||
|
||||
return {
|
||||
user: session.user,
|
||||
user: user,
|
||||
wishlists: userWishlists,
|
||||
savedWishlists: savedWithAccess,
|
||||
isAuthenticated: true
|
||||
|
||||
@@ -11,6 +11,30 @@
|
||||
|
||||
let { data }: { data: PageData } = $props();
|
||||
|
||||
// For anonymous users, get theme from localStorage
|
||||
function getInitialTheme() {
|
||||
if (data.isAuthenticated) {
|
||||
return data.user?.dashboardTheme || 'none';
|
||||
} else {
|
||||
// Anonymous user - get from localStorage
|
||||
if (typeof window !== 'undefined') {
|
||||
return localStorage.getItem('dashboardTheme') || 'none';
|
||||
}
|
||||
return 'none';
|
||||
}
|
||||
}
|
||||
|
||||
let currentTheme = $state(getInitialTheme());
|
||||
|
||||
// Save to localStorage when theme changes for anonymous users
|
||||
function handleThemeUpdate(theme: string | null) {
|
||||
currentTheme = theme || 'none';
|
||||
|
||||
if (!data.isAuthenticated && typeof window !== 'undefined') {
|
||||
localStorage.setItem('dashboardTheme', currentTheme);
|
||||
}
|
||||
}
|
||||
|
||||
const t = $derived(languageStore.t);
|
||||
|
||||
// Only owned wishlists for "My Wishlists"
|
||||
@@ -34,11 +58,13 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<PageContainer theme={data.user?.dashboardTheme} themeColor="hsl(var(--primary))">
|
||||
<PageContainer theme={currentTheme} themeColor="#3b82f6">
|
||||
<DashboardHeader
|
||||
userName={data.user?.name}
|
||||
userEmail={data.user?.email}
|
||||
dashboardTheme={data.user?.dashboardTheme || 'none'}
|
||||
dashboardTheme={currentTheme}
|
||||
isAuthenticated={data.isAuthenticated}
|
||||
onThemeUpdate={handleThemeUpdate}
|
||||
/>
|
||||
|
||||
<!-- Local Wishlists Section (for anonymous and authenticated users) -->
|
||||
|
||||
Reference in New Issue
Block a user