refactor(client): requireProfile(message?) + Wunschliste migriert (Item G)
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m21s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m21s
Option B aus dem Roadmap-Plan. requireProfile bekommt einen optionalen message-Parameter mit dem bisherigen Text als Default — die 5 Bestands- Aufrufe aendern sich nicht, die Wunschliste nutzt die Custom-Message „um mitzuwünschen" sauber ueber den Helper statt mit dupliziertem alertAction-Block. Netto: -3 Zeilen in wishlist/+page.svelte, eine Duplikation weniger, Helper dokumentiert jetzt explizit den Message-Override-Use-Case. Gate: svelte-check 0 Warnings, 184/184 Tests, Wunschliste zeigt korrekte Message beim Klick ohne Profil. Refs docs/superpowers/plans/2026-04-19-post-review-roadmap.md Item G. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -66,12 +66,14 @@ export const profileStore = new ProfileStore();
|
|||||||
* Returns the active profile, or null after showing the standard
|
* Returns the active profile, or null after showing the standard
|
||||||
* "kein Profil gewählt" dialog. Use as the first line of any per-profile
|
* "kein Profil gewählt" dialog. Use as the first line of any per-profile
|
||||||
* action so we don't repeat the guard at every call-site.
|
* action so we don't repeat the guard at every call-site.
|
||||||
|
*
|
||||||
|
* `message` ueberschreibt den Default, wenn eine Aktion einen spezifischen
|
||||||
|
* Hinweis braucht (z. B. „um mitzuwünschen" auf der Wunschliste).
|
||||||
*/
|
*/
|
||||||
export async function requireProfile(): Promise<Profile | null> {
|
export async function requireProfile(
|
||||||
|
message = 'Tippe oben rechts auf „Profil wählen", dann klappt die Aktion.'
|
||||||
|
): Promise<Profile | null> {
|
||||||
if (profileStore.active) return profileStore.active;
|
if (profileStore.active) return profileStore.active;
|
||||||
await alertAction({
|
await alertAction({ title: 'Kein Profil gewählt', message });
|
||||||
title: 'Kein Profil gewählt',
|
|
||||||
message: 'Tippe oben rechts auf „Profil wählen", dann klappt die Aktion.'
|
|
||||||
});
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { Utensils, Trash2, CookingPot } from 'lucide-svelte';
|
import { Utensils, Trash2, CookingPot } from 'lucide-svelte';
|
||||||
import { profileStore } from '$lib/client/profile.svelte';
|
import { profileStore, requireProfile } from '$lib/client/profile.svelte';
|
||||||
import { wishlistStore } from '$lib/client/wishlist.svelte';
|
import { wishlistStore } from '$lib/client/wishlist.svelte';
|
||||||
import { alertAction, confirmAction } from '$lib/client/confirm.svelte';
|
import { confirmAction } from '$lib/client/confirm.svelte';
|
||||||
import { requireOnline } from '$lib/client/require-online';
|
import { requireOnline } from '$lib/client/require-online';
|
||||||
import type { WishlistEntry, SortKey } from '$lib/server/wishlist/repository';
|
import type { WishlistEntry, SortKey } from '$lib/server/wishlist/repository';
|
||||||
|
|
||||||
@@ -35,15 +35,12 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function toggleMine(entry: WishlistEntry) {
|
async function toggleMine(entry: WishlistEntry) {
|
||||||
if (!profileStore.active) {
|
const profile = await requireProfile(
|
||||||
await alertAction({
|
'Tippe oben rechts auf „Profil wählen", um mitzuwünschen.'
|
||||||
title: 'Kein Profil gewählt',
|
);
|
||||||
message: 'Tippe oben rechts auf „Profil wählen", um mitzuwünschen.'
|
if (!profile) return;
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!requireOnline('Die Wunschlisten-Aktion')) return;
|
if (!requireOnline('Die Wunschlisten-Aktion')) return;
|
||||||
const profileId = profileStore.active.id;
|
const profileId = profile.id;
|
||||||
if (entry.on_my_wishlist) {
|
if (entry.on_my_wishlist) {
|
||||||
await fetch(`/api/wishlist/${entry.recipe_id}?profile_id=${profileId}`, {
|
await fetch(`/api/wishlist/${entry.recipe_id}?profile_id=${profileId}`, {
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
|
|||||||
Reference in New Issue
Block a user