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:
16
src/lib/client/wishlist.svelte.ts
Normal file
16
src/lib/client/wishlist.svelte.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
class WishlistStore {
|
||||||
|
count = $state(0);
|
||||||
|
|
||||||
|
async refresh(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/wishlist/count');
|
||||||
|
if (!res.ok) return;
|
||||||
|
const body = await res.json();
|
||||||
|
this.count = typeof body.count === 'number' ? body.count : 0;
|
||||||
|
} catch {
|
||||||
|
// keep last known count on network error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const wishlistStore = new WishlistStore();
|
||||||
29
src/lib/server/db/migrations/005_wishlist_per_user.sql
Normal file
29
src/lib/server/db/migrations/005_wishlist_per_user.sql
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
-- Wishlist: from "one entry per recipe" to "per-user membership".
|
||||||
|
-- Multiple profiles can now wish for the same recipe. The old wishlist_like
|
||||||
|
-- table merges into this — liking WAS already "me too", so existing likes
|
||||||
|
-- become wishlist memberships.
|
||||||
|
|
||||||
|
CREATE TABLE wishlist_new (
|
||||||
|
recipe_id INTEGER NOT NULL REFERENCES recipe(id) ON DELETE CASCADE,
|
||||||
|
profile_id INTEGER NOT NULL REFERENCES profile(id) ON DELETE CASCADE,
|
||||||
|
added_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (recipe_id, profile_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Preserve existing explicit additions (only if a profile was attached)
|
||||||
|
INSERT OR IGNORE INTO wishlist_new (recipe_id, profile_id, added_at)
|
||||||
|
SELECT recipe_id, added_by_profile_id, added_at
|
||||||
|
FROM wishlist
|
||||||
|
WHERE added_by_profile_id IS NOT NULL;
|
||||||
|
|
||||||
|
-- Likes become memberships
|
||||||
|
INSERT OR IGNORE INTO wishlist_new (recipe_id, profile_id, added_at)
|
||||||
|
SELECT recipe_id, profile_id, created_at
|
||||||
|
FROM wishlist_like;
|
||||||
|
|
||||||
|
DROP TABLE wishlist_like;
|
||||||
|
DROP TABLE wishlist;
|
||||||
|
ALTER TABLE wishlist_new RENAME TO wishlist;
|
||||||
|
|
||||||
|
CREATE INDEX idx_wishlist_profile ON wishlist(profile_id);
|
||||||
|
CREATE INDEX idx_wishlist_recipe ON wishlist(recipe_id);
|
||||||
@@ -5,11 +5,10 @@ export type WishlistEntry = {
|
|||||||
title: string;
|
title: string;
|
||||||
image_path: string | null;
|
image_path: string | null;
|
||||||
source_domain: string | null;
|
source_domain: string | null;
|
||||||
added_by_profile_id: number | null;
|
added_at: string; // earliest per recipe
|
||||||
added_by_name: string | null;
|
wanted_by_count: number;
|
||||||
added_at: string;
|
wanted_by_names: string; // comma-joined profile names
|
||||||
like_count: number;
|
on_my_wishlist: 0 | 1;
|
||||||
liked_by_me: 0 | 1;
|
|
||||||
avg_stars: number | null;
|
avg_stars: number | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -21,9 +20,9 @@ export function listWishlist(
|
|||||||
sort: SortKey = 'popular'
|
sort: SortKey = 'popular'
|
||||||
): WishlistEntry[] {
|
): WishlistEntry[] {
|
||||||
const orderBy = {
|
const orderBy = {
|
||||||
popular: 'like_count DESC, w.added_at DESC',
|
popular: 'wanted_by_count DESC, first_added DESC',
|
||||||
newest: 'w.added_at DESC',
|
newest: 'first_added DESC',
|
||||||
oldest: 'w.added_at ASC'
|
oldest: 'first_added ASC'
|
||||||
}[sort];
|
}[sort];
|
||||||
|
|
||||||
return db
|
return db
|
||||||
@@ -33,66 +32,76 @@ export function listWishlist(
|
|||||||
r.title,
|
r.title,
|
||||||
r.image_path,
|
r.image_path,
|
||||||
r.source_domain,
|
r.source_domain,
|
||||||
w.added_by_profile_id,
|
MIN(w.added_at) AS first_added,
|
||||||
p.name AS added_by_name,
|
MIN(w.added_at) AS added_at,
|
||||||
w.added_at,
|
COUNT(w.profile_id) AS wanted_by_count,
|
||||||
(SELECT COUNT(*) FROM wishlist_like wl WHERE wl.recipe_id = w.recipe_id) AS like_count,
|
COALESCE(GROUP_CONCAT(p.name, ', '), '') AS wanted_by_names,
|
||||||
CASE
|
CASE
|
||||||
WHEN ? IS NULL THEN 0
|
WHEN ? IS NULL THEN 0
|
||||||
WHEN EXISTS (SELECT 1 FROM wishlist_like wl
|
WHEN EXISTS (SELECT 1 FROM wishlist w2
|
||||||
WHERE wl.recipe_id = w.recipe_id AND wl.profile_id = ?)
|
WHERE w2.recipe_id = w.recipe_id AND w2.profile_id = ?)
|
||||||
THEN 1
|
THEN 1
|
||||||
ELSE 0
|
ELSE 0
|
||||||
END AS liked_by_me,
|
END AS on_my_wishlist,
|
||||||
(SELECT AVG(stars) FROM rating WHERE recipe_id = w.recipe_id) AS avg_stars
|
(SELECT AVG(stars) FROM rating WHERE recipe_id = w.recipe_id) AS avg_stars
|
||||||
FROM wishlist w
|
FROM wishlist w
|
||||||
JOIN recipe r ON r.id = w.recipe_id
|
JOIN recipe r ON r.id = w.recipe_id
|
||||||
LEFT JOIN profile p ON p.id = w.added_by_profile_id
|
LEFT JOIN profile p ON p.id = w.profile_id
|
||||||
|
GROUP BY w.recipe_id
|
||||||
ORDER BY ${orderBy}`
|
ORDER BY ${orderBy}`
|
||||||
)
|
)
|
||||||
.all(activeProfileId, activeProfileId) as WishlistEntry[];
|
.all(activeProfileId, activeProfileId) as WishlistEntry[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isOnWishlist(db: Database.Database, recipeId: number): boolean {
|
export function listWishlistProfileIds(
|
||||||
|
db: Database.Database,
|
||||||
|
recipeId: number
|
||||||
|
): number[] {
|
||||||
return (
|
return (
|
||||||
db
|
db
|
||||||
.prepare('SELECT 1 AS ok FROM wishlist WHERE recipe_id = ?')
|
.prepare('SELECT profile_id FROM wishlist WHERE recipe_id = ?')
|
||||||
.get(recipeId) !== undefined
|
.all(recipeId) as { profile_id: number }[]
|
||||||
);
|
).map((r) => r.profile_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function countWishlistRecipes(db: Database.Database): number {
|
||||||
|
const row = db
|
||||||
|
.prepare('SELECT COUNT(DISTINCT recipe_id) AS n FROM wishlist')
|
||||||
|
.get() as { n: number };
|
||||||
|
return row.n;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addToWishlist(
|
export function addToWishlist(
|
||||||
db: Database.Database,
|
db: Database.Database,
|
||||||
recipeId: number,
|
recipeId: number,
|
||||||
profileId: number | null
|
profileId: number
|
||||||
): void {
|
): void {
|
||||||
db.prepare(
|
db.prepare(
|
||||||
`INSERT INTO wishlist(recipe_id, added_by_profile_id)
|
`INSERT INTO wishlist(recipe_id, profile_id)
|
||||||
VALUES (?, ?)
|
VALUES (?, ?)
|
||||||
ON CONFLICT(recipe_id) DO NOTHING`
|
ON CONFLICT(recipe_id, profile_id) DO NOTHING`
|
||||||
).run(recipeId, profileId);
|
).run(recipeId, profileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeFromWishlist(db: Database.Database, recipeId: number): void {
|
export function removeFromWishlist(
|
||||||
db.prepare('DELETE FROM wishlist WHERE recipe_id = ?').run(recipeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function likeWish(
|
|
||||||
db: Database.Database,
|
db: Database.Database,
|
||||||
recipeId: number,
|
recipeId: number,
|
||||||
profileId: number
|
profileId: number
|
||||||
): void {
|
): void {
|
||||||
db.prepare(
|
db.prepare('DELETE FROM wishlist WHERE recipe_id = ? AND profile_id = ?').run(
|
||||||
'INSERT OR IGNORE INTO wishlist_like(recipe_id, profile_id) VALUES (?, ?)'
|
recipeId,
|
||||||
).run(recipeId, profileId);
|
profileId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unlikeWish(
|
export function isOnMyWishlist(
|
||||||
db: Database.Database,
|
db: Database.Database,
|
||||||
recipeId: number,
|
recipeId: number,
|
||||||
profileId: number
|
profileId: number
|
||||||
): void {
|
): boolean {
|
||||||
db.prepare(
|
return (
|
||||||
'DELETE FROM wishlist_like WHERE recipe_id = ? AND profile_id = ?'
|
db
|
||||||
).run(recipeId, profileId);
|
.prepare('SELECT 1 AS ok FROM wishlist WHERE recipe_id = ? AND profile_id = ?')
|
||||||
|
.get(recipeId, profileId) !== undefined
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
import { goto, afterNavigate } from '$app/navigation';
|
import { goto, afterNavigate } from '$app/navigation';
|
||||||
import { Heart, Settings, CookingPot, Globe, Utensils } from 'lucide-svelte';
|
import { Heart, Settings, CookingPot, Globe, Utensils } from 'lucide-svelte';
|
||||||
import { profileStore } from '$lib/client/profile.svelte';
|
import { profileStore } from '$lib/client/profile.svelte';
|
||||||
|
import { wishlistStore } from '$lib/client/wishlist.svelte';
|
||||||
import ProfileSwitcher from '$lib/components/ProfileSwitcher.svelte';
|
import ProfileSwitcher from '$lib/components/ProfileSwitcher.svelte';
|
||||||
import ConfirmDialog from '$lib/components/ConfirmDialog.svelte';
|
import ConfirmDialog from '$lib/components/ConfirmDialog.svelte';
|
||||||
import SearchLoader from '$lib/components/SearchLoader.svelte';
|
import SearchLoader from '$lib/components/SearchLoader.svelte';
|
||||||
@@ -105,6 +106,7 @@
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
profileStore.load();
|
profileStore.load();
|
||||||
|
void wishlistStore.refresh();
|
||||||
document.addEventListener('click', handleClickOutside);
|
document.addEventListener('click', handleClickOutside);
|
||||||
document.addEventListener('keydown', handleKey);
|
document.addEventListener('keydown', handleKey);
|
||||||
return () => {
|
return () => {
|
||||||
@@ -211,8 +213,17 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="bar-right">
|
<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} />
|
<Heart size={20} strokeWidth={2} />
|
||||||
|
{#if wishlistStore.count > 0}
|
||||||
|
<span class="badge">{wishlistStore.count}</span>
|
||||||
|
{/if}
|
||||||
</a>
|
</a>
|
||||||
<a href="/admin" class="nav-link" aria-label="Einstellungen">
|
<a href="/admin" class="nav-link" aria-label="Einstellungen">
|
||||||
<Settings size={20} strokeWidth={2} />
|
<Settings size={20} strokeWidth={2} />
|
||||||
@@ -399,10 +410,28 @@
|
|||||||
border-radius: 999px;
|
border-radius: 999px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-size: 1.15rem;
|
font-size: 1.15rem;
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
.nav-link:hover {
|
.nav-link:hover {
|
||||||
background: #f4f8f5;
|
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 {
|
main {
|
||||||
padding: 0 1rem 4rem;
|
padding: 0 1rem 4rem;
|
||||||
max-width: 760px;
|
max-width: 760px;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
|
|
||||||
const AddSchema = z.object({
|
const AddSchema = z.object({
|
||||||
recipe_id: z.number().int().positive(),
|
recipe_id: z.number().int().positive(),
|
||||||
profile_id: z.number().int().positive().nullable().optional()
|
profile_id: z.number().int().positive()
|
||||||
});
|
});
|
||||||
|
|
||||||
const VALID_SORTS: readonly SortKey[] = ['popular', 'newest', 'oldest'] as const;
|
const VALID_SORTS: readonly SortKey[] = ['popular', 'newest', 'oldest'] as const;
|
||||||
@@ -34,7 +34,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||||||
export const POST: RequestHandler = async ({ request }) => {
|
export const POST: RequestHandler = async ({ request }) => {
|
||||||
const body = await request.json().catch(() => null);
|
const body = await request.json().catch(() => null);
|
||||||
const parsed = AddSchema.safeParse(body);
|
const parsed = AddSchema.safeParse(body);
|
||||||
if (!parsed.success) error(400, { message: 'Invalid body' });
|
if (!parsed.success) error(400, { message: 'recipe_id and profile_id required' });
|
||||||
addToWishlist(getDb(), parsed.data.recipe_id, parsed.data.profile_id ?? null);
|
addToWishlist(getDb(), parsed.data.recipe_id, parsed.data.profile_id);
|
||||||
return json({ ok: true }, { status: 201 });
|
return json({ ok: true }, { status: 201 });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,14 +3,15 @@ import { json, error } from '@sveltejs/kit';
|
|||||||
import { getDb } from '$lib/server/db';
|
import { getDb } from '$lib/server/db';
|
||||||
import { removeFromWishlist } from '$lib/server/wishlist/repository';
|
import { removeFromWishlist } from '$lib/server/wishlist/repository';
|
||||||
|
|
||||||
function parseId(raw: string): number {
|
function parsePositiveInt(raw: string | null, field: string): number {
|
||||||
const id = Number(raw);
|
const n = raw === null ? NaN : Number(raw);
|
||||||
if (!Number.isInteger(id) || id <= 0) error(400, { message: 'Invalid recipe_id' });
|
if (!Number.isInteger(n) || n <= 0) error(400, { message: `Invalid ${field}` });
|
||||||
return id;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DELETE: RequestHandler = async ({ params }) => {
|
export const DELETE: RequestHandler = async ({ params, url }) => {
|
||||||
const id = parseId(params.recipe_id!);
|
const id = parsePositiveInt(params.recipe_id!, 'recipe_id');
|
||||||
removeFromWishlist(getDb(), id);
|
const profileId = parsePositiveInt(url.searchParams.get('profile_id'), 'profile_id');
|
||||||
|
removeFromWishlist(getDb(), id, profileId);
|
||||||
return json({ ok: true });
|
return json({ ok: true });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
import type { RequestHandler } from './$types';
|
|
||||||
import { json, error } from '@sveltejs/kit';
|
|
||||||
import { z } from 'zod';
|
|
||||||
import { getDb } from '$lib/server/db';
|
|
||||||
import { likeWish, unlikeWish } from '$lib/server/wishlist/repository';
|
|
||||||
|
|
||||||
const Schema = z.object({ profile_id: z.number().int().positive() });
|
|
||||||
|
|
||||||
function parseId(raw: string): number {
|
|
||||||
const id = Number(raw);
|
|
||||||
if (!Number.isInteger(id) || id <= 0) error(400, { message: 'Invalid recipe_id' });
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PUT: RequestHandler = async ({ params, request }) => {
|
|
||||||
const id = parseId(params.recipe_id!);
|
|
||||||
const body = await request.json().catch(() => null);
|
|
||||||
const parsed = Schema.safeParse(body);
|
|
||||||
if (!parsed.success) error(400, { message: 'Invalid body' });
|
|
||||||
likeWish(getDb(), id, parsed.data.profile_id);
|
|
||||||
return json({ ok: true });
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DELETE: RequestHandler = async ({ params, request }) => {
|
|
||||||
const id = parseId(params.recipe_id!);
|
|
||||||
const body = await request.json().catch(() => null);
|
|
||||||
const parsed = Schema.safeParse(body);
|
|
||||||
if (!parsed.success) error(400, { message: 'Invalid body' });
|
|
||||||
unlikeWish(getDb(), id, parsed.data.profile_id);
|
|
||||||
return json({ ok: true });
|
|
||||||
};
|
|
||||||
8
src/routes/api/wishlist/count/+server.ts
Normal file
8
src/routes/api/wishlist/count/+server.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import type { RequestHandler } from './$types';
|
||||||
|
import { json } from '@sveltejs/kit';
|
||||||
|
import { getDb } from '$lib/server/db';
|
||||||
|
import { countWishlistRecipes } from '$lib/server/wishlist/repository';
|
||||||
|
|
||||||
|
export const GET: RequestHandler = async () => {
|
||||||
|
return json({ count: countWishlistRecipes(getDb()) });
|
||||||
|
};
|
||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
listFavoriteProfiles,
|
listFavoriteProfiles,
|
||||||
listRatings
|
listRatings
|
||||||
} from '$lib/server/recipes/actions';
|
} from '$lib/server/recipes/actions';
|
||||||
|
import { listWishlistProfileIds } from '$lib/server/wishlist/repository';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params }) => {
|
export const load: PageServerLoad = async ({ params }) => {
|
||||||
const id = Number(params.id);
|
const id = Number(params.id);
|
||||||
@@ -19,7 +20,16 @@ export const load: PageServerLoad = async ({ params }) => {
|
|||||||
const comments = listComments(db, id);
|
const comments = listComments(db, id);
|
||||||
const cooking_log = listCookingLog(db, id);
|
const cooking_log = listCookingLog(db, id);
|
||||||
const favorite_profile_ids = listFavoriteProfiles(db, id);
|
const favorite_profile_ids = listFavoriteProfiles(db, id);
|
||||||
|
const wishlist_profile_ids = listWishlistProfileIds(db, id);
|
||||||
const avg_stars =
|
const avg_stars =
|
||||||
ratings.length === 0 ? null : ratings.reduce((s, r) => s + r.stars, 0) / ratings.length;
|
ratings.length === 0 ? null : ratings.reduce((s, r) => s + r.stars, 0) / ratings.length;
|
||||||
return { recipe, ratings, comments, cooking_log, favorite_profile_ids, avg_stars };
|
return {
|
||||||
|
recipe,
|
||||||
|
ratings,
|
||||||
|
comments,
|
||||||
|
cooking_log,
|
||||||
|
favorite_profile_ids,
|
||||||
|
wishlist_profile_ids,
|
||||||
|
avg_stars
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
import RecipeView from '$lib/components/RecipeView.svelte';
|
import RecipeView from '$lib/components/RecipeView.svelte';
|
||||||
import StarRating from '$lib/components/StarRating.svelte';
|
import StarRating from '$lib/components/StarRating.svelte';
|
||||||
import { profileStore } from '$lib/client/profile.svelte';
|
import { profileStore } from '$lib/client/profile.svelte';
|
||||||
|
import { wishlistStore } from '$lib/client/wishlist.svelte';
|
||||||
import { confirmAction, alertAction } from '$lib/client/confirm.svelte';
|
import { confirmAction, alertAction } from '$lib/client/confirm.svelte';
|
||||||
import type { CommentRow } from '$lib/server/recipes/actions';
|
import type { CommentRow } from '$lib/server/recipes/actions';
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@
|
|||||||
let comments = $state<CommentRow[]>([]);
|
let comments = $state<CommentRow[]>([]);
|
||||||
let cookingLog = $state<typeof data.cooking_log>([]);
|
let cookingLog = $state<typeof data.cooking_log>([]);
|
||||||
let favoriteProfileIds = $state<number[]>([]);
|
let favoriteProfileIds = $state<number[]>([]);
|
||||||
let onWishlist = $state(false);
|
let wishlistProfileIds = $state<number[]>([]);
|
||||||
let newComment = $state('');
|
let newComment = $state('');
|
||||||
|
|
||||||
let title = $state('');
|
let title = $state('');
|
||||||
@@ -37,6 +38,7 @@
|
|||||||
comments = [...data.comments];
|
comments = [...data.comments];
|
||||||
cookingLog = [...data.cooking_log];
|
cookingLog = [...data.cooking_log];
|
||||||
favoriteProfileIds = [...data.favorite_profile_ids];
|
favoriteProfileIds = [...data.favorite_profile_ids];
|
||||||
|
wishlistProfileIds = [...data.wishlist_profile_ids];
|
||||||
title = data.recipe.title;
|
title = data.recipe.title;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -50,6 +52,10 @@
|
|||||||
profileStore.active ? favoriteProfileIds.includes(profileStore.active.id) : false
|
profileStore.active ? favoriteProfileIds.includes(profileStore.active.id) : false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onMyWishlist = $derived(
|
||||||
|
profileStore.active ? wishlistProfileIds.includes(profileStore.active.id) : false
|
||||||
|
);
|
||||||
|
|
||||||
async function setRating(stars: number) {
|
async function setRating(stars: number) {
|
||||||
if (!profileStore.active) {
|
if (!profileStore.active) {
|
||||||
await alertAction({
|
await alertAction({
|
||||||
@@ -195,27 +201,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function toggleWishlist() {
|
async function toggleWishlist() {
|
||||||
if (onWishlist) {
|
if (!profileStore.active) {
|
||||||
await fetch(`/api/wishlist/${data.recipe.id}`, { method: 'DELETE' });
|
await alertAction({
|
||||||
onWishlist = false;
|
title: 'Kein Profil gewählt',
|
||||||
|
message: 'Tippe oben rechts auf „Profil wählen", dann klappt die Aktion.'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const profileId = profileStore.active.id;
|
||||||
|
if (onMyWishlist) {
|
||||||
|
await fetch(`/api/wishlist/${data.recipe.id}?profile_id=${profileId}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
wishlistProfileIds = wishlistProfileIds.filter((id) => id !== profileId);
|
||||||
} else {
|
} else {
|
||||||
await fetch('/api/wishlist', {
|
await fetch('/api/wishlist', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'content-type': 'application/json' },
|
headers: { 'content-type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({ recipe_id: data.recipe.id, profile_id: profileId })
|
||||||
recipe_id: data.recipe.id,
|
|
||||||
profile_id: profileStore.active?.id ?? null
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
onWishlist = true;
|
wishlistProfileIds = [...wishlistProfileIds, profileId];
|
||||||
}
|
}
|
||||||
}
|
void wishlistStore.refresh();
|
||||||
|
|
||||||
async function refreshWishlistState() {
|
|
||||||
const res = await fetch('/api/wishlist?sort=newest');
|
|
||||||
if (!res.ok) return;
|
|
||||||
const body = await res.json();
|
|
||||||
onWishlist = body.entries.some((e: { recipe_id: number }) => e.recipe_id === data.recipe.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wake-Lock
|
// Wake-Lock
|
||||||
@@ -232,7 +239,6 @@
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
void requestWakeLock();
|
void requestWakeLock();
|
||||||
void refreshWishlistState();
|
|
||||||
const onVisibility = () => {
|
const onVisibility = () => {
|
||||||
if (document.visibilityState === 'visible' && !wakeLock) void requestWakeLock();
|
if (document.visibilityState === 'visible' && !wakeLock) void requestWakeLock();
|
||||||
};
|
};
|
||||||
@@ -286,8 +292,8 @@
|
|||||||
<Heart size={18} strokeWidth={2} fill={isFav ? 'currentColor' : 'none'} />
|
<Heart size={18} strokeWidth={2} fill={isFav ? 'currentColor' : 'none'} />
|
||||||
<span>Favorit</span>
|
<span>Favorit</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn" class:wish={onWishlist} onclick={toggleWishlist}>
|
<button class="btn" class:wish={onMyWishlist} onclick={toggleWishlist}>
|
||||||
{#if onWishlist}
|
{#if onMyWishlist}
|
||||||
<Check size={18} strokeWidth={2.5} />
|
<Check size={18} strokeWidth={2.5} />
|
||||||
<span>Auf Wunschliste</span>
|
<span>Auf Wunschliste</span>
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { Heart, Trash2, CookingPot } from 'lucide-svelte';
|
import { Heart, CookingPot } from 'lucide-svelte';
|
||||||
import { profileStore } from '$lib/client/profile.svelte';
|
import { profileStore } from '$lib/client/profile.svelte';
|
||||||
import { confirmAction, alertAction } from '$lib/client/confirm.svelte';
|
import { wishlistStore } from '$lib/client/wishlist.svelte';
|
||||||
|
import { alertAction } from '$lib/client/confirm.svelte';
|
||||||
import type { WishlistEntry, SortKey } from '$lib/server/wishlist/repository';
|
import type { WishlistEntry, SortKey } from '$lib/server/wishlist/repository';
|
||||||
|
|
||||||
let entries = $state<WishlistEntry[]>([]);
|
let entries = $state<WishlistEntry[]>([]);
|
||||||
@@ -26,36 +27,34 @@
|
|||||||
void load();
|
void load();
|
||||||
});
|
});
|
||||||
|
|
||||||
async function toggleLike(entry: WishlistEntry) {
|
async function toggleMine(entry: WishlistEntry) {
|
||||||
if (!profileStore.active) {
|
if (!profileStore.active) {
|
||||||
await alertAction({
|
await alertAction({
|
||||||
title: 'Kein Profil gewählt',
|
title: 'Kein Profil gewählt',
|
||||||
message: 'Tippe oben rechts auf „Profil wählen", um zu liken.'
|
message: 'Tippe oben rechts auf „Profil wählen", um mitzuwünschen.'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const method = entry.liked_by_me ? 'DELETE' : 'PUT';
|
const profileId = profileStore.active.id;
|
||||||
await fetch(`/api/wishlist/${entry.recipe_id}/like`, {
|
if (entry.on_my_wishlist) {
|
||||||
method,
|
await fetch(`/api/wishlist/${entry.recipe_id}?profile_id=${profileId}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await fetch('/api/wishlist', {
|
||||||
|
method: 'POST',
|
||||||
headers: { 'content-type': 'application/json' },
|
headers: { 'content-type': 'application/json' },
|
||||||
body: JSON.stringify({ profile_id: profileStore.active.id })
|
body: JSON.stringify({ recipe_id: entry.recipe_id, profile_id: profileId })
|
||||||
});
|
});
|
||||||
|
}
|
||||||
await load();
|
await load();
|
||||||
|
void wishlistStore.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function remove(entry: WishlistEntry) {
|
onMount(() => {
|
||||||
const ok = await confirmAction({
|
void load();
|
||||||
title: 'Von der Wunschliste entfernen?',
|
void wishlistStore.refresh();
|
||||||
message: `„${entry.title}" wird aus der Wunschliste entfernt. Das Rezept selbst bleibt gespeichert.`,
|
|
||||||
confirmLabel: 'Entfernen',
|
|
||||||
destructive: true
|
|
||||||
});
|
});
|
||||||
if (!ok) return;
|
|
||||||
await fetch(`/api/wishlist/${entry.recipe_id}`, { method: 'DELETE' });
|
|
||||||
await load();
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(load);
|
|
||||||
|
|
||||||
function resolveImage(p: string | null): string | null {
|
function resolveImage(p: string | null): string | null {
|
||||||
if (!p) return null;
|
if (!p) return null;
|
||||||
@@ -100,11 +99,11 @@
|
|||||||
<div class="text">
|
<div class="text">
|
||||||
<div class="title">{e.title}</div>
|
<div class="title">{e.title}</div>
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
{#if e.added_by_name}
|
{#if e.wanted_by_names}
|
||||||
<span>von {e.added_by_name}</span>
|
<span class="wanted-by">{e.wanted_by_names}</span>
|
||||||
{/if}
|
{/if}
|
||||||
{#if e.source_domain}
|
{#if e.source_domain}
|
||||||
<span>· {e.source_domain}</span>
|
<span class="src">· {e.source_domain}</span>
|
||||||
{/if}
|
{/if}
|
||||||
{#if e.avg_stars !== null}
|
{#if e.avg_stars !== null}
|
||||||
<span>· ★ {e.avg_stars.toFixed(1)}</span>
|
<span>· ★ {e.avg_stars.toFixed(1)}</span>
|
||||||
@@ -115,18 +114,15 @@
|
|||||||
<div class="actions">
|
<div class="actions">
|
||||||
<button
|
<button
|
||||||
class="like"
|
class="like"
|
||||||
class:active={e.liked_by_me}
|
class:active={e.on_my_wishlist}
|
||||||
aria-label={e.liked_by_me ? 'Unlike' : 'Like'}
|
aria-label={e.on_my_wishlist ? 'Ich will das nicht mehr' : 'Ich will das auch'}
|
||||||
onclick={() => toggleLike(e)}
|
onclick={() => toggleMine(e)}
|
||||||
>
|
>
|
||||||
<Heart size={18} strokeWidth={2} fill={e.liked_by_me ? 'currentColor' : 'none'} />
|
<Heart size={18} strokeWidth={2} fill={e.on_my_wishlist ? 'currentColor' : 'none'} />
|
||||||
{#if e.like_count > 0}
|
{#if e.wanted_by_count > 0}
|
||||||
<span class="count">{e.like_count}</span>
|
<span class="count">{e.wanted_by_count}</span>
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
<button class="del" aria-label="Entfernen" onclick={() => remove(e)}>
|
|
||||||
<Trash2 size={18} strokeWidth={2} />
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
@@ -175,7 +171,8 @@
|
|||||||
padding: 3rem 1rem;
|
padding: 3rem 1rem;
|
||||||
}
|
}
|
||||||
.big {
|
.big {
|
||||||
font-size: 3rem;
|
color: #8fb097;
|
||||||
|
display: inline-flex;
|
||||||
margin: 0 0 0.5rem;
|
margin: 0 0 0.5rem;
|
||||||
}
|
}
|
||||||
.hint {
|
.hint {
|
||||||
@@ -215,7 +212,7 @@
|
|||||||
background: #eef3ef;
|
background: #eef3ef;
|
||||||
display: grid;
|
display: grid;
|
||||||
place-items: center;
|
place-items: center;
|
||||||
font-size: 2rem;
|
color: #8fb097;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
.text {
|
.text {
|
||||||
@@ -239,15 +236,16 @@
|
|||||||
font-size: 0.82rem;
|
font-size: 0.82rem;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
.wanted-by {
|
||||||
|
color: #2b6a3d;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
.actions {
|
.actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
align-items: center;
|
||||||
gap: 0.4rem;
|
|
||||||
padding: 0.5rem 0.6rem 0.5rem 0;
|
padding: 0.5rem 0.6rem 0.5rem 0;
|
||||||
justify-content: center;
|
|
||||||
}
|
}
|
||||||
.like,
|
.like {
|
||||||
.del {
|
|
||||||
min-width: 48px;
|
min-width: 48px;
|
||||||
min-height: 44px;
|
min-height: 44px;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
@@ -259,6 +257,7 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 0.3rem;
|
gap: 0.3rem;
|
||||||
font-size: 1.05rem;
|
font-size: 1.05rem;
|
||||||
|
color: #444;
|
||||||
}
|
}
|
||||||
.like.active {
|
.like.active {
|
||||||
color: #c53030;
|
color: #c53030;
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import {
|
|||||||
addToWishlist,
|
addToWishlist,
|
||||||
removeFromWishlist,
|
removeFromWishlist,
|
||||||
listWishlist,
|
listWishlist,
|
||||||
isOnWishlist,
|
listWishlistProfileIds,
|
||||||
likeWish,
|
isOnMyWishlist,
|
||||||
unlikeWish
|
countWishlistRecipes
|
||||||
} from '../../src/lib/server/wishlist/repository';
|
} from '../../src/lib/server/wishlist/repository';
|
||||||
import type { Recipe } from '../../src/lib/types';
|
import type { Recipe } from '../../src/lib/types';
|
||||||
|
|
||||||
@@ -38,96 +38,95 @@ beforeEach(() => {
|
|||||||
db = openInMemoryForTest();
|
db = openInMemoryForTest();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('wishlist add/remove', () => {
|
describe('per-user wishlist', () => {
|
||||||
it('adds and lists', () => {
|
it('adds and lists for a single profile', () => {
|
||||||
const r1 = insertRecipe(db, recipe('Carbonara'));
|
const r1 = insertRecipe(db, recipe('Carbonara'));
|
||||||
const p = createProfile(db, 'Hendrik');
|
const p = createProfile(db, 'Hendrik');
|
||||||
addToWishlist(db, r1, p.id);
|
addToWishlist(db, r1, p.id);
|
||||||
expect(isOnWishlist(db, r1)).toBe(true);
|
expect(isOnMyWishlist(db, r1, p.id)).toBe(true);
|
||||||
|
|
||||||
const list = listWishlist(db, p.id);
|
const list = listWishlist(db, p.id);
|
||||||
expect(list.length).toBe(1);
|
expect(list.length).toBe(1);
|
||||||
expect(list[0].title).toBe('Carbonara');
|
expect(list[0].title).toBe('Carbonara');
|
||||||
expect(list[0].added_by_name).toBe('Hendrik');
|
expect(list[0].wanted_by_count).toBe(1);
|
||||||
|
expect(list[0].wanted_by_names).toBe('Hendrik');
|
||||||
|
expect(list[0].on_my_wishlist).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is idempotent on double-add', () => {
|
it('aggregates multiple users per recipe', () => {
|
||||||
|
const r1 = insertRecipe(db, recipe('Pizza'));
|
||||||
|
const a = createProfile(db, 'Alice');
|
||||||
|
const b = createProfile(db, 'Bob');
|
||||||
|
const c = createProfile(db, 'Cara');
|
||||||
|
addToWishlist(db, r1, a.id);
|
||||||
|
addToWishlist(db, r1, b.id);
|
||||||
|
addToWishlist(db, r1, c.id);
|
||||||
|
|
||||||
|
const listFromA = listWishlist(db, a.id);
|
||||||
|
expect(listFromA.length).toBe(1);
|
||||||
|
expect(listFromA[0].wanted_by_count).toBe(3);
|
||||||
|
expect(listFromA[0].on_my_wishlist).toBe(1);
|
||||||
|
|
||||||
|
const ids = listWishlistProfileIds(db, r1);
|
||||||
|
expect(ids.sort()).toEqual([a.id, b.id, c.id].sort());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is idempotent on double-add for same profile', () => {
|
||||||
const r1 = insertRecipe(db, recipe('Pizza'));
|
const r1 = insertRecipe(db, recipe('Pizza'));
|
||||||
const p = createProfile(db, 'A');
|
const p = createProfile(db, 'A');
|
||||||
addToWishlist(db, r1, p.id);
|
addToWishlist(db, r1, p.id);
|
||||||
addToWishlist(db, r1, p.id);
|
addToWishlist(db, r1, p.id);
|
||||||
expect(listWishlist(db, p.id).length).toBe(1);
|
const list = listWishlist(db, p.id);
|
||||||
|
expect(list[0].wanted_by_count).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes', () => {
|
it('removes only my entry, keeps others', () => {
|
||||||
const r1 = insertRecipe(db, recipe('X'));
|
const r1 = insertRecipe(db, recipe('Salad'));
|
||||||
addToWishlist(db, r1, null);
|
const a = createProfile(db, 'A');
|
||||||
removeFromWishlist(db, r1);
|
const b = createProfile(db, 'B');
|
||||||
expect(listWishlist(db, null).length).toBe(0);
|
addToWishlist(db, r1, a.id);
|
||||||
|
addToWishlist(db, r1, b.id);
|
||||||
|
removeFromWishlist(db, r1, a.id);
|
||||||
|
expect(isOnMyWishlist(db, r1, a.id)).toBe(false);
|
||||||
|
expect(isOnMyWishlist(db, r1, b.id)).toBe(true);
|
||||||
|
expect(listWishlist(db, b.id)[0].wanted_by_count).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cascades with recipe delete', () => {
|
it('on_my_wishlist is 0 for profiles that did not wish', () => {
|
||||||
|
const r1 = insertRecipe(db, recipe('Curry'));
|
||||||
|
const a = createProfile(db, 'A');
|
||||||
|
const b = createProfile(db, 'B');
|
||||||
|
addToWishlist(db, r1, a.id);
|
||||||
|
|
||||||
|
const listFromB = listWishlist(db, b.id);
|
||||||
|
expect(listFromB[0].on_my_wishlist).toBe(0);
|
||||||
|
expect(listFromB[0].wanted_by_count).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('cascades when recipe is deleted', () => {
|
||||||
const r1 = insertRecipe(db, recipe('X'));
|
const r1 = insertRecipe(db, recipe('X'));
|
||||||
addToWishlist(db, r1, null);
|
const a = createProfile(db, 'A');
|
||||||
|
addToWishlist(db, r1, a.id);
|
||||||
db.prepare('DELETE FROM recipe WHERE id = ?').run(r1);
|
db.prepare('DELETE FROM recipe WHERE id = ?').run(r1);
|
||||||
|
expect(listWishlist(db, a.id).length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('cascades when profile is deleted', () => {
|
||||||
|
const r1 = insertRecipe(db, recipe('X'));
|
||||||
|
const a = createProfile(db, 'A');
|
||||||
|
addToWishlist(db, r1, a.id);
|
||||||
|
db.prepare('DELETE FROM profile WHERE id = ?').run(a.id);
|
||||||
expect(listWishlist(db, null).length).toBe(0);
|
expect(listWishlist(db, null).length).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('wishlist likes + sort', () => {
|
it('countWishlistRecipes counts distinct recipes (not rows)', () => {
|
||||||
it('counts likes per entry and shows liked_by_me for active profile', () => {
|
|
||||||
const r1 = insertRecipe(db, recipe('R1'));
|
const r1 = insertRecipe(db, recipe('R1'));
|
||||||
const r2 = insertRecipe(db, recipe('R2'));
|
const r2 = insertRecipe(db, recipe('R2'));
|
||||||
const a = createProfile(db, 'A');
|
const a = createProfile(db, 'A');
|
||||||
const b = createProfile(db, 'B');
|
const b = createProfile(db, 'B');
|
||||||
const c = createProfile(db, 'C');
|
|
||||||
addToWishlist(db, r1, a.id);
|
addToWishlist(db, r1, a.id);
|
||||||
|
addToWishlist(db, r1, b.id); // same recipe, different user
|
||||||
addToWishlist(db, r2, a.id);
|
addToWishlist(db, r2, a.id);
|
||||||
likeWish(db, r1, a.id);
|
expect(countWishlistRecipes(db)).toBe(2);
|
||||||
likeWish(db, r1, b.id);
|
|
||||||
likeWish(db, r1, c.id);
|
|
||||||
likeWish(db, r2, a.id);
|
|
||||||
|
|
||||||
const listA = listWishlist(db, a.id, 'popular');
|
|
||||||
expect(listA[0].title).toBe('R1');
|
|
||||||
expect(listA[0].like_count).toBe(3);
|
|
||||||
expect(listA[0].liked_by_me).toBe(1);
|
|
||||||
expect(listA[1].title).toBe('R2');
|
|
||||||
expect(listA[1].like_count).toBe(1);
|
|
||||||
|
|
||||||
const listB = listWishlist(db, b.id);
|
|
||||||
expect(listB.find((e) => e.recipe_id === r1)!.liked_by_me).toBe(1);
|
|
||||||
expect(listB.find((e) => e.recipe_id === r2)!.liked_by_me).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('unlike is idempotent and decrements count', () => {
|
|
||||||
const r = insertRecipe(db, recipe('R'));
|
|
||||||
const a = createProfile(db, 'A');
|
|
||||||
addToWishlist(db, r, a.id);
|
|
||||||
likeWish(db, r, a.id);
|
|
||||||
unlikeWish(db, r, a.id);
|
|
||||||
unlikeWish(db, r, a.id);
|
|
||||||
const [entry] = listWishlist(db, a.id);
|
|
||||||
expect(entry.like_count).toBe(0);
|
|
||||||
expect(entry.liked_by_me).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sort=newest orders by added_at desc, oldest asc', () => {
|
|
||||||
const r1 = insertRecipe(db, recipe('First'));
|
|
||||||
// Force different timestamps via raw insert with explicit added_at
|
|
||||||
db.prepare("INSERT INTO wishlist(recipe_id, added_at) VALUES (?, '2026-01-01 10:00:00')").run(r1);
|
|
||||||
const r2 = insertRecipe(db, recipe('Second'));
|
|
||||||
db.prepare("INSERT INTO wishlist(recipe_id, added_at) VALUES (?, '2026-01-02 10:00:00')").run(r2);
|
|
||||||
|
|
||||||
expect(listWishlist(db, null, 'newest').map((e) => e.title)).toEqual(['Second', 'First']);
|
|
||||||
expect(listWishlist(db, null, 'oldest').map((e) => e.title)).toEqual(['First', 'Second']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('handles anonymous (no active profile) — liked_by_me always 0', () => {
|
|
||||||
const r = insertRecipe(db, recipe('R'));
|
|
||||||
addToWishlist(db, r, null);
|
|
||||||
likeWish(db, r, createProfile(db, 'A').id);
|
|
||||||
const [entry] = listWishlist(db, null);
|
|
||||||
expect(entry.like_count).toBe(1);
|
|
||||||
expect(entry.liked_by_me).toBe(0);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user