update: hide empty claimed wishlists, move local wishlists, cleanup comments
This commit is contained in:
@@ -21,11 +21,9 @@
|
|||||||
let localWishlists = $state<LocalWishlist[]>([]);
|
let localWishlists = $state<LocalWishlist[]>([]);
|
||||||
let enrichedWishlists = $state<any[]>([]);
|
let enrichedWishlists = $state<any[]>([]);
|
||||||
|
|
||||||
// Load local wishlists on mount and fetch their data from server
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
localWishlists = getLocalWishlists();
|
localWishlists = getLocalWishlists();
|
||||||
|
|
||||||
// Fetch full wishlist data for each local wishlist
|
|
||||||
const promises = localWishlists.map(async (local) => {
|
const promises = localWishlists.map(async (local) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/wishlist/${local.ownerToken}`);
|
const response = await fetch(`/api/wishlist/${local.ownerToken}`);
|
||||||
@@ -39,7 +37,6 @@
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch wishlist data:', error);
|
console.error('Failed to fetch wishlist data:', error);
|
||||||
}
|
}
|
||||||
// Fallback to local data if fetch fails
|
|
||||||
return {
|
return {
|
||||||
id: local.ownerToken,
|
id: local.ownerToken,
|
||||||
title: local.title,
|
title: local.title,
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ export function addLocalWishlist(wishlist: LocalWishlist): void {
|
|||||||
try {
|
try {
|
||||||
const wishlists = getLocalWishlists();
|
const wishlists = getLocalWishlists();
|
||||||
|
|
||||||
// Check if already exists
|
|
||||||
const exists = wishlists.some(w => w.ownerToken === wishlist.ownerToken);
|
const exists = wishlists.some(w => w.ownerToken === wishlist.ownerToken);
|
||||||
if (exists) return;
|
if (exists) return;
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,6 @@ export const actions: Actions = {
|
|||||||
return { success: false, error: 'Wishlist ID is required' };
|
return { success: false, error: 'Wishlist ID is required' };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the user owns this wishlist
|
|
||||||
await db.delete(wishlists)
|
await db.delete(wishlists)
|
||||||
.where(and(
|
.where(and(
|
||||||
eq(wishlists.id, wishlistId),
|
eq(wishlists.id, wishlistId),
|
||||||
|
|||||||
@@ -11,12 +11,10 @@
|
|||||||
|
|
||||||
let { data }: { data: PageData } = $props();
|
let { data }: { data: PageData } = $props();
|
||||||
|
|
||||||
// For anonymous users, get theme from localStorage
|
|
||||||
function getInitialTheme() {
|
function getInitialTheme() {
|
||||||
if (data.isAuthenticated) {
|
if (data.isAuthenticated) {
|
||||||
return data.user?.dashboardTheme || 'none';
|
return data.user?.dashboardTheme || 'none';
|
||||||
} else {
|
} else {
|
||||||
// Anonymous user - get from localStorage
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
return localStorage.getItem('dashboardTheme') || 'none';
|
return localStorage.getItem('dashboardTheme') || 'none';
|
||||||
}
|
}
|
||||||
@@ -24,12 +22,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For anonymous users, get color from localStorage
|
|
||||||
function getInitialColor() {
|
function getInitialColor() {
|
||||||
if (data.isAuthenticated) {
|
if (data.isAuthenticated) {
|
||||||
return data.user?.dashboardColor || null;
|
return data.user?.dashboardColor || null;
|
||||||
} else {
|
} else {
|
||||||
// Anonymous user - get from localStorage
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
return localStorage.getItem('dashboardColor') || null;
|
return localStorage.getItem('dashboardColor') || null;
|
||||||
}
|
}
|
||||||
@@ -40,7 +36,6 @@
|
|||||||
let currentTheme = $state(getInitialTheme());
|
let currentTheme = $state(getInitialTheme());
|
||||||
let currentColor = $state(getInitialColor());
|
let currentColor = $state(getInitialColor());
|
||||||
|
|
||||||
// Save to localStorage when theme changes for anonymous users
|
|
||||||
function handleThemeUpdate(theme: string | null) {
|
function handleThemeUpdate(theme: string | null) {
|
||||||
currentTheme = theme || 'none';
|
currentTheme = theme || 'none';
|
||||||
|
|
||||||
@@ -49,7 +44,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save to localStorage when color changes for anonymous users
|
|
||||||
function handleColorUpdate(color: string | null) {
|
function handleColorUpdate(color: string | null) {
|
||||||
currentColor = color;
|
currentColor = color;
|
||||||
|
|
||||||
@@ -64,10 +58,8 @@
|
|||||||
|
|
||||||
const t = $derived(languageStore.t);
|
const t = $derived(languageStore.t);
|
||||||
|
|
||||||
// Only owned wishlists for "My Wishlists"
|
|
||||||
const myWishlists = $derived(() => data.wishlists || []);
|
const myWishlists = $derived(() => data.wishlists || []);
|
||||||
|
|
||||||
// Claimed wishlists (those with ownerToken, meaning they were claimed via edit link)
|
|
||||||
const claimedWishlists = $derived(() => {
|
const claimedWishlists = $derived(() => {
|
||||||
return (data.savedWishlists || [])
|
return (data.savedWishlists || [])
|
||||||
.filter(saved => saved.wishlist?.ownerToken)
|
.filter(saved => saved.wishlist?.ownerToken)
|
||||||
@@ -79,7 +71,6 @@
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Saved wishlists are those WITHOUT ownerToken (saved from public view only)
|
|
||||||
const savedWishlists = $derived(() => {
|
const savedWishlists = $derived(() => {
|
||||||
return (data.savedWishlists || []).filter(saved => !saved.wishlist?.ownerToken);
|
return (data.savedWishlists || []).filter(saved => !saved.wishlist?.ownerToken);
|
||||||
});
|
});
|
||||||
@@ -96,15 +87,7 @@
|
|||||||
onColorUpdate={handleColorUpdate}
|
onColorUpdate={handleColorUpdate}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Local Wishlists Section (for anonymous and authenticated users) -->
|
|
||||||
<LocalWishlistsSection
|
|
||||||
isAuthenticated={data.isAuthenticated}
|
|
||||||
fallbackColor={currentColor}
|
|
||||||
fallbackTheme={currentTheme}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{#if data.isAuthenticated}
|
{#if data.isAuthenticated}
|
||||||
<!-- My Wishlists Section -->
|
|
||||||
<WishlistSection
|
<WishlistSection
|
||||||
title={t.dashboard.myWishlists}
|
title={t.dashboard.myWishlists}
|
||||||
description={t.dashboard.myWishlistsDescription}
|
description={t.dashboard.myWishlistsDescription}
|
||||||
@@ -162,7 +145,12 @@
|
|||||||
{/snippet}
|
{/snippet}
|
||||||
</WishlistSection>
|
</WishlistSection>
|
||||||
|
|
||||||
<!-- Claimed Wishlists Section -->
|
<LocalWishlistsSection
|
||||||
|
isAuthenticated={data.isAuthenticated}
|
||||||
|
fallbackColor={currentColor}
|
||||||
|
fallbackTheme={currentTheme}
|
||||||
|
/>
|
||||||
|
|
||||||
<WishlistSection
|
<WishlistSection
|
||||||
title={t.dashboard.claimedWishlists}
|
title={t.dashboard.claimedWishlists}
|
||||||
description={t.dashboard.claimedWishlistsDescription}
|
description={t.dashboard.claimedWishlistsDescription}
|
||||||
@@ -219,7 +207,6 @@
|
|||||||
{/snippet}
|
{/snippet}
|
||||||
</WishlistSection>
|
</WishlistSection>
|
||||||
|
|
||||||
<!-- Saved Wishlists Section -->
|
|
||||||
<WishlistSection
|
<WishlistSection
|
||||||
title={t.dashboard.savedWishlists}
|
title={t.dashboard.savedWishlists}
|
||||||
description={t.dashboard.savedWishlistsDescription}
|
description={t.dashboard.savedWishlistsDescription}
|
||||||
@@ -228,6 +215,7 @@
|
|||||||
emptyDescription={t.dashboard.emptySavedWishlistsDescription}
|
emptyDescription={t.dashboard.emptySavedWishlistsDescription}
|
||||||
fallbackColor={currentColor}
|
fallbackColor={currentColor}
|
||||||
fallbackTheme={currentTheme}
|
fallbackTheme={currentTheme}
|
||||||
|
hideIfEmpty={true}
|
||||||
>
|
>
|
||||||
{#snippet actions(saved, unlocked)}
|
{#snippet actions(saved, unlocked)}
|
||||||
<div class="flex gap-2 flex-wrap">
|
<div class="flex gap-2 flex-wrap">
|
||||||
|
|||||||
Reference in New Issue
Block a user