Compare commits
17 Commits
search-sta
...
feature/in
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c07d2f99ad | ||
|
|
8069c5c246 | ||
|
|
7d6ee04fec | ||
|
|
b646720a6e | ||
|
|
526c7433f4 | ||
|
|
96cb55495e | ||
|
|
a1baf7f30a | ||
|
|
b0d5f921e2 | ||
|
|
72816d6b35 | ||
|
|
ad5a6afcd9 | ||
|
|
30a409fd16 | ||
|
|
504fbb6cc6 | ||
|
|
d50841c5a6 | ||
|
|
defbb5e24d | ||
|
|
c43b1dca87 | ||
|
|
015cb432fb | ||
|
|
f273942286 |
897
docs/superpowers/plans/2026-04-19-editor-split.md
Normal file
897
docs/superpowers/plans/2026-04-19-editor-split.md
Normal file
@@ -0,0 +1,897 @@
|
||||
# Editor-Split Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use `superpowers:subagent-driven-development` (recommended) or `superpowers:executing-plans` to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Split the monolithic `RecipeEditor.svelte` (628 L) and pull one readability-oriented block out of `RecipeView.svelte` (398 L) by extracting 4 focused Svelte components: `ImageUploadBox`, `IngredientRow`, `StepList`, `TimeDisplay`. No behavior changes, just structure.
|
||||
|
||||
**Architecture:** Parent-owned state stays in the parent (`RecipeEditor` still owns `ingredients: DraftIng[]`, `steps: DraftStep[]`). Sub-components receive props + callbacks and render their own template + scoped CSS. Shared draft types land in `src/lib/components/recipe-editor-types.ts` so sub-components and parent agree on the shape. `RecipeView.TimeDisplay` is pure presentational with no state.
|
||||
|
||||
**Tech Stack:** Svelte 5 runes (`$props`, `$state`, `$derived`), TypeScript-strict, no new runtime deps.
|
||||
|
||||
---
|
||||
|
||||
## Why this is worth doing
|
||||
|
||||
- `RecipeEditor.svelte:42-89` (Bild-Upload) and `RecipeEditor.svelte:313-334` (Zubereitung) are each self-contained logic-islands with their own state and handlers. Extracting them caps the file a Claude can reason about in one shot.
|
||||
- `IngredientRow` renders 10 lines of template with 5 ARIA labels and 6 grid-columns — a natural single-responsibility unit.
|
||||
- `TimeDisplay` is pure formatting; owning it as a component lets future phases (preview, card hover) reuse it.
|
||||
|
||||
## What we are NOT doing
|
||||
|
||||
- No refactor of `RecipeView`'s tabs / servings-stepper / ingredient-display. Those work fine as-is; roadmap only names the 4 above.
|
||||
- No component unit tests (kochwas has none for components; the e2e `recipe-detail.spec.ts` still covers View behavior, and edit-flow is manually smoked).
|
||||
- No `<style global>` extraction. Small CSS duplication (`.add`, `.del` buttons) is accepted.
|
||||
- No prop-type sharing via `<script module>` blocks. A `.ts` sibling file is simpler.
|
||||
|
||||
## Design Snapshot
|
||||
|
||||
**Shared types** — `src/lib/components/recipe-editor-types.ts`:
|
||||
|
||||
```ts
|
||||
export type DraftIng = {
|
||||
qty: string;
|
||||
unit: string;
|
||||
name: string;
|
||||
note: string;
|
||||
};
|
||||
|
||||
export type DraftStep = { text: string };
|
||||
```
|
||||
|
||||
**Component APIs (locked before implementation):**
|
||||
|
||||
```ts
|
||||
// ImageUploadBox.svelte
|
||||
type Props = {
|
||||
recipeId: number;
|
||||
imagePath: string | null; // initial value; component owns its own state after
|
||||
onchange: (path: string | null) => void;
|
||||
};
|
||||
|
||||
// IngredientRow.svelte
|
||||
type Props = {
|
||||
ing: DraftIng; // passed by reference — bind:value=ing.* works transparently
|
||||
idx: number;
|
||||
total: number; // for "last row? disable move-down"
|
||||
onmove: (dir: -1 | 1) => void;
|
||||
onremove: () => void;
|
||||
};
|
||||
|
||||
// StepList.svelte
|
||||
type Props = {
|
||||
steps: DraftStep[]; // passed by reference
|
||||
onadd: () => void;
|
||||
onremove: (idx: number) => void;
|
||||
};
|
||||
|
||||
// TimeDisplay.svelte
|
||||
type Props = {
|
||||
prepTimeMin: number | null;
|
||||
cookTimeMin: number | null;
|
||||
totalTimeMin: number | null;
|
||||
};
|
||||
```
|
||||
|
||||
**Render-wrapping pattern:** The parent keeps the `<section class="block"><h2>…</h2> … </section>` wrappers. Sub-components render bare content (no outer utility-class wrapper), so the parent's scoped `.block` / `h2` styling continues to apply.
|
||||
|
||||
---
|
||||
|
||||
## Task 1: Extract `ImageUploadBox`
|
||||
|
||||
**Files:**
|
||||
- Create: `src/lib/components/ImageUploadBox.svelte`
|
||||
- Modify: `src/lib/components/RecipeEditor.svelte`
|
||||
|
||||
- [ ] **Step 1: Create the new component**
|
||||
|
||||
```svelte
|
||||
<!-- src/lib/components/ImageUploadBox.svelte -->
|
||||
<script lang="ts">
|
||||
import { ImagePlus, ImageOff } from 'lucide-svelte';
|
||||
import { confirmAction } from '$lib/client/confirm.svelte';
|
||||
import { asyncFetch } from '$lib/client/api-fetch-wrapper';
|
||||
import { requireOnline } from '$lib/client/require-online';
|
||||
|
||||
type Props = {
|
||||
recipeId: number;
|
||||
imagePath: string | null;
|
||||
onchange: (path: string | null) => void;
|
||||
};
|
||||
|
||||
let { recipeId, imagePath: initial, onchange }: Props = $props();
|
||||
|
||||
let imagePath = $state<string | null>(initial);
|
||||
let uploading = $state(false);
|
||||
let fileInput: HTMLInputElement | null = $state(null);
|
||||
|
||||
const imageSrc = $derived(
|
||||
imagePath === null
|
||||
? null
|
||||
: /^https?:\/\//i.test(imagePath)
|
||||
? imagePath
|
||||
: `/images/${imagePath}`
|
||||
);
|
||||
|
||||
async function onFileChosen(event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
input.value = '';
|
||||
if (!file) return;
|
||||
if (!requireOnline('Der Bild-Upload')) return;
|
||||
uploading = true;
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append('file', file);
|
||||
const res = await asyncFetch(
|
||||
`/api/recipes/${recipeId}/image`,
|
||||
{ method: 'POST', body: fd },
|
||||
'Upload fehlgeschlagen'
|
||||
);
|
||||
if (!res) return;
|
||||
const body = await res.json();
|
||||
imagePath = body.image_path;
|
||||
onchange(imagePath);
|
||||
} finally {
|
||||
uploading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function removeImage() {
|
||||
if (imagePath === null) return;
|
||||
const ok = await confirmAction({
|
||||
title: 'Bild entfernen?',
|
||||
message: 'Das Rezept wird danach ohne Titelbild angezeigt.',
|
||||
confirmLabel: 'Entfernen',
|
||||
destructive: true
|
||||
});
|
||||
if (!ok) return;
|
||||
if (!requireOnline('Das Entfernen')) return;
|
||||
uploading = true;
|
||||
try {
|
||||
const res = await asyncFetch(
|
||||
`/api/recipes/${recipeId}/image`,
|
||||
{ method: 'DELETE' },
|
||||
'Entfernen fehlgeschlagen'
|
||||
);
|
||||
if (!res) return;
|
||||
imagePath = null;
|
||||
onchange(null);
|
||||
} finally {
|
||||
uploading = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="image-row">
|
||||
<div class="image-preview" class:empty={!imageSrc}>
|
||||
{#if imageSrc}
|
||||
<img src={imageSrc} alt="" />
|
||||
{:else}
|
||||
<span class="placeholder">Kein Bild</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="image-actions">
|
||||
<button
|
||||
class="btn"
|
||||
type="button"
|
||||
onclick={() => fileInput?.click()}
|
||||
disabled={uploading}
|
||||
>
|
||||
<ImagePlus size={16} strokeWidth={2} />
|
||||
<span>{imagePath ? 'Bild ersetzen' : 'Bild hochladen'}</span>
|
||||
</button>
|
||||
{#if imagePath}
|
||||
<button class="btn ghost" type="button" onclick={removeImage} disabled={uploading}>
|
||||
<ImageOff size={16} strokeWidth={2} />
|
||||
<span>Entfernen</span>
|
||||
</button>
|
||||
{/if}
|
||||
{#if uploading}
|
||||
<span class="upload-status">Lade …</span>
|
||||
{/if}
|
||||
</div>
|
||||
<input
|
||||
bind:this={fileInput}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp,image/gif,image/avif"
|
||||
class="file-input"
|
||||
onchange={onFileChosen}
|
||||
/>
|
||||
</div>
|
||||
<p class="image-hint">Max. 10 MB. JPG, PNG, WebP, GIF oder AVIF.</p>
|
||||
|
||||
<style>
|
||||
.image-row {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.image-preview {
|
||||
width: 160px;
|
||||
aspect-ratio: 16 / 10;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
background: #eef3ef;
|
||||
border: 1px solid #e4eae7;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.image-preview img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
.image-preview.empty {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
color: #999;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.image-preview .placeholder {
|
||||
padding: 0 0.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
.image-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
.upload-status {
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.file-input {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
.image-hint {
|
||||
margin: 0.6rem 0 0;
|
||||
color: #888;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.btn {
|
||||
padding: 0.55rem 0.85rem;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #cfd9d1;
|
||||
background: white;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
font-size: 0.9rem;
|
||||
min-height: 40px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.btn.ghost {
|
||||
color: #666;
|
||||
}
|
||||
.btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: progress;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Wire up `RecipeEditor.svelte`**
|
||||
|
||||
Remove lines 30–89 (imagePath/uploading/fileInput state, imageSrc derived, onFileChosen, removeImage).
|
||||
|
||||
Remove these imports at the top:
|
||||
```ts
|
||||
import { Plus, Trash2, ChevronUp, ChevronDown, ImagePlus, ImageOff } from 'lucide-svelte';
|
||||
import { confirmAction } from '$lib/client/confirm.svelte';
|
||||
import { asyncFetch } from '$lib/client/api-fetch-wrapper';
|
||||
import { requireOnline } from '$lib/client/require-online';
|
||||
```
|
||||
Replace with (Task 1 needs only Plus + Trash2 + Chevrons — the image-specific imports move to the sub-component; `confirmAction`/`asyncFetch`/`requireOnline` stay for future tasks):
|
||||
```ts
|
||||
import { Plus, Trash2, ChevronUp, ChevronDown } from 'lucide-svelte';
|
||||
import ImageUploadBox from '$lib/components/ImageUploadBox.svelte';
|
||||
```
|
||||
|
||||
Remove the image-related CSS (`.image-row`, `.image-preview*`, `.image-actions`, `.image-actions .btn`, `.upload-status`, `.file-input`, `.image-hint`, `.image-block` — those live in the sub-component now).
|
||||
|
||||
Replace the Bild section in the template:
|
||||
```svelte
|
||||
<section class="block">
|
||||
<h2>Bild</h2>
|
||||
<ImageUploadBox
|
||||
recipeId={recipe.id}
|
||||
imagePath={recipe.image_path}
|
||||
onchange={(p) => onimagechange?.(p)}
|
||||
/>
|
||||
</section>
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Run checks**
|
||||
|
||||
```bash
|
||||
npm run check
|
||||
npm test
|
||||
```
|
||||
|
||||
Expected: 0 errors, 196/196 tests pass.
|
||||
|
||||
- [ ] **Step 4: Manual smoke**
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Open any saved recipe → edit → upload an image → verify it shows up and `onimagechange` fires (parent's state updates). Remove the image → confirms the confirm-dialog and removes. Bail out if either flow breaks.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add src/lib/components/ImageUploadBox.svelte src/lib/components/RecipeEditor.svelte
|
||||
git commit -m "$(cat <<'EOF'
|
||||
refactor(editor): ImageUploadBox als eigenstaendige Component
|
||||
|
||||
Isoliert den Bild-Upload-Flow (File-Input, Preview, Entfernen-Dialog)
|
||||
aus dem RecipeEditor. Parent haelt nur noch den <section>-Wrapper und
|
||||
reicht recipe.id + image_path rein, kriegt Aenderungen per onchange
|
||||
callback zurueck.
|
||||
|
||||
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Task 2: Extract types + `IngredientRow`
|
||||
|
||||
**Files:**
|
||||
- Create: `src/lib/components/recipe-editor-types.ts`
|
||||
- Create: `src/lib/components/IngredientRow.svelte`
|
||||
- Modify: `src/lib/components/RecipeEditor.svelte`
|
||||
|
||||
- [ ] **Step 1: Types file**
|
||||
|
||||
```ts
|
||||
// src/lib/components/recipe-editor-types.ts
|
||||
export type DraftIng = {
|
||||
qty: string;
|
||||
unit: string;
|
||||
name: string;
|
||||
note: string;
|
||||
};
|
||||
|
||||
export type DraftStep = { text: string };
|
||||
```
|
||||
|
||||
- [ ] **Step 2: IngredientRow component**
|
||||
|
||||
```svelte
|
||||
<!-- src/lib/components/IngredientRow.svelte -->
|
||||
<script lang="ts">
|
||||
import { Trash2, ChevronUp, ChevronDown } from 'lucide-svelte';
|
||||
import type { DraftIng } from './recipe-editor-types';
|
||||
|
||||
type Props = {
|
||||
ing: DraftIng;
|
||||
idx: number;
|
||||
total: number;
|
||||
onmove: (dir: -1 | 1) => void;
|
||||
onremove: () => void;
|
||||
};
|
||||
|
||||
let { ing, idx, total, onmove, onremove }: Props = $props();
|
||||
</script>
|
||||
|
||||
<li class="ing-row">
|
||||
<div class="move">
|
||||
<button
|
||||
class="move-btn"
|
||||
type="button"
|
||||
aria-label="Zutat nach oben"
|
||||
disabled={idx === 0}
|
||||
onclick={() => onmove(-1)}
|
||||
>
|
||||
<ChevronUp size={14} strokeWidth={2.5} />
|
||||
</button>
|
||||
<button
|
||||
class="move-btn"
|
||||
type="button"
|
||||
aria-label="Zutat nach unten"
|
||||
disabled={idx === total - 1}
|
||||
onclick={() => onmove(1)}
|
||||
>
|
||||
<ChevronDown size={14} strokeWidth={2.5} />
|
||||
</button>
|
||||
</div>
|
||||
<input class="qty" type="text" bind:value={ing.qty} placeholder="Menge" aria-label="Menge" />
|
||||
<input class="unit" type="text" bind:value={ing.unit} placeholder="Einheit" aria-label="Einheit" />
|
||||
<input class="name" type="text" bind:value={ing.name} placeholder="Zutat" aria-label="Zutat" />
|
||||
<input class="note" type="text" bind:value={ing.note} placeholder="Notiz" aria-label="Notiz" />
|
||||
<button class="del" type="button" aria-label="Zutat entfernen" onclick={onremove}>
|
||||
<Trash2 size={16} strokeWidth={2} />
|
||||
</button>
|
||||
</li>
|
||||
|
||||
<style>
|
||||
.ing-row {
|
||||
display: grid;
|
||||
grid-template-columns: 28px 70px 70px 1fr 1fr 40px;
|
||||
gap: 0.35rem;
|
||||
align-items: center;
|
||||
}
|
||||
.move {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
.move-btn {
|
||||
width: 28px;
|
||||
height: 20px;
|
||||
border: 1px solid #cfd9d1;
|
||||
background: white;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
color: #555;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
}
|
||||
.move-btn:hover:not(:disabled) {
|
||||
background: #f4f8f5;
|
||||
}
|
||||
.move-btn:disabled {
|
||||
opacity: 0.3;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.ing-row input {
|
||||
padding: 0.5rem 0.55rem;
|
||||
border: 1px solid #cfd9d1;
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
min-height: 38px;
|
||||
font-family: inherit;
|
||||
min-width: 0;
|
||||
}
|
||||
.del {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 1px solid #f1b4b4;
|
||||
background: white;
|
||||
color: #c53030;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.del:hover {
|
||||
background: #fdf3f3;
|
||||
}
|
||||
@media (max-width: 560px) {
|
||||
.ing-row {
|
||||
grid-template-columns: 28px 70px 1fr 40px;
|
||||
grid-template-areas:
|
||||
'move qty name del'
|
||||
'move unit unit del'
|
||||
'note note note note';
|
||||
}
|
||||
.ing-row .move {
|
||||
grid-area: move;
|
||||
}
|
||||
.ing-row .qty {
|
||||
grid-area: qty;
|
||||
}
|
||||
.ing-row .unit {
|
||||
grid-area: unit;
|
||||
}
|
||||
.ing-row .name {
|
||||
grid-area: name;
|
||||
}
|
||||
.ing-row .note {
|
||||
grid-area: note;
|
||||
}
|
||||
.ing-row .del {
|
||||
grid-area: del;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Wire up `RecipeEditor.svelte`**
|
||||
|
||||
Replace the local `DraftIng` / `DraftStep` type declarations (lines 100–106) with:
|
||||
```ts
|
||||
import type { DraftIng, DraftStep } from '$lib/components/recipe-editor-types';
|
||||
import IngredientRow from '$lib/components/IngredientRow.svelte';
|
||||
```
|
||||
|
||||
In the template, swap the `<li class="ing-row">` block for:
|
||||
```svelte
|
||||
{#each ingredients as ing, idx (idx)}
|
||||
<IngredientRow
|
||||
{ing}
|
||||
{idx}
|
||||
total={ingredients.length}
|
||||
onmove={(dir) => moveIngredient(idx, dir)}
|
||||
onremove={() => removeIngredient(idx)}
|
||||
/>
|
||||
{/each}
|
||||
```
|
||||
|
||||
Remove the CSS for `.ing-row`, `.move`, `.move-btn`, `.ing-row input`, `.del`, and the `@media (max-width: 560px)` block — all now live in `IngredientRow.svelte`.
|
||||
|
||||
Remove the unused imports `ChevronUp`, `ChevronDown`, `Trash2` from RecipeEditor (they moved to the sub-component, but wait — `Trash2` is also used for step-remove. Keep `Trash2`, remove the two Chevrons).
|
||||
|
||||
- [ ] **Step 4: Run checks**
|
||||
|
||||
```bash
|
||||
npm run check
|
||||
npm test
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Manual smoke**
|
||||
|
||||
Open any recipe in edit mode. Add an ingredient, type into all 4 fields, reorder up/down, remove one. Verify save persists the ordering.
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
|
||||
```bash
|
||||
git add src/lib/components/recipe-editor-types.ts src/lib/components/IngredientRow.svelte src/lib/components/RecipeEditor.svelte
|
||||
git commit -m "$(cat <<'EOF'
|
||||
refactor(editor): IngredientRow + shared types
|
||||
|
||||
IngredientRow rendert eine einzelne editierbare Zutat-Zeile. DraftIng
|
||||
und DraftStep sind jetzt in recipe-editor-types.ts, damit Parent und
|
||||
Sub-Components auf dieselbe Form referenzieren.
|
||||
|
||||
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Task 3: Extract `StepList`
|
||||
|
||||
**Files:**
|
||||
- Create: `src/lib/components/StepList.svelte`
|
||||
- Modify: `src/lib/components/RecipeEditor.svelte`
|
||||
|
||||
- [ ] **Step 1: StepList component**
|
||||
|
||||
```svelte
|
||||
<!-- src/lib/components/StepList.svelte -->
|
||||
<script lang="ts">
|
||||
import { Plus, Trash2 } from 'lucide-svelte';
|
||||
import type { DraftStep } from './recipe-editor-types';
|
||||
|
||||
type Props = {
|
||||
steps: DraftStep[];
|
||||
onadd: () => void;
|
||||
onremove: (idx: number) => void;
|
||||
};
|
||||
|
||||
let { steps, onadd, onremove }: Props = $props();
|
||||
</script>
|
||||
|
||||
<ol class="step-list">
|
||||
{#each steps as step, idx (idx)}
|
||||
<li class="step-row">
|
||||
<span class="num">{idx + 1}</span>
|
||||
<textarea
|
||||
bind:value={step.text}
|
||||
rows="3"
|
||||
placeholder="Schritt beschreiben …"
|
||||
></textarea>
|
||||
<button class="del" type="button" aria-label="Schritt entfernen" onclick={() => onremove(idx)}>
|
||||
<Trash2 size={16} strokeWidth={2} />
|
||||
</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ol>
|
||||
<button class="add" type="button" onclick={onadd}>
|
||||
<Plus size={16} strokeWidth={2} />
|
||||
<span>Schritt hinzufügen</span>
|
||||
</button>
|
||||
|
||||
<style>
|
||||
.step-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0 0 0.6rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.step-row {
|
||||
display: grid;
|
||||
grid-template-columns: 32px 1fr 40px;
|
||||
gap: 0.5rem;
|
||||
align-items: start;
|
||||
}
|
||||
.num {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: #2b6a3d;
|
||||
color: white;
|
||||
border-radius: 50%;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
.step-row textarea {
|
||||
padding: 0.55rem 0.7rem;
|
||||
border: 1px solid #cfd9d1;
|
||||
border-radius: 8px;
|
||||
font-size: 0.95rem;
|
||||
font-family: inherit;
|
||||
resize: vertical;
|
||||
min-height: 70px;
|
||||
}
|
||||
.del {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 1px solid #f1b4b4;
|
||||
background: white;
|
||||
color: #c53030;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.del:hover {
|
||||
background: #fdf3f3;
|
||||
}
|
||||
.add {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
padding: 0.55rem 0.9rem;
|
||||
border: 1px dashed #cfd9d1;
|
||||
background: white;
|
||||
color: #2b6a3d;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
font-family: inherit;
|
||||
}
|
||||
.add:hover {
|
||||
background: #f4f8f5;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Wire up `RecipeEditor.svelte`**
|
||||
|
||||
Add import:
|
||||
```ts
|
||||
import StepList from '$lib/components/StepList.svelte';
|
||||
```
|
||||
|
||||
Replace the entire Zubereitung `<section class="block">` template block (starting `<section class="block">` with `<h2>Zubereitung</h2>` through the add-step button):
|
||||
|
||||
```svelte
|
||||
<section class="block">
|
||||
<h2>Zubereitung</h2>
|
||||
<StepList {steps} onadd={addStep} onremove={removeStep} />
|
||||
</section>
|
||||
```
|
||||
|
||||
**CSS audit — what stays and what goes in the parent:**
|
||||
|
||||
Parent's template after Tasks 1–3 still contains:
|
||||
- `<section class="block"><h2>Bild</h2><ImageUploadBox .../></section>` — no `.block` inner styles needed beyond what's in parent.
|
||||
- `<div class="meta">` — still here. Keep `.meta`, `.field`, `.row`, `.small`, `.lbl`.
|
||||
- `<section class="block"><h2>Zutaten</h2><ul class="ing-list">{#each ..}<IngredientRow/>{/each}</ul><button class="add">...</button></section>` — still uses `.ing-list` and `.add`.
|
||||
- `<section class="block"><h2>Zubereitung</h2><StepList/></section>` — no inner CSS.
|
||||
- `<div class="foot"><button class="btn ghost">...</button><button class="btn primary">...</button></div>` — keeps `.foot`, `.btn`, `.btn.ghost`, `.btn.primary`, `.btn:disabled`.
|
||||
|
||||
So parent CSS after Task 3 keeps: `.editor`, `.meta`, `.field`, `.lbl`, `.row`, `.small`, `.block`, `.block h2`, `.ing-list` (the `<ul>` wrapper), `.add` (for "Zutat hinzufügen"), `.foot`, `.btn` and variants.
|
||||
|
||||
Drop from parent CSS in Task 3: `.step-list`, `.step-row`, `.num`, `.step-row textarea`, `.del`.
|
||||
|
||||
- [ ] **Step 3: Run checks**
|
||||
|
||||
```bash
|
||||
npm run check
|
||||
npm test
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Manual smoke**
|
||||
|
||||
Open any recipe → edit → add a step, type, remove, save. Verify steps persist with correct ordering.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add src/lib/components/StepList.svelte src/lib/components/RecipeEditor.svelte
|
||||
git commit -m "$(cat <<'EOF'
|
||||
refactor(editor): StepList als eigenstaendige Component
|
||||
|
||||
Zubereitungs-Liste mit Add + Remove als Sub-Component. Parent steuert
|
||||
nur noch den Wrapper und reicht steps + die zwei Callbacks rein.
|
||||
|
||||
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Task 4: Extract `TimeDisplay` (RecipeView)
|
||||
|
||||
**Files:**
|
||||
- Create: `src/lib/components/TimeDisplay.svelte`
|
||||
- Modify: `src/lib/components/RecipeView.svelte`
|
||||
|
||||
- [ ] **Step 1: TimeDisplay component**
|
||||
|
||||
```svelte
|
||||
<!-- src/lib/components/TimeDisplay.svelte -->
|
||||
<script lang="ts">
|
||||
type Props = {
|
||||
prepTimeMin: number | null;
|
||||
cookTimeMin: number | null;
|
||||
totalTimeMin: number | null;
|
||||
};
|
||||
|
||||
let { prepTimeMin, cookTimeMin, totalTimeMin }: Props = $props();
|
||||
|
||||
const summary = $derived.by(() => {
|
||||
const parts: string[] = [];
|
||||
if (prepTimeMin) parts.push(`Vorb. ${prepTimeMin} min`);
|
||||
if (cookTimeMin) parts.push(`Kochen ${cookTimeMin} min`);
|
||||
if (!prepTimeMin && !cookTimeMin && totalTimeMin)
|
||||
parts.push(`Gesamt ${totalTimeMin} min`);
|
||||
return parts.join(' · ');
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if summary}
|
||||
<p class="times">{summary}</p>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.times {
|
||||
margin: 0 0 0.25rem;
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Wire up `RecipeView.svelte`**
|
||||
|
||||
Add import:
|
||||
```ts
|
||||
import TimeDisplay from '$lib/components/TimeDisplay.svelte';
|
||||
```
|
||||
|
||||
Remove the local `timeSummary()` function (lines 45–52).
|
||||
|
||||
Replace the `{#if timeSummary()}<p class="times">...</p>{/if}` block in the template with:
|
||||
```svelte
|
||||
<TimeDisplay
|
||||
prepTimeMin={recipe.prep_time_min}
|
||||
cookTimeMin={recipe.cook_time_min}
|
||||
totalTimeMin={recipe.total_time_min}
|
||||
/>
|
||||
```
|
||||
|
||||
Remove the `.times` CSS from RecipeView (it's in the sub-component now).
|
||||
|
||||
- [ ] **Step 3: Run checks**
|
||||
|
||||
```bash
|
||||
npm run check
|
||||
npm test
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Manual smoke**
|
||||
|
||||
Open any recipe → verify the time line still shows the same content (Vorb. / Kochen / Gesamt).
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add src/lib/components/TimeDisplay.svelte src/lib/components/RecipeView.svelte
|
||||
git commit -m "$(cat <<'EOF'
|
||||
refactor(view): TimeDisplay als eigenstaendige Component
|
||||
|
||||
timeSummary-Formatierung in eine wiederverwendbare Component
|
||||
gezogen. RecipeView liefert nur noch die drei Werte — zukuenftige
|
||||
Call-Sites (Preview, Hover-Cards) koennen dieselbe Logik reusen.
|
||||
|
||||
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Task 5: Self-review + push
|
||||
|
||||
- [ ] **Step 1: Line-count audit**
|
||||
|
||||
```bash
|
||||
wc -l src/lib/components/RecipeEditor.svelte src/lib/components/RecipeView.svelte src/lib/components/ImageUploadBox.svelte src/lib/components/IngredientRow.svelte src/lib/components/StepList.svelte src/lib/components/TimeDisplay.svelte
|
||||
```
|
||||
|
||||
Expected shape (approximate, ±10%):
|
||||
- `RecipeEditor.svelte`: 628 → ~330–370
|
||||
- `RecipeView.svelte`: 398 → ~380
|
||||
- `ImageUploadBox.svelte`: ~160
|
||||
- `IngredientRow.svelte`: ~110
|
||||
- `StepList.svelte`: ~100
|
||||
- `TimeDisplay.svelte`: ~30
|
||||
|
||||
- [ ] **Step 2: Full test + typecheck**
|
||||
|
||||
```bash
|
||||
npm test
|
||||
npm run check
|
||||
```
|
||||
|
||||
Both green.
|
||||
|
||||
- [ ] **Step 3: Git log review**
|
||||
|
||||
```bash
|
||||
git log --oneline main..HEAD
|
||||
```
|
||||
|
||||
Expected 4 commits:
|
||||
1. `refactor(editor): ImageUploadBox als eigenstaendige Component`
|
||||
2. `refactor(editor): IngredientRow + shared types`
|
||||
3. `refactor(editor): StepList als eigenstaendige Component`
|
||||
4. `refactor(view): TimeDisplay als eigenstaendige Component`
|
||||
|
||||
- [ ] **Step 4: Remote E2E after push**
|
||||
|
||||
```bash
|
||||
git push -u origin editor-split
|
||||
```
|
||||
|
||||
CI builds branch-tagged image. After deploy to `kochwas-dev.siegeln.net`:
|
||||
|
||||
```bash
|
||||
npm run test:e2e:remote
|
||||
```
|
||||
|
||||
Expected: 40/42 green (same as Search-State-Store baseline). `recipe-detail.spec.ts` (6 tests) specifically exercises the View side — must be clean.
|
||||
|
||||
Manual UAT pass on `https://kochwas-dev.siegeln.net/`:
|
||||
- Edit a recipe → upload + remove image.
|
||||
- Add / reorder / remove an ingredient → save → verify persistence on reload.
|
||||
- Add / remove a step → save → verify.
|
||||
- Check time-summary rendering on any recipe with prep/cook/total times set.
|
||||
|
||||
- [ ] **Step 5: Merge to main**
|
||||
|
||||
Once UAT is clean:
|
||||
```bash
|
||||
git checkout main
|
||||
git merge --no-ff editor-split
|
||||
git push origin main
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Risk Notes
|
||||
|
||||
- **Prop-reference mutability.** `IngredientRow` and `StepList` receive `ing` / `steps` by reference and use `bind:value` on their own `<input>` / `<textarea>` elements. Svelte 5 handles this correctly — writes propagate to the parent's `$state` array. Verified pattern with existing `searchFilterStore` usage and similar bind-through-prop in older Svelte 5 components in this codebase.
|
||||
- **Confirm-dialog scope.** `ImageUploadBox` imports `confirmAction` directly rather than using a prop-callback. Consistent with the rest of the codebase (`confirmAction` is a global).
|
||||
- **Scoped CSS duplication.** `.del` and `.add` button styles exist in multiple sub-components. Accepted — the alternative (global button classes) is out of scope for this phase.
|
||||
- **No component unit tests.** Risk: a structural mistake (bad prop passing, missing callback wiring) wouldn't be caught by logic-layer tests. Mitigation: manual smoke test + `npm run check` type-safety + existing e2e coverage on RecipeView side.
|
||||
|
||||
## Deferred — NOT in this plan
|
||||
|
||||
- **Component unit tests with `@testing-library/svelte`:** Would add Vitest+browser setup. Worth doing in a separate phase once the project acquires a second component-refactor candidate.
|
||||
- **Edit-flow E2E spec:** `tests/e2e/remote/recipe-edit.spec.ts` would cover the editor end-to-end. Valuable, but out of scope here — this phase is structural extraction, not test coverage expansion.
|
||||
- **Extract `RecipeHero` / `ServingsStepper` / `TabSwitcher` from RecipeView:** Not on the roadmap. Add to a future phase if RecipeView grows further.
|
||||
@@ -23,8 +23,10 @@ export default defineConfig({
|
||||
headless: true,
|
||||
trace: 'retain-on-failure',
|
||||
screenshot: 'only-on-failure',
|
||||
// Service-Worker zulassen, aber keine Offline-Manipulation — die
|
||||
// Tests hier pruefen Live-Verhalten gegen den Server.
|
||||
serviceWorkers: 'allow'
|
||||
// Service-Worker blocken: Diese Suite testet Live-API-Verhalten gegen
|
||||
// den Server, keine PWA-Features (dafuer offline.spec.ts lokal). Die
|
||||
// frische SW-Registrierung pro Context akkumulierte im Single-Worker-
|
||||
// Run Browser-State und crashte Chromium zufaellig nach 20-30 Specs.
|
||||
serviceWorkers: 'block'
|
||||
}
|
||||
});
|
||||
|
||||
190
src/lib/components/ImageUploadBox.svelte
Normal file
190
src/lib/components/ImageUploadBox.svelte
Normal file
@@ -0,0 +1,190 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import { ImagePlus, ImageOff } from 'lucide-svelte';
|
||||
import { confirmAction } from '$lib/client/confirm.svelte';
|
||||
import { asyncFetch } from '$lib/client/api-fetch-wrapper';
|
||||
import { requireOnline } from '$lib/client/require-online';
|
||||
|
||||
type Props = {
|
||||
recipeId: number;
|
||||
imagePath: string | null;
|
||||
onchange: (path: string | null) => void;
|
||||
};
|
||||
|
||||
let { recipeId, imagePath: initial, onchange }: Props = $props();
|
||||
|
||||
let imagePath = $state<string | null>(untrack(() => initial));
|
||||
let uploading = $state(false);
|
||||
let fileInput: HTMLInputElement | null = $state(null);
|
||||
|
||||
const imageSrc = $derived(
|
||||
imagePath === null
|
||||
? null
|
||||
: /^https?:\/\//i.test(imagePath)
|
||||
? imagePath
|
||||
: `/images/${imagePath}`
|
||||
);
|
||||
|
||||
async function onFileChosen(event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
input.value = '';
|
||||
if (!file) return;
|
||||
if (!requireOnline('Der Bild-Upload')) return;
|
||||
uploading = true;
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append('file', file);
|
||||
const res = await asyncFetch(
|
||||
`/api/recipes/${recipeId}/image`,
|
||||
{ method: 'POST', body: fd },
|
||||
'Upload fehlgeschlagen'
|
||||
);
|
||||
if (!res) return;
|
||||
const body = await res.json();
|
||||
imagePath = body.image_path;
|
||||
onchange(imagePath);
|
||||
} finally {
|
||||
uploading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function removeImage() {
|
||||
if (imagePath === null) return;
|
||||
const ok = await confirmAction({
|
||||
title: 'Bild entfernen?',
|
||||
message: 'Das Rezept wird danach ohne Titelbild angezeigt.',
|
||||
confirmLabel: 'Entfernen',
|
||||
destructive: true
|
||||
});
|
||||
if (!ok) return;
|
||||
if (!requireOnline('Das Entfernen')) return;
|
||||
uploading = true;
|
||||
try {
|
||||
const res = await asyncFetch(
|
||||
`/api/recipes/${recipeId}/image`,
|
||||
{ method: 'DELETE' },
|
||||
'Entfernen fehlgeschlagen'
|
||||
);
|
||||
if (!res) return;
|
||||
imagePath = null;
|
||||
onchange(null);
|
||||
} finally {
|
||||
uploading = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="image-row">
|
||||
<div class="image-preview" class:empty={!imageSrc}>
|
||||
{#if imageSrc}
|
||||
<img src={imageSrc} alt="" />
|
||||
{:else}
|
||||
<span class="placeholder">Kein Bild</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="image-actions">
|
||||
<button
|
||||
class="btn"
|
||||
type="button"
|
||||
onclick={() => fileInput?.click()}
|
||||
disabled={uploading}
|
||||
>
|
||||
<ImagePlus size={16} strokeWidth={2} />
|
||||
<span>{imagePath ? 'Bild ersetzen' : 'Bild hochladen'}</span>
|
||||
</button>
|
||||
{#if imagePath}
|
||||
<button class="btn ghost" type="button" onclick={removeImage} disabled={uploading}>
|
||||
<ImageOff size={16} strokeWidth={2} />
|
||||
<span>Entfernen</span>
|
||||
</button>
|
||||
{/if}
|
||||
{#if uploading}
|
||||
<span class="upload-status">Lade …</span>
|
||||
{/if}
|
||||
</div>
|
||||
<input
|
||||
bind:this={fileInput}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp,image/gif,image/avif"
|
||||
class="file-input"
|
||||
onchange={onFileChosen}
|
||||
/>
|
||||
</div>
|
||||
<p class="image-hint">Max. 10 MB. JPG, PNG, WebP, GIF oder AVIF.</p>
|
||||
|
||||
<style>
|
||||
.image-row {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.image-preview {
|
||||
width: 160px;
|
||||
aspect-ratio: 16 / 10;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
background: #eef3ef;
|
||||
border: 1px solid #e4eae7;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.image-preview img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
.image-preview.empty {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
color: #999;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.image-preview .placeholder {
|
||||
padding: 0 0.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
.image-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
.upload-status {
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.file-input {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
.image-hint {
|
||||
margin: 0.6rem 0 0;
|
||||
color: #888;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.btn {
|
||||
padding: 0.55rem 0.85rem;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #cfd9d1;
|
||||
background: white;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
font-size: 0.9rem;
|
||||
min-height: 40px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.btn.ghost {
|
||||
color: #666;
|
||||
}
|
||||
.btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: progress;
|
||||
}
|
||||
</style>
|
||||
221
src/lib/components/IngredientRow.svelte
Normal file
221
src/lib/components/IngredientRow.svelte
Normal file
@@ -0,0 +1,221 @@
|
||||
<script lang="ts">
|
||||
import { Trash2, ChevronUp, ChevronDown, Plus, X } from 'lucide-svelte';
|
||||
import type { DraftIng } from './recipe-editor-types';
|
||||
|
||||
type Props = {
|
||||
ing: DraftIng;
|
||||
idx: number;
|
||||
total: number;
|
||||
onmove: (dir: -1 | 1) => void;
|
||||
onremove: () => void;
|
||||
onaddSection: () => void;
|
||||
onremoveSection: () => void;
|
||||
};
|
||||
|
||||
let { ing, idx, total, onmove, onremove, onaddSection, onremoveSection }: Props = $props();
|
||||
</script>
|
||||
|
||||
{#if ing.section_heading === null}
|
||||
<li class="section-insert">
|
||||
<button type="button" class="add-section" onclick={onaddSection}>
|
||||
<Plus size={12} strokeWidth={2.5} />
|
||||
<span>Abschnitt hinzufügen</span>
|
||||
</button>
|
||||
</li>
|
||||
{:else}
|
||||
<li class="section-heading-row">
|
||||
<input
|
||||
class="section-heading"
|
||||
type="text"
|
||||
bind:value={ing.section_heading}
|
||||
placeholder='Sektion, z. B. „Für den Teig"'
|
||||
aria-label="Sektionsüberschrift"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="section-remove"
|
||||
aria-label="Sektion entfernen"
|
||||
onclick={onremoveSection}
|
||||
>
|
||||
<X size={14} strokeWidth={2.5} />
|
||||
</button>
|
||||
</li>
|
||||
{/if}
|
||||
<li class="ing-row">
|
||||
<div class="move">
|
||||
<button
|
||||
class="move-btn"
|
||||
type="button"
|
||||
aria-label="Zutat nach oben"
|
||||
disabled={idx === 0}
|
||||
onclick={() => onmove(-1)}
|
||||
>
|
||||
<ChevronUp size={14} strokeWidth={2.5} />
|
||||
</button>
|
||||
<button
|
||||
class="move-btn"
|
||||
type="button"
|
||||
aria-label="Zutat nach unten"
|
||||
disabled={idx === total - 1}
|
||||
onclick={() => onmove(1)}
|
||||
>
|
||||
<ChevronDown size={14} strokeWidth={2.5} />
|
||||
</button>
|
||||
</div>
|
||||
<input class="qty" type="text" bind:value={ing.qty} placeholder="Menge" aria-label="Menge" />
|
||||
<input class="unit" type="text" bind:value={ing.unit} placeholder="Einheit" aria-label="Einheit" />
|
||||
<input class="name" type="text" bind:value={ing.name} placeholder="Zutat" aria-label="Zutat" />
|
||||
<input class="note" type="text" bind:value={ing.note} placeholder="Notiz" aria-label="Notiz" />
|
||||
<button class="del" type="button" aria-label="Zutat entfernen" onclick={onremove}>
|
||||
<Trash2 size={16} strokeWidth={2} />
|
||||
</button>
|
||||
</li>
|
||||
|
||||
<style>
|
||||
.ing-row {
|
||||
display: grid;
|
||||
grid-template-columns: 28px 70px 70px 1fr 1fr 40px;
|
||||
gap: 0.35rem;
|
||||
align-items: center;
|
||||
}
|
||||
.move {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
.move-btn {
|
||||
width: 28px;
|
||||
height: 20px;
|
||||
border: 1px solid #cfd9d1;
|
||||
background: white;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
color: #555;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
}
|
||||
.move-btn:hover:not(:disabled) {
|
||||
background: #f4f8f5;
|
||||
}
|
||||
.move-btn:disabled {
|
||||
opacity: 0.3;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.ing-row input {
|
||||
padding: 0.5rem 0.55rem;
|
||||
border: 1px solid #cfd9d1;
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
min-height: 38px;
|
||||
font-family: inherit;
|
||||
min-width: 0;
|
||||
}
|
||||
.del {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 1px solid #f1b4b4;
|
||||
background: white;
|
||||
color: #c53030;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.del:hover {
|
||||
background: #fdf3f3;
|
||||
}
|
||||
@media (max-width: 560px) {
|
||||
.ing-row {
|
||||
grid-template-columns: 28px 70px 1fr 40px;
|
||||
grid-template-areas:
|
||||
'move qty name del'
|
||||
'move unit unit del'
|
||||
'note note note note';
|
||||
}
|
||||
.ing-row .move {
|
||||
grid-area: move;
|
||||
}
|
||||
.ing-row .qty {
|
||||
grid-area: qty;
|
||||
}
|
||||
.ing-row .unit {
|
||||
grid-area: unit;
|
||||
}
|
||||
.ing-row .name {
|
||||
grid-area: name;
|
||||
}
|
||||
.ing-row .note {
|
||||
grid-area: note;
|
||||
}
|
||||
.ing-row .del {
|
||||
grid-area: del;
|
||||
}
|
||||
}
|
||||
.section-insert {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
list-style: none;
|
||||
margin: -0.2rem 0 0.1rem;
|
||||
opacity: 0;
|
||||
transition: opacity 0.15s;
|
||||
}
|
||||
/* Parent-UL liegt im RecipeEditor, daher :global(.ing-list). Ohne das
|
||||
scopt Svelte die Klasse und der Selector matcht zur Laufzeit nicht. */
|
||||
:global(.ing-list):hover .section-insert,
|
||||
.section-insert:focus-within {
|
||||
opacity: 1;
|
||||
}
|
||||
.add-section {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
padding: 0.2rem 0.55rem;
|
||||
border: 1px dashed #cfd9d1;
|
||||
background: white;
|
||||
color: #2b6a3d;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
font-size: 0.75rem;
|
||||
font-family: inherit;
|
||||
}
|
||||
.add-section:hover {
|
||||
background: #f4f8f5;
|
||||
}
|
||||
.section-heading-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 32px;
|
||||
gap: 0.35rem;
|
||||
list-style: none;
|
||||
margin-top: 0.4rem;
|
||||
}
|
||||
.section-heading {
|
||||
padding: 0.45rem 0.7rem;
|
||||
border: 1px solid #cfd9d1;
|
||||
border-radius: 8px;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
color: #2b6a3d;
|
||||
font-family: inherit;
|
||||
background: #f4f8f5;
|
||||
}
|
||||
.section-remove {
|
||||
width: 32px;
|
||||
height: 38px;
|
||||
border: 1px solid #cfd9d1;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
color: #666;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.section-remove:hover {
|
||||
background: #fdf3f3;
|
||||
border-color: #f1b4b4;
|
||||
color: #c53030;
|
||||
}
|
||||
</style>
|
||||
@@ -1,10 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import { Plus, Trash2, ChevronUp, ChevronDown, ImagePlus, ImageOff } from 'lucide-svelte';
|
||||
import { Plus } from 'lucide-svelte';
|
||||
import type { Recipe, Ingredient, Step } from '$lib/types';
|
||||
import { confirmAction } from '$lib/client/confirm.svelte';
|
||||
import { asyncFetch } from '$lib/client/api-fetch-wrapper';
|
||||
import { requireOnline } from '$lib/client/require-online';
|
||||
import ImageUploadBox from '$lib/components/ImageUploadBox.svelte';
|
||||
import IngredientRow from '$lib/components/IngredientRow.svelte';
|
||||
import StepList from '$lib/components/StepList.svelte';
|
||||
import type { DraftIng, DraftStep } from '$lib/components/recipe-editor-types';
|
||||
|
||||
type Props = {
|
||||
recipe: Recipe;
|
||||
@@ -27,67 +28,6 @@
|
||||
|
||||
let { recipe, saving = false, onsave, oncancel, onimagechange }: Props = $props();
|
||||
|
||||
let imagePath = $state<string | null>(untrack(() => recipe.image_path));
|
||||
let uploading = $state(false);
|
||||
let fileInput: HTMLInputElement | null = $state(null);
|
||||
|
||||
const imageSrc = $derived(
|
||||
imagePath === null
|
||||
? null
|
||||
: /^https?:\/\//i.test(imagePath)
|
||||
? imagePath
|
||||
: `/images/${imagePath}`
|
||||
);
|
||||
|
||||
async function onFileChosen(event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
input.value = '';
|
||||
if (!file) return;
|
||||
if (!requireOnline('Der Bild-Upload')) return;
|
||||
uploading = true;
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append('file', file);
|
||||
const res = await asyncFetch(
|
||||
`/api/recipes/${recipe.id}/image`,
|
||||
{ method: 'POST', body: fd },
|
||||
'Upload fehlgeschlagen'
|
||||
);
|
||||
if (!res) return;
|
||||
const body = await res.json();
|
||||
imagePath = body.image_path;
|
||||
onimagechange?.(imagePath);
|
||||
} finally {
|
||||
uploading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function removeImage() {
|
||||
if (imagePath === null) return;
|
||||
const ok = await confirmAction({
|
||||
title: 'Bild entfernen?',
|
||||
message: 'Das Rezept wird danach ohne Titelbild angezeigt.',
|
||||
confirmLabel: 'Entfernen',
|
||||
destructive: true
|
||||
});
|
||||
if (!ok) return;
|
||||
if (!requireOnline('Das Entfernen')) return;
|
||||
uploading = true;
|
||||
try {
|
||||
const res = await asyncFetch(
|
||||
`/api/recipes/${recipe.id}/image`,
|
||||
{ method: 'DELETE' },
|
||||
'Entfernen fehlgeschlagen'
|
||||
);
|
||||
if (!res) return;
|
||||
imagePath = null;
|
||||
onimagechange?.(null);
|
||||
} finally {
|
||||
uploading = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Form-lokaler Zustand: Initialwerte aus dem Prop snapshotten (untrack),
|
||||
// damit User-Edits nicht von prop-Updates ueberschrieben werden.
|
||||
let title = $state(untrack(() => recipe.title));
|
||||
@@ -97,21 +37,14 @@
|
||||
let cookMin = $state<number | ''>(untrack(() => recipe.cook_time_min ?? ''));
|
||||
let totalMin = $state<number | ''>(untrack(() => recipe.total_time_min ?? ''));
|
||||
|
||||
type DraftIng = {
|
||||
qty: string;
|
||||
unit: string;
|
||||
name: string;
|
||||
note: string;
|
||||
};
|
||||
type DraftStep = { text: string };
|
||||
|
||||
let ingredients = $state<DraftIng[]>(
|
||||
untrack(() =>
|
||||
recipe.ingredients.map((i) => ({
|
||||
qty: i.quantity !== null ? String(i.quantity).replace('.', ',') : '',
|
||||
unit: i.unit ?? '',
|
||||
name: i.name,
|
||||
note: i.note ?? ''
|
||||
note: i.note ?? '',
|
||||
section_heading: i.section_heading
|
||||
}))
|
||||
)
|
||||
);
|
||||
@@ -120,7 +53,7 @@
|
||||
);
|
||||
|
||||
function addIngredient() {
|
||||
ingredients = [...ingredients, { qty: '', unit: '', name: '', note: '' }];
|
||||
ingredients = [...ingredients, { qty: '', unit: '', name: '', note: '', section_heading: null }];
|
||||
}
|
||||
function removeIngredient(idx: number) {
|
||||
ingredients = ingredients.filter((_, i) => i !== idx);
|
||||
@@ -132,6 +65,16 @@
|
||||
[next[idx], next[target]] = [next[target], next[idx]];
|
||||
ingredients = next;
|
||||
}
|
||||
function addSection(idx: number) {
|
||||
const next = [...ingredients];
|
||||
next[idx] = { ...next[idx], section_heading: '' };
|
||||
ingredients = next;
|
||||
}
|
||||
function removeSection(idx: number) {
|
||||
const next = [...ingredients];
|
||||
next[idx] = { ...next[idx], section_heading: null };
|
||||
ingredients = next;
|
||||
}
|
||||
function addStep() {
|
||||
steps = [...steps, { text: '' }];
|
||||
}
|
||||
@@ -162,13 +105,15 @@
|
||||
if (qty !== null) rawParts.push(String(qty).replace('.', ','));
|
||||
if (unit) rawParts.push(unit);
|
||||
rawParts.push(name);
|
||||
const heading = i.section_heading === null ? null : (i.section_heading.trim() || null);
|
||||
return {
|
||||
position: idx + 1,
|
||||
quantity: qty,
|
||||
unit,
|
||||
name,
|
||||
note,
|
||||
raw_text: rawParts.join(' ')
|
||||
raw_text: rawParts.join(' '),
|
||||
section_heading: heading
|
||||
};
|
||||
});
|
||||
const cleanedSteps: Step[] = steps
|
||||
@@ -189,50 +134,13 @@
|
||||
</script>
|
||||
|
||||
<div class="editor">
|
||||
<section class="block image-block">
|
||||
<section class="block">
|
||||
<h2>Bild</h2>
|
||||
<div class="image-row">
|
||||
<div class="image-preview" class:empty={!imageSrc}>
|
||||
{#if imageSrc}
|
||||
<img src={imageSrc} alt="" />
|
||||
{:else}
|
||||
<span class="placeholder">Kein Bild</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="image-actions">
|
||||
<button
|
||||
class="btn"
|
||||
type="button"
|
||||
onclick={() => fileInput?.click()}
|
||||
disabled={uploading}
|
||||
>
|
||||
<ImagePlus size={16} strokeWidth={2} />
|
||||
<span>{imagePath ? 'Bild ersetzen' : 'Bild hochladen'}</span>
|
||||
</button>
|
||||
{#if imagePath}
|
||||
<button
|
||||
class="btn ghost"
|
||||
type="button"
|
||||
onclick={removeImage}
|
||||
disabled={uploading}
|
||||
>
|
||||
<ImageOff size={16} strokeWidth={2} />
|
||||
<span>Entfernen</span>
|
||||
</button>
|
||||
{/if}
|
||||
{#if uploading}
|
||||
<span class="upload-status">Lade …</span>
|
||||
{/if}
|
||||
</div>
|
||||
<input
|
||||
bind:this={fileInput}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp,image/gif,image/avif"
|
||||
class="file-input"
|
||||
onchange={onFileChosen}
|
||||
/>
|
||||
</div>
|
||||
<p class="image-hint">Max. 10 MB. JPG, PNG, WebP, GIF oder AVIF.</p>
|
||||
<ImageUploadBox
|
||||
recipeId={recipe.id!}
|
||||
imagePath={recipe.image_path}
|
||||
onchange={(p) => onimagechange?.(p)}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<div class="meta">
|
||||
@@ -273,35 +181,15 @@
|
||||
<h2>Zutaten</h2>
|
||||
<ul class="ing-list">
|
||||
{#each ingredients as ing, idx (idx)}
|
||||
<li class="ing-row">
|
||||
<div class="move">
|
||||
<button
|
||||
class="move-btn"
|
||||
type="button"
|
||||
aria-label="Zutat nach oben"
|
||||
disabled={idx === 0}
|
||||
onclick={() => moveIngredient(idx, -1)}
|
||||
>
|
||||
<ChevronUp size={14} strokeWidth={2.5} />
|
||||
</button>
|
||||
<button
|
||||
class="move-btn"
|
||||
type="button"
|
||||
aria-label="Zutat nach unten"
|
||||
disabled={idx === ingredients.length - 1}
|
||||
onclick={() => moveIngredient(idx, 1)}
|
||||
>
|
||||
<ChevronDown size={14} strokeWidth={2.5} />
|
||||
</button>
|
||||
</div>
|
||||
<input class="qty" type="text" bind:value={ing.qty} placeholder="Menge" aria-label="Menge" />
|
||||
<input class="unit" type="text" bind:value={ing.unit} placeholder="Einheit" aria-label="Einheit" />
|
||||
<input class="name" type="text" bind:value={ing.name} placeholder="Zutat" aria-label="Zutat" />
|
||||
<input class="note" type="text" bind:value={ing.note} placeholder="Notiz" aria-label="Notiz" />
|
||||
<button class="del" type="button" aria-label="Zutat entfernen" onclick={() => removeIngredient(idx)}>
|
||||
<Trash2 size={16} strokeWidth={2} />
|
||||
</button>
|
||||
</li>
|
||||
<IngredientRow
|
||||
{ing}
|
||||
{idx}
|
||||
total={ingredients.length}
|
||||
onmove={(dir) => moveIngredient(idx, dir)}
|
||||
onremove={() => removeIngredient(idx)}
|
||||
onaddSection={() => addSection(idx)}
|
||||
onremoveSection={() => removeSection(idx)}
|
||||
/>
|
||||
{/each}
|
||||
</ul>
|
||||
<button class="add" type="button" onclick={addIngredient}>
|
||||
@@ -312,25 +200,7 @@
|
||||
|
||||
<section class="block">
|
||||
<h2>Zubereitung</h2>
|
||||
<ol class="step-list">
|
||||
{#each steps as step, idx (idx)}
|
||||
<li class="step-row">
|
||||
<span class="num">{idx + 1}</span>
|
||||
<textarea
|
||||
bind:value={step.text}
|
||||
rows="3"
|
||||
placeholder="Schritt beschreiben …"
|
||||
></textarea>
|
||||
<button class="del" type="button" aria-label="Schritt entfernen" onclick={() => removeStep(idx)}>
|
||||
<Trash2 size={16} strokeWidth={2} />
|
||||
</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ol>
|
||||
<button class="add" type="button" onclick={addStep}>
|
||||
<Plus size={16} strokeWidth={2} />
|
||||
<span>Schritt hinzufügen</span>
|
||||
</button>
|
||||
<StepList {steps} onadd={addStep} onremove={removeStep} />
|
||||
</section>
|
||||
|
||||
<div class="foot">
|
||||
@@ -396,74 +266,12 @@
|
||||
border-radius: 12px;
|
||||
padding: 1rem;
|
||||
}
|
||||
.image-row {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.image-preview {
|
||||
width: 160px;
|
||||
aspect-ratio: 16 / 10;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
background: #eef3ef;
|
||||
border: 1px solid #e4eae7;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.image-preview img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
.image-preview.empty {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
color: #999;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.image-preview .placeholder {
|
||||
padding: 0 0.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
.image-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
.image-actions .btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
padding: 0.55rem 0.85rem;
|
||||
min-height: 40px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.upload-status {
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.file-input {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
.image-hint {
|
||||
margin: 0.6rem 0 0;
|
||||
color: #888;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.block h2 {
|
||||
font-size: 1.05rem;
|
||||
margin: 0 0 0.75rem;
|
||||
color: #2b6a3d;
|
||||
}
|
||||
.ing-list,
|
||||
.step-list {
|
||||
.ing-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0 0 0.6rem;
|
||||
@@ -471,88 +279,6 @@
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.ing-row {
|
||||
display: grid;
|
||||
grid-template-columns: 28px 70px 70px 1fr 1fr 40px;
|
||||
gap: 0.35rem;
|
||||
align-items: center;
|
||||
}
|
||||
.move {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
.move-btn {
|
||||
width: 28px;
|
||||
height: 20px;
|
||||
border: 1px solid #cfd9d1;
|
||||
background: white;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
color: #555;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
}
|
||||
.move-btn:hover:not(:disabled) {
|
||||
background: #f4f8f5;
|
||||
}
|
||||
.move-btn:disabled {
|
||||
opacity: 0.3;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.ing-row input {
|
||||
padding: 0.5rem 0.55rem;
|
||||
border: 1px solid #cfd9d1;
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
min-height: 38px;
|
||||
font-family: inherit;
|
||||
min-width: 0;
|
||||
}
|
||||
.step-row {
|
||||
display: grid;
|
||||
grid-template-columns: 32px 1fr 40px;
|
||||
gap: 0.5rem;
|
||||
align-items: start;
|
||||
}
|
||||
.num {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: #2b6a3d;
|
||||
color: white;
|
||||
border-radius: 50%;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
.step-row textarea {
|
||||
padding: 0.55rem 0.7rem;
|
||||
border: 1px solid #cfd9d1;
|
||||
border-radius: 8px;
|
||||
font-size: 0.95rem;
|
||||
font-family: inherit;
|
||||
resize: vertical;
|
||||
min-height: 70px;
|
||||
}
|
||||
.del {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 1px solid #f1b4b4;
|
||||
background: white;
|
||||
color: #c53030;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.del:hover {
|
||||
background: #fdf3f3;
|
||||
}
|
||||
.add {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -598,31 +324,4 @@
|
||||
opacity: 0.6;
|
||||
cursor: progress;
|
||||
}
|
||||
@media (max-width: 560px) {
|
||||
.ing-row {
|
||||
grid-template-columns: 28px 70px 1fr 40px;
|
||||
grid-template-areas:
|
||||
'move qty name del'
|
||||
'move unit unit del'
|
||||
'note note note note';
|
||||
}
|
||||
.ing-row .move {
|
||||
grid-area: move;
|
||||
}
|
||||
.ing-row .qty {
|
||||
grid-area: qty;
|
||||
}
|
||||
.ing-row .unit {
|
||||
grid-area: unit;
|
||||
}
|
||||
.ing-row .name {
|
||||
grid-area: name;
|
||||
}
|
||||
.ing-row .note {
|
||||
grid-area: note;
|
||||
}
|
||||
.ing-row .del {
|
||||
grid-area: del;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { scaleIngredients } from '$lib/recipes/scaler';
|
||||
import type { Recipe } from '$lib/types';
|
||||
import TimeDisplay from '$lib/components/TimeDisplay.svelte';
|
||||
|
||||
type Props = {
|
||||
recipe: Recipe;
|
||||
@@ -41,15 +42,6 @@
|
||||
if (Number.isInteger(q)) return String(q);
|
||||
return q.toLocaleString('de-DE', { maximumFractionDigits: 2 });
|
||||
}
|
||||
|
||||
function timeSummary(): string {
|
||||
const parts: string[] = [];
|
||||
if (recipe.prep_time_min) parts.push(`Vorb. ${recipe.prep_time_min} min`);
|
||||
if (recipe.cook_time_min) parts.push(`Kochen ${recipe.cook_time_min} min`);
|
||||
if (!recipe.prep_time_min && !recipe.cook_time_min && recipe.total_time_min)
|
||||
parts.push(`Gesamt ${recipe.total_time_min} min`);
|
||||
return parts.join(' · ');
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if banner}
|
||||
@@ -79,9 +71,11 @@
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
{#if timeSummary()}
|
||||
<p class="times">{timeSummary()}</p>
|
||||
{/if}
|
||||
<TimeDisplay
|
||||
prepTimeMin={recipe.prep_time_min}
|
||||
cookTimeMin={recipe.cook_time_min}
|
||||
totalTimeMin={recipe.total_time_min}
|
||||
/>
|
||||
{#if recipe.source_url}
|
||||
<p class="src">
|
||||
Quelle: <a href={recipe.source_url} target="_blank" rel="noopener">{recipe.source_domain}</a>
|
||||
@@ -133,6 +127,9 @@
|
||||
</div>
|
||||
<ul class="ing-list">
|
||||
{#each scaled as ing, i (i)}
|
||||
{#if ing.section_heading && ing.section_heading.trim()}
|
||||
<li class="section-heading">{ing.section_heading}</li>
|
||||
{/if}
|
||||
<li>
|
||||
{#if ing.quantity !== null || ing.unit}
|
||||
<span class="qty">
|
||||
@@ -212,11 +209,6 @@
|
||||
font-size: 0.8rem;
|
||||
color: #888;
|
||||
}
|
||||
.times {
|
||||
margin: 0 0 0.25rem;
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.src {
|
||||
margin: 0;
|
||||
font-size: 0.85rem;
|
||||
@@ -292,6 +284,19 @@
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
.ing-list .section-heading {
|
||||
list-style: none;
|
||||
font-weight: 600;
|
||||
color: #2b6a3d;
|
||||
font-size: 1rem;
|
||||
margin-top: 0.9rem;
|
||||
margin-bottom: 0.2rem;
|
||||
padding: 0.15rem 0;
|
||||
border-bottom: 1px solid #e4eae7;
|
||||
}
|
||||
.ing-list .section-heading:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
.ing-list li {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
|
||||
101
src/lib/components/StepList.svelte
Normal file
101
src/lib/components/StepList.svelte
Normal file
@@ -0,0 +1,101 @@
|
||||
<script lang="ts">
|
||||
import { Plus, Trash2 } from 'lucide-svelte';
|
||||
import type { DraftStep } from './recipe-editor-types';
|
||||
|
||||
type Props = {
|
||||
steps: DraftStep[];
|
||||
onadd: () => void;
|
||||
onremove: (idx: number) => void;
|
||||
};
|
||||
|
||||
let { steps, onadd, onremove }: Props = $props();
|
||||
</script>
|
||||
|
||||
<ol class="step-list">
|
||||
{#each steps as step, idx (idx)}
|
||||
<li class="step-row">
|
||||
<span class="num">{idx + 1}</span>
|
||||
<textarea
|
||||
bind:value={step.text}
|
||||
rows="3"
|
||||
placeholder="Schritt beschreiben …"
|
||||
></textarea>
|
||||
<button class="del" type="button" aria-label="Schritt entfernen" onclick={() => onremove(idx)}>
|
||||
<Trash2 size={16} strokeWidth={2} />
|
||||
</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ol>
|
||||
<button class="add" type="button" onclick={onadd}>
|
||||
<Plus size={16} strokeWidth={2} />
|
||||
<span>Schritt hinzufügen</span>
|
||||
</button>
|
||||
|
||||
<style>
|
||||
.step-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0 0 0.6rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.step-row {
|
||||
display: grid;
|
||||
grid-template-columns: 32px 1fr 40px;
|
||||
gap: 0.5rem;
|
||||
align-items: start;
|
||||
}
|
||||
.num {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: #2b6a3d;
|
||||
color: white;
|
||||
border-radius: 50%;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
.step-row textarea {
|
||||
padding: 0.55rem 0.7rem;
|
||||
border: 1px solid #cfd9d1;
|
||||
border-radius: 8px;
|
||||
font-size: 0.95rem;
|
||||
font-family: inherit;
|
||||
resize: vertical;
|
||||
min-height: 70px;
|
||||
}
|
||||
.del {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 1px solid #f1b4b4;
|
||||
background: white;
|
||||
color: #c53030;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.del:hover {
|
||||
background: #fdf3f3;
|
||||
}
|
||||
.add {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
padding: 0.55rem 0.9rem;
|
||||
border: 1px dashed #cfd9d1;
|
||||
background: white;
|
||||
color: #2b6a3d;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
font-family: inherit;
|
||||
}
|
||||
.add:hover {
|
||||
background: #f4f8f5;
|
||||
}
|
||||
</style>
|
||||
30
src/lib/components/TimeDisplay.svelte
Normal file
30
src/lib/components/TimeDisplay.svelte
Normal file
@@ -0,0 +1,30 @@
|
||||
<script lang="ts">
|
||||
type Props = {
|
||||
prepTimeMin: number | null;
|
||||
cookTimeMin: number | null;
|
||||
totalTimeMin: number | null;
|
||||
};
|
||||
|
||||
let { prepTimeMin, cookTimeMin, totalTimeMin }: Props = $props();
|
||||
|
||||
const summary = $derived.by(() => {
|
||||
const parts: string[] = [];
|
||||
if (prepTimeMin) parts.push(`Vorb. ${prepTimeMin} min`);
|
||||
if (cookTimeMin) parts.push(`Kochen ${cookTimeMin} min`);
|
||||
if (!prepTimeMin && !cookTimeMin && totalTimeMin)
|
||||
parts.push(`Gesamt ${totalTimeMin} min`);
|
||||
return parts.join(' · ');
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if summary}
|
||||
<p class="times">{summary}</p>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.times {
|
||||
margin: 0 0 0.25rem;
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
</style>
|
||||
9
src/lib/components/recipe-editor-types.ts
Normal file
9
src/lib/components/recipe-editor-types.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export type DraftIng = {
|
||||
qty: string;
|
||||
unit: string;
|
||||
name: string;
|
||||
note: string;
|
||||
section_heading: string | null;
|
||||
};
|
||||
|
||||
export type DraftStep = { text: string };
|
||||
7
src/lib/server/db/migrations/012_ingredient_section.sql
Normal file
7
src/lib/server/db/migrations/012_ingredient_section.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
-- Nullable-Spalte fuer optionale Sektionsueberschriften bei Zutaten. User
|
||||
-- soll im Editor gruppieren koennen ("Fuer den Teig", "Fuer die Fuellung").
|
||||
-- Rendering-Regel: Ist section_heading gesetzt (nicht NULL, nicht leer),
|
||||
-- startet an dieser Zeile eine neue Sektion mit diesem Titel; alle folgenden
|
||||
-- Zutaten gehoeren dazu, bis die naechste Zeile wieder eine Ueberschrift hat.
|
||||
-- Ordnung bleibt die bestehende position-Spalte.
|
||||
ALTER TABLE ingredient ADD COLUMN section_heading TEXT;
|
||||
@@ -105,16 +105,16 @@ export function parseIngredient(raw: string, position = 0): Ingredient {
|
||||
if (tail.length > 0) {
|
||||
const quantity = clampQuantity(UNICODE_FRACTION_MAP[firstChar]);
|
||||
const { unit, name } = splitUnitAndName(tail);
|
||||
return { position, quantity, unit, name, note, raw_text: rawText };
|
||||
return { position, quantity, unit, name, note, raw_text: rawText, section_heading: null };
|
||||
}
|
||||
}
|
||||
|
||||
const qtyPattern = /^((?:\d+[.,]?\d*(?:\s*[-–]\s*\d+[.,]?\d*)?)|(?:\d+\/\d+))\s+(.+)$/;
|
||||
const qtyMatch = qtyPattern.exec(working);
|
||||
if (!qtyMatch) {
|
||||
return { position, quantity: null, unit: null, name: working, note, raw_text: rawText };
|
||||
return { position, quantity: null, unit: null, name: working, note, raw_text: rawText, section_heading: null };
|
||||
}
|
||||
const quantity = clampQuantity(parseQuantity(qtyMatch[1]));
|
||||
const { unit, name } = splitUnitAndName(qtyMatch[2]);
|
||||
return { position, quantity, unit, name, note, raw_text: rawText };
|
||||
return { position, quantity, unit, name, note, raw_text: rawText, section_heading: null };
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ export function insertRecipe(db: Database.Database, recipe: Recipe): number {
|
||||
const id = Number(info.lastInsertRowid);
|
||||
|
||||
const insIng = db.prepare(
|
||||
`INSERT INTO ingredient(recipe_id, position, quantity, unit, name, note, raw_text)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`
|
||||
`INSERT INTO ingredient(recipe_id, position, quantity, unit, name, note, raw_text, section_heading)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
);
|
||||
for (const ing of recipe.ingredients) {
|
||||
insIng.run(id, ing.position, ing.quantity, ing.unit, ing.name, ing.note, ing.raw_text);
|
||||
insIng.run(id, ing.position, ing.quantity, ing.unit, ing.name, ing.note, ing.raw_text, ing.section_heading);
|
||||
}
|
||||
|
||||
const insStep = db.prepare(
|
||||
@@ -104,7 +104,7 @@ export function getRecipeById(db: Database.Database, id: number): Recipe | null
|
||||
|
||||
const ingredients = db
|
||||
.prepare(
|
||||
`SELECT position, quantity, unit, name, note, raw_text
|
||||
`SELECT position, quantity, unit, name, note, raw_text, section_heading
|
||||
FROM ingredient WHERE recipe_id = ? ORDER BY position`
|
||||
)
|
||||
.all(id) as Ingredient[];
|
||||
@@ -215,11 +215,11 @@ export function replaceIngredients(
|
||||
const tx = db.transaction(() => {
|
||||
db.prepare('DELETE FROM ingredient WHERE recipe_id = ?').run(recipeId);
|
||||
const ins = db.prepare(
|
||||
`INSERT INTO ingredient(recipe_id, position, quantity, unit, name, note, raw_text)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`
|
||||
`INSERT INTO ingredient(recipe_id, position, quantity, unit, name, note, raw_text, section_heading)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
);
|
||||
for (const ing of ingredients) {
|
||||
ins.run(recipeId, ing.position, ing.quantity, ing.unit, ing.name, ing.note, ing.raw_text);
|
||||
ins.run(recipeId, ing.position, ing.quantity, ing.unit, ing.name, ing.note, ing.raw_text, ing.section_heading);
|
||||
}
|
||||
refreshFts(db, recipeId);
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ export type Ingredient = {
|
||||
name: string;
|
||||
note: string | null;
|
||||
raw_text: string;
|
||||
section_heading: string | null;
|
||||
};
|
||||
|
||||
export type Step = {
|
||||
|
||||
@@ -24,7 +24,8 @@ const IngredientSchema = z.object({
|
||||
unit: z.string().max(30).nullable(),
|
||||
name: z.string().min(1).max(200),
|
||||
note: z.string().max(300).nullable(),
|
||||
raw_text: z.string().max(500)
|
||||
raw_text: z.string().max(500),
|
||||
section_heading: z.string().max(200).nullable()
|
||||
});
|
||||
|
||||
const StepSchema = z.object({
|
||||
|
||||
219
tests/e2e/remote/ingredient-sections.spec.ts
Normal file
219
tests/e2e/remote/ingredient-sections.spec.ts
Normal file
@@ -0,0 +1,219 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { setActiveProfile, HENDRIK_ID } from './fixtures/profile';
|
||||
|
||||
// Helper: idempotent recipe delete.
|
||||
async function deleteRecipe(
|
||||
request: Parameters<Parameters<typeof test>[1]>[0]['request'],
|
||||
id: number
|
||||
): Promise<void> {
|
||||
await request.delete(`/api/recipes/${id}`);
|
||||
}
|
||||
|
||||
// Shared ingredient payload builder — fills all required Zod fields.
|
||||
function makeIngredient(
|
||||
position: number,
|
||||
name: string,
|
||||
section_heading: string | null,
|
||||
overrides: Partial<{
|
||||
quantity: number | null;
|
||||
unit: string | null;
|
||||
note: string | null;
|
||||
raw_text: string;
|
||||
}> = {}
|
||||
) {
|
||||
return {
|
||||
position,
|
||||
quantity: overrides.quantity ?? null,
|
||||
unit: overrides.unit ?? null,
|
||||
name,
|
||||
note: overrides.note ?? null,
|
||||
raw_text: overrides.raw_text ?? name,
|
||||
section_heading
|
||||
};
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Per-test cleanup scaffolding — single variable, reset in beforeEach.
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
let createdId: number | null = null;
|
||||
|
||||
test.beforeEach(() => {
|
||||
createdId = null;
|
||||
});
|
||||
|
||||
test.afterEach(async ({ request }) => {
|
||||
if (createdId !== null) {
|
||||
await deleteRecipe(request, createdId);
|
||||
createdId = null;
|
||||
}
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Test 1 — pure API roundtrip (no browser needed)
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
test('API: section_heading persistiert ueber PATCH + GET', async ({ request }) => {
|
||||
// 1. Create blank recipe.
|
||||
const createRes = await request.post('/api/recipes/blank');
|
||||
expect(createRes.status()).toBe(200);
|
||||
const { id } = (await createRes.json()) as { id: number };
|
||||
createdId = id;
|
||||
|
||||
// 2. PATCH with 3 ingredients carrying section_heading values.
|
||||
const patchRes = await request.patch(`/api/recipes/${id}`, {
|
||||
data: {
|
||||
ingredients: [
|
||||
makeIngredient(1, 'Mehl', 'Fuer den Teig', { quantity: 200, unit: 'g', raw_text: '200 g Mehl' }),
|
||||
makeIngredient(2, 'Zucker', null, { quantity: 100, unit: 'g', raw_text: '100 g Zucker' }),
|
||||
makeIngredient(3, 'Beeren', 'Fuer die Fuellung', { quantity: 150, unit: 'g', raw_text: '150 g Beeren' })
|
||||
]
|
||||
}
|
||||
});
|
||||
expect(patchRes.status()).toBe(200);
|
||||
|
||||
// 3. GET and assert persisted values.
|
||||
const getRes = await request.get(`/api/recipes/${id}`);
|
||||
expect(getRes.status()).toBe(200);
|
||||
const body = (await getRes.json()) as {
|
||||
recipe: { ingredients: Array<{ name: string; section_heading: string | null }> };
|
||||
};
|
||||
const ings = body.recipe.ingredients;
|
||||
|
||||
const mehl = ings.find((i) => i.name === 'Mehl');
|
||||
const zucker = ings.find((i) => i.name === 'Zucker');
|
||||
const beeren = ings.find((i) => i.name === 'Beeren');
|
||||
|
||||
expect(mehl?.section_heading).toBe('Fuer den Teig');
|
||||
expect(zucker?.section_heading).toBeNull();
|
||||
expect(beeren?.section_heading).toBe('Fuer die Fuellung');
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Test 2 — UI edit flow: add section, save, assert view renders heading
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
test('Editor: Abschnitt via Inline-Button anlegen, View rendert Ueberschrift', async ({
|
||||
page,
|
||||
request
|
||||
}) => {
|
||||
// 1. Create blank recipe via API.
|
||||
const createRes = await request.post('/api/recipes/blank');
|
||||
expect(createRes.status()).toBe(200);
|
||||
const { id } = (await createRes.json()) as { id: number };
|
||||
createdId = id;
|
||||
|
||||
// 2. Open recipe in edit mode.
|
||||
await setActiveProfile(page, HENDRIK_ID);
|
||||
await page.goto(`/recipes/${id}?edit=1`);
|
||||
|
||||
// 3. Add two ingredient rows.
|
||||
const addIngBtn = page.getByRole('button', { name: /Zutat hinzufügen/i });
|
||||
await addIngBtn.click();
|
||||
await addIngBtn.click();
|
||||
|
||||
// Fill the two ingredient rows by aria-label "Zutat" inputs.
|
||||
const nameInputs = page.locator('.ing-list .ing-row input[aria-label="Zutat"]');
|
||||
await nameInputs.nth(0).fill('Mehl');
|
||||
await nameInputs.nth(1).fill('Zucker');
|
||||
|
||||
// 4. Click "Abschnitt hinzufügen" above the first row.
|
||||
// The button is inside .section-insert which is opacity:0 until hover/focus.
|
||||
// Hover the ing-list to trigger visibility, then click.
|
||||
await page.hover('.ing-list');
|
||||
await page.locator('.ing-list .add-section').first().click();
|
||||
|
||||
// 5. Type heading text into the section-heading input that appeared.
|
||||
const headingInput = page.locator('.ing-list input[aria-label="Sektionsüberschrift"]').first();
|
||||
await headingInput.fill('Fuer den Teig');
|
||||
|
||||
// 6. Save — exact match to avoid colliding with "Kommentar speichern".
|
||||
await page.getByRole('button', { name: 'Speichern', exact: true }).click();
|
||||
|
||||
// After save, editMode becomes false — page switches to view mode.
|
||||
// Wait for the section-heading element to confirm view mode is active.
|
||||
await expect(page.locator('.ing-list .section-heading').first()).toBeVisible({ timeout: 8000 });
|
||||
|
||||
// 7. Assert heading text is rendered.
|
||||
await expect(page.locator('.ing-list .section-heading').first()).toHaveText('Fuer den Teig');
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Test 3 — UI: remove an existing section heading, save, confirm it's gone
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
test('Editor: Sektion entfernen speichert ohne Ueberschrift', async ({ page, request }) => {
|
||||
// 1. Create blank recipe and pre-populate via API.
|
||||
const createRes = await request.post('/api/recipes/blank');
|
||||
expect(createRes.status()).toBe(200);
|
||||
const { id } = (await createRes.json()) as { id: number };
|
||||
createdId = id;
|
||||
|
||||
await request.patch(`/api/recipes/${id}`, {
|
||||
data: {
|
||||
ingredients: [makeIngredient(1, 'Butter', 'Teig', { raw_text: 'Butter' })]
|
||||
}
|
||||
});
|
||||
|
||||
// 2. Open editor.
|
||||
await setActiveProfile(page, HENDRIK_ID);
|
||||
await page.goto(`/recipes/${id}?edit=1`);
|
||||
|
||||
// The section-heading-row should be visible since heading = 'Teig'.
|
||||
const removeBtn = page
|
||||
.locator('.ing-list')
|
||||
.getByRole('button', { name: 'Sektion entfernen' });
|
||||
await expect(removeBtn).toBeVisible({ timeout: 6000 });
|
||||
|
||||
// 3. Click the section-remove X button.
|
||||
await removeBtn.click();
|
||||
|
||||
// 4. Save — exact match to avoid colliding with "Kommentar speichern".
|
||||
await page.getByRole('button', { name: 'Speichern', exact: true }).click();
|
||||
|
||||
// Wait for view mode (editMode = false makes RecipeEditor unmount).
|
||||
// The .section-heading-row is part of the editor; in view mode we check
|
||||
// the view's .ing-list for absence of .section-heading items.
|
||||
await expect(page.locator('.ing-list .section-heading')).toHaveCount(0, { timeout: 8000 });
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Test 4 — empty heading trims to null on save
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
test('Editor: leeres Heading wird beim Speichern zu null', async ({ page, request }) => {
|
||||
// 1. Create blank recipe.
|
||||
const createRes = await request.post('/api/recipes/blank');
|
||||
expect(createRes.status()).toBe(200);
|
||||
const { id } = (await createRes.json()) as { id: number };
|
||||
createdId = id;
|
||||
|
||||
// 2. Open editor, add one ingredient, open section input and leave it empty.
|
||||
await setActiveProfile(page, HENDRIK_ID);
|
||||
await page.goto(`/recipes/${id}?edit=1`);
|
||||
|
||||
await page.getByRole('button', { name: /Zutat hinzufügen/i }).click();
|
||||
await page.locator('.ing-list .ing-row input[aria-label="Zutat"]').first().fill('Eier');
|
||||
|
||||
// Trigger add-section visibility and click.
|
||||
await page.hover('.ing-list');
|
||||
await page.locator('.ing-list .add-section').first().click();
|
||||
|
||||
// Leave the heading input empty (do not type anything).
|
||||
// The save() function trims '' → null.
|
||||
|
||||
// 3. Save — exact match to avoid colliding with "Kommentar speichern".
|
||||
await page.getByRole('button', { name: 'Speichern', exact: true }).click();
|
||||
|
||||
// Wait until view mode is active (editor gone).
|
||||
await expect(page.locator('.ing-list .section-heading')).toHaveCount(0, { timeout: 8000 });
|
||||
|
||||
// 4. Confirm via API that section_heading is null.
|
||||
const getRes = await request.get(`/api/recipes/${id}`);
|
||||
expect(getRes.status()).toBe(200);
|
||||
const body = (await getRes.json()) as {
|
||||
recipe: { ingredients: Array<{ name: string; section_heading: string | null }> };
|
||||
};
|
||||
const eier = body.recipe.ingredients.find((i) => i.name === 'Eier');
|
||||
expect(eier?.section_heading).toBeNull();
|
||||
});
|
||||
@@ -70,7 +70,8 @@ describe('recipe repository', () => {
|
||||
unit: 'g',
|
||||
name: 'Pancetta',
|
||||
note: null,
|
||||
raw_text: '200 g Pancetta'
|
||||
raw_text: '200 g Pancetta',
|
||||
section_heading: null
|
||||
}
|
||||
],
|
||||
tags: ['Italienisch']
|
||||
@@ -118,13 +119,13 @@ describe('recipe repository', () => {
|
||||
baseRecipe({
|
||||
title: 'Pasta',
|
||||
ingredients: [
|
||||
{ position: 1, quantity: 200, unit: 'g', name: 'Pancetta', note: null, raw_text: '200 g Pancetta' }
|
||||
{ position: 1, quantity: 200, unit: 'g', name: 'Pancetta', note: null, raw_text: '200 g Pancetta', section_heading: null }
|
||||
]
|
||||
})
|
||||
);
|
||||
replaceIngredients(db, id, [
|
||||
{ position: 1, quantity: 500, unit: 'g', name: 'Nudeln', note: null, raw_text: '500 g Nudeln' },
|
||||
{ position: 2, quantity: 2, unit: null, name: 'Eier', note: null, raw_text: '2 Eier' }
|
||||
{ position: 1, quantity: 500, unit: 'g', name: 'Nudeln', note: null, raw_text: '500 g Nudeln', section_heading: null },
|
||||
{ position: 2, quantity: 2, unit: null, name: 'Eier', note: null, raw_text: '2 Eier', section_heading: null }
|
||||
]);
|
||||
const loaded = getRecipeById(db, id);
|
||||
expect(loaded?.ingredients.length).toBe(2);
|
||||
@@ -154,4 +155,31 @@ describe('recipe repository', () => {
|
||||
const loaded = getRecipeById(db, id);
|
||||
expect(loaded?.steps.map((s) => s.text)).toEqual(['Erst', 'Dann']);
|
||||
});
|
||||
|
||||
it('persistiert section_heading und gibt es beim Laden zurueck', () => {
|
||||
const db = openInMemoryForTest();
|
||||
const recipe = baseRecipe({
|
||||
title: 'Torte',
|
||||
ingredients: [
|
||||
{ position: 1, quantity: 200, unit: 'g', name: 'Mehl', note: null, raw_text: '200 g Mehl', section_heading: 'Für den Teig' },
|
||||
{ position: 2, quantity: 100, unit: 'g', name: 'Zucker', note: null, raw_text: '100 g Zucker', section_heading: null },
|
||||
{ position: 3, quantity: 300, unit: 'g', name: 'Beeren', note: null, raw_text: '300 g Beeren', section_heading: 'Für die Füllung' }
|
||||
]
|
||||
});
|
||||
const id = insertRecipe(db, recipe);
|
||||
const loaded = getRecipeById(db, id);
|
||||
expect(loaded!.ingredients[0].section_heading).toBe('Für den Teig');
|
||||
expect(loaded!.ingredients[1].section_heading).toBeNull();
|
||||
expect(loaded!.ingredients[2].section_heading).toBe('Für die Füllung');
|
||||
});
|
||||
|
||||
it('replaceIngredients persistiert section_heading', () => {
|
||||
const db = openInMemoryForTest();
|
||||
const id = insertRecipe(db, baseRecipe({ title: 'X' }));
|
||||
replaceIngredients(db, id, [
|
||||
{ position: 1, quantity: null, unit: null, name: 'A', note: null, raw_text: 'A', section_heading: 'Kopf' }
|
||||
]);
|
||||
const loaded = getRecipeById(db, id);
|
||||
expect(loaded!.ingredients[0].section_heading).toBe('Kopf');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,7 +48,7 @@ describe('searchLocal', () => {
|
||||
recipe({
|
||||
title: 'Pasta',
|
||||
ingredients: [
|
||||
{ position: 1, quantity: 200, unit: 'g', name: 'Pancetta', note: null, raw_text: '' }
|
||||
{ position: 1, quantity: 200, unit: 'g', name: 'Pancetta', note: null, raw_text: '', section_heading: null }
|
||||
]
|
||||
})
|
||||
);
|
||||
|
||||
@@ -8,7 +8,8 @@ const mk = (q: number | null, unit: string | null, name: string): Ingredient =>
|
||||
unit,
|
||||
name,
|
||||
note: null,
|
||||
raw_text: ''
|
||||
raw_text: '',
|
||||
section_heading: null
|
||||
});
|
||||
|
||||
describe('roundQuantity', () => {
|
||||
@@ -40,4 +41,15 @@ describe('scaleIngredients', () => {
|
||||
const scaled = scaleIngredients([mk(100, 'g', 'Butter')], 1 / 3);
|
||||
expect(scaled[0].quantity).toBe(33);
|
||||
});
|
||||
|
||||
it('preserves section_heading through scaling', () => {
|
||||
const input: Ingredient[] = [
|
||||
{ position: 1, quantity: 200, unit: 'g', name: 'Mehl', note: null, raw_text: '200 g Mehl', section_heading: 'Teig' },
|
||||
{ position: 2, quantity: null, unit: null, name: 'Ei', note: null, raw_text: 'Ei', section_heading: null }
|
||||
];
|
||||
const scaled = scaleIngredients(input, 2);
|
||||
expect(scaled[0].section_heading).toBe('Teig');
|
||||
expect(scaled[1].section_heading).toBeNull();
|
||||
expect(scaled[0].quantity).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user