diff --git a/src/lib/i18n/translations/da.ts b/src/lib/i18n/translations/da.ts index d933d67..ac93420 100644 --- a/src/lib/i18n/translations/da.ts +++ b/src/lib/i18n/translations/da.ts @@ -11,6 +11,8 @@ export const da: Translation = { dashboard: { myWishlists: 'Mine Ønskelister', myWishlistsDescription: 'Ønskelister du ejer og administrerer', + claimedWishlists: 'Ejede Ønskelister', + claimedWishlistsDescription: 'Ønskelister du har taget ejerskab af og kan redigere', savedWishlists: 'Gemte Ønskelister', savedWishlistsDescription: 'Ønskelister du følger', createNew: '+ Opret Ny', @@ -20,6 +22,8 @@ export const da: Translation = { unsave: 'Fjern', emptyWishlists: 'Du har ikke oprettet nogen ønskelister endnu.', emptyWishlistsAction: 'Opret Din Første Ønskeliste', + emptyClaimedWishlists: 'Du har ikke taget ejerskab af nogen ønskelister endnu.', + emptyClaimedWishlistsDescription: 'Når nogen deler et redigeringslink med dig, kan du tage ejerskab af det for at administrere det fra dit dashboard.', emptySavedWishlists: 'Du har ikke gemt nogen ønskelister endnu.', emptySavedWishlistsDescription: 'Når du ser en andens ønskeliste, kan du gemme den for nemt at finde den senere.', by: 'af', @@ -53,7 +57,9 @@ export const da: Translation = { claimWishlist: 'Tag Ejerskab Af Ønskeliste', unclaimWishlist: 'Fjern Ejerskab Af Ønskeliste', youOwnThis: 'Du Ejer Denne Ønskeliste', - alreadyInDashboard: 'Denne ønskeliste er allerede it dit dashboard.', + youClaimedThis: 'Du Har Taget Ejerskab Af Denne Ønskeliste', + alreadyInDashboard: 'Denne ønskeliste er allerede it dit dashboard.', + alreadyClaimed: 'Denne ønskeliste er allerede i dit dashboard som en ejet ønskeliste.', claimDescription: 'Tag ejerskab af denne ønskeliste for at tilføje den til dit dashboard', claimedDescription: 'Du har taget ejerskab af denne ønskeliste og kan tilgå den fra dit dashboard', deleteWishlist: 'Slet Ønskeliste', diff --git a/src/lib/i18n/translations/en.ts b/src/lib/i18n/translations/en.ts index 48ba06d..6a6c9a7 100644 --- a/src/lib/i18n/translations/en.ts +++ b/src/lib/i18n/translations/en.ts @@ -8,6 +8,8 @@ export const en = { dashboard: { myWishlists: 'My Wishlists', myWishlistsDescription: 'Wishlists you own and manage', + claimedWishlists: 'Claimed Wishlists', + claimedWishlistsDescription: 'Wishlists you have claimed and can edit', savedWishlists: 'Saved Wishlists', savedWishlistsDescription: "Wishlists you're following", createNew: '+ Create New', @@ -17,6 +19,8 @@ export const en = { unsave: 'Unsave', emptyWishlists: "You haven't created any wishlists yet.", emptyWishlistsAction: 'Create Your First Wishlist', + emptyClaimedWishlists: "You haven't claimed any wishlists yet.", + emptyClaimedWishlistsDescription: "When someone shares an edit link with you, you can claim it to manage it from your dashboard.", emptySavedWishlists: "You haven't saved any wishlists yet.", emptySavedWishlistsDescription: "When viewing someone's wishlist, you can save it to easily find it later.", by: 'by', @@ -50,7 +54,9 @@ export const en = { claimWishlist: 'Claim Wishlist', unclaimWishlist: 'Unclaim Wishlist', youOwnThis: 'You Own This Wishlist', - alreadyInDashboard: 'This wishlist is already in your dashboard as the owner.', + youClaimedThis: 'You Have Claimed This Wishlist', + alreadyInDashboard: 'This wishlist is already in your dashboard as the owner.', + alreadyClaimed: 'This wishlist is already in your dashboard as a claimed wishlist.', claimDescription: 'Claim this wishlist to add it to your dashboard', claimedDescription: 'You have claimed this wishlist and can access it from your dashboard', deleteWishlist: 'Delete Wishlist', diff --git a/src/routes/dashboard/+page.svelte b/src/routes/dashboard/+page.svelte index a5e379f..3e58f62 100644 --- a/src/routes/dashboard/+page.svelte +++ b/src/routes/dashboard/+page.svelte @@ -16,14 +16,20 @@ const t = $derived(languageStore.t); let myWishlistsUnlocked = $state(false); + let claimedWishlistsUnlocked = $state(false); let savedWishlistsUnlocked = $state(false); let myWishlistsSearch = $state(''); + let claimedWishlistsSearch = $state(''); let savedWishlistsSearch = $state(''); - // Combine owned and claimed wishlists for "My Wishlists" + // Only owned wishlists for "My Wishlists" (exclude claimed) const allMyWishlists = $derived(() => { const owned = data.wishlists || []; - // Only include claimed wishlists (those with ownerToken, meaning they were claimed via edit link) + return owned; + }); + + // Claimed wishlists (those with ownerToken, meaning they were claimed via edit link) + const allClaimedWishlists = $derived(() => { const claimed = (data.savedWishlists || []) .filter(saved => saved.wishlist?.ownerToken) // Has edit access .map(saved => ({ @@ -32,7 +38,7 @@ isClaimed: true, savedId: saved.id })); - return [...owned, ...claimed]; + return claimed; }); const sortedWishlists = $derived(() => { @@ -61,6 +67,32 @@ }); }); + const sortedClaimedWishlists = $derived(() => { + const filtered = claimedWishlistsSearch.trim() + ? allClaimedWishlists().filter(w => + w.title.toLowerCase().includes(claimedWishlistsSearch.toLowerCase()) || + w.description?.toLowerCase().includes(claimedWishlistsSearch.toLowerCase()) + ) + : allClaimedWishlists(); + + return [...filtered].sort((a, b) => { + if (a.isFavorite && !b.isFavorite) return -1; + if (!a.isFavorite && b.isFavorite) return 1; + + const aHasEndDate = !!a.endDate; + const bHasEndDate = !!b.endDate; + + if (aHasEndDate && !bHasEndDate) return -1; + if (!aHasEndDate && bHasEndDate) return 1; + + if (aHasEndDate && bHasEndDate) { + return new Date(a.endDate!).getTime() - new Date(b.endDate!).getTime(); + } + + return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(); + }); + }); + // Saved wishlists are those WITHOUT ownerToken (saved from public view only) const sortedSavedWishlists = $derived(() => { const filtered = savedWishlistsSearch.trim() @@ -155,33 +187,18 @@ color={wishlist.color} >
- {#if wishlist.isClaimed} - -
{ - return async ({ update }) => { - await update({ reset: false }); - }; - }}> - - - -
- {:else} - -
{ - return async ({ update }) => { - await update({ reset: false }); - }; - }}> - - - -
- {/if} + +
{ + return async ({ update }) => { + await update({ reset: false }); + }; + }}> + + + +
- {#if wishlist.isClaimed && myWishlistsUnlocked} - -
{ +
+ + {/snippet} + + + {#if allClaimedWishlists().length > 0} + + {#snippet headerAction()} +
+ +
+ {/snippet} + + {#snippet searchBar()} + {#if allClaimedWishlists().length > 0} + + {/if} + {/snippet} + + {#snippet children(wishlist)} + +
+ + { return async ({ update }) => { await update({ reset: false }); }; }}> - - {/if} -
-
- {/snippet} -
+ + + {#if claimedWishlistsUnlocked} + +
{ + return async ({ update }) => { + await update({ reset: false }); + }; + }}> + + +
+ {/if} + + + {/snippet} + + {/if} { const session = await locals.auth(); let isSaved = false; + let isClaimed = false; let savedWishlistId: string | null = null; if (session?.user?.id) { @@ -33,12 +34,14 @@ export const load: PageServerLoad = async ({ params, locals }) => { ) }); isSaved = !!saved; + isClaimed = !!saved?.ownerToken; // User has claimed if ownerToken exists in savedWishlists savedWishlistId = saved?.id || null; } return { wishlist, isSaved, + isClaimed, savedWishlistId, isAuthenticated: !!session?.user }; diff --git a/src/routes/wishlist/[token]/+page.svelte b/src/routes/wishlist/[token]/+page.svelte index 6a9aec8..d001072 100644 --- a/src/routes/wishlist/[token]/+page.svelte +++ b/src/routes/wishlist/[token]/+page.svelte @@ -22,7 +22,6 @@ let { data }: { data: PageData } = $props(); - let showSaveForm = $state(false); let searchQuery = $state(''); const t = $derived(languageStore.t); @@ -55,7 +54,17 @@ {/if} {#if data.isAuthenticated} - {#if data.isSaved} + {#if data.isClaimed} + + + {:else if data.isSaved} +
{:else} - + +
{ + return async ({ update }) => { + await update({ reset: false }); + }; + }}> + + +
{/if} {:else} {/if} - - {#if showSaveForm && !data.isSaved} - - - Save This Wishlist - Save this wishlist to easily find it later in your dashboard - - -
{ - return async ({ update }) => { - await update(); - showSaveForm = false; - }; - }} - class="space-y-4" - > - -
- - -
-
-
-
- {/if} - {#if data.wishlist.items && data.wishlist.items.length > 0}