feat(wishlist): per-user Wünsche + Header-Badge mit Gesamtzahl
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m16s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m16s
Schema-Änderung (Migration 005):
- Tabelle wishlist umgestellt auf PK (recipe_id, profile_id)
- wishlist_like-Tabelle zusammengelegt — Liken WAR schon "will ich auch",
also werden alle bestehenden Likes Memberships auf der neuen Tabelle.
- Alt-Einträge mit added_by_profile_id werden migriert, anonyme gehen
verloren (war inkonsistent, jetzt erzwingen wir profile_id NOT NULL).
Repository:
- listWishlist aggregiert pro Rezept: wanted_by_count, wanted_by_names
(kommagetrennt), on_my_wishlist für das aktive Profil
- listWishlistProfileIds(recipeId) für den Recipe-Page-Loader
- countWishlistRecipes für das Header-Badge (DISTINCT recipe_id)
- addToWishlist/removeFromWishlist/isOnMyWishlist alle mit profile_id
als Pflicht
API:
- POST /api/wishlist: profile_id jetzt Pflicht (nullable raus)
- DELETE /api/wishlist/[recipe_id]?profile_id=X (nur eigenes Entry)
- /api/wishlist/[recipe_id]/like komplett entfernt (Konzept obsolet)
- Neu: GET /api/wishlist/count → { count: <distinct recipes> }
UI:
- Header-Heart bekommt rotes Badge mit Zahl der Wunschliste-Rezepte.
wishlistStore in $lib/client/wishlist.svelte.ts hält den Count reaktiv;
Refresh auf Mount, nach Add/Remove, beim Öffnen der Wunschliste.
- Recipe-Detail: Loader liefert wishlist_profile_ids; onMyWishlist ist
ein $derived. Toggle fragt aktives Profil (alertAction sonst), mutiert
die lokale Liste + ruft wishlistStore.refresh.
- Wunschliste-Seite: Heart toggelt eigenen Wunsch, Count zeigt Gesamt-
wünsche, kommagetrennte Namen zeigen "wer will". Trash-Button
entfernt — Heart-off reicht jetzt.
Tests (99 → 99, 8 neu geschrieben):
- Per-User-Add/Remove, aggregierte Counts, on_my_wishlist, Cascades bei
Recipe/Profile-Delete, countWishlistRecipes = DISTINCT.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
import { goto, afterNavigate } from '$app/navigation';
|
||||
import { Heart, Settings, CookingPot, Globe, Utensils } from 'lucide-svelte';
|
||||
import { profileStore } from '$lib/client/profile.svelte';
|
||||
import { wishlistStore } from '$lib/client/wishlist.svelte';
|
||||
import ProfileSwitcher from '$lib/components/ProfileSwitcher.svelte';
|
||||
import ConfirmDialog from '$lib/components/ConfirmDialog.svelte';
|
||||
import SearchLoader from '$lib/components/SearchLoader.svelte';
|
||||
@@ -105,6 +106,7 @@
|
||||
|
||||
onMount(() => {
|
||||
profileStore.load();
|
||||
void wishlistStore.refresh();
|
||||
document.addEventListener('click', handleClickOutside);
|
||||
document.addEventListener('keydown', handleKey);
|
||||
return () => {
|
||||
@@ -211,8 +213,17 @@
|
||||
</div>
|
||||
{/if}
|
||||
<div class="bar-right">
|
||||
<a href="/wishlist" class="nav-link" aria-label="Wunschliste">
|
||||
<a
|
||||
href="/wishlist"
|
||||
class="nav-link wishlist-link"
|
||||
aria-label={wishlistStore.count > 0
|
||||
? `Wunschliste (${wishlistStore.count})`
|
||||
: 'Wunschliste'}
|
||||
>
|
||||
<Heart size={20} strokeWidth={2} />
|
||||
{#if wishlistStore.count > 0}
|
||||
<span class="badge">{wishlistStore.count}</span>
|
||||
{/if}
|
||||
</a>
|
||||
<a href="/admin" class="nav-link" aria-label="Einstellungen">
|
||||
<Settings size={20} strokeWidth={2} />
|
||||
@@ -399,10 +410,28 @@
|
||||
border-radius: 999px;
|
||||
text-decoration: none;
|
||||
font-size: 1.15rem;
|
||||
position: relative;
|
||||
}
|
||||
.nav-link:hover {
|
||||
background: #f4f8f5;
|
||||
}
|
||||
.badge {
|
||||
position: absolute;
|
||||
top: -2px;
|
||||
right: -2px;
|
||||
min-width: 18px;
|
||||
height: 18px;
|
||||
padding: 0 5px;
|
||||
border-radius: 999px;
|
||||
background: #c53030;
|
||||
color: white;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 700;
|
||||
line-height: 18px;
|
||||
text-align: center;
|
||||
box-shadow: 0 0 0 2px white;
|
||||
pointer-events: none;
|
||||
}
|
||||
main {
|
||||
padding: 0 1rem 4rem;
|
||||
max-width: 760px;
|
||||
|
||||
Reference in New Issue
Block a user