feat: export + detail receptů
feat: losování jídel
This commit is contained in:
1 parent
35cbc5a9ca
commit
caffb6d8b4
23 files changed
+2674
-43
No files matched your search
@@ -5,6 +5,7 @@ import { RECIPE_FLAVOR_NAMES } from "../enums";
|
||||
import { deriveRecipe, formatCalories, formatPrice, formatWeight, parseIntInput } from "../Utils";
|
||||
import SourceInput from "./SourceInput";
|
||||
import RecipeCategoryInput from "./RecipeCategoryInput";
|
||||
import RecipeNote from "./RecipeNote";
|
||||
import RecipeIngredientsEditor, {
|
||||
DraftIngredient, emptyIngredient, toDraftIngredient, toIngredient,
|
||||
} from "./RecipeIngredientsEditor";
|
||||
@@ -21,6 +22,9 @@ type Props = {
|
||||
onCancel: () => void,
|
||||
};
|
||||
|
||||
/** Ukázka Markdownu, dokud je postup prázdný. */
|
||||
const NOTE_PLACEHOLDER = 'Jak se jídlo připravuje…\n\n## Příprava\n1. Cibuli nakrájejte nadrobno\n2. **Orestujte** dozlatova';
|
||||
|
||||
/** Naplní formulář z receptu, nebo ho nechá prázdný pro nový. */
|
||||
const createForm = (template?: MealTemplate, meal?: Props['meal']) => ({
|
||||
name: meal?.name ?? template?.name ?? '',
|
||||
@@ -42,6 +46,7 @@ const MealTemplateForm = ({ template, meal, onSaved, onCancel }: Readonly<Props>
|
||||
template?.ingredients?.length ? template.ingredients.map(toDraftIngredient) : [emptyIngredient()]);
|
||||
const [error, setError] = useState<string | undefined>();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [notePreview, setNotePreview] = useState(false);
|
||||
const flavorId = useId();
|
||||
|
||||
const update = (changes: Partial<ReturnType<typeof createForm>>) =>
|
||||
@@ -178,14 +183,43 @@ const MealTemplateForm = ({ template, meal, onSaved, onCancel }: Readonly<Props>
|
||||
</fieldset>
|
||||
|
||||
<Form.Group className="mb-3">
|
||||
<Form.Label>Postup</Form.Label>
|
||||
<Form.Control
|
||||
as="textarea"
|
||||
rows={6}
|
||||
value={form.note}
|
||||
placeholder="Jak se jídlo připravuje…"
|
||||
onChange={event => update({ note: event.target.value })}
|
||||
/>
|
||||
<div className="recipe-note-label">
|
||||
<Form.Label>Postup</Form.Label>
|
||||
<ToggleButtonGroup
|
||||
type="radio"
|
||||
name={`${flavorId}-note`}
|
||||
size="sm"
|
||||
value={notePreview ? 'preview' : 'edit'}
|
||||
onChange={(value: string) => setNotePreview(value === 'preview')}
|
||||
>
|
||||
<ToggleButton id={`${flavorId}-note-edit`} value="edit" variant="outline-secondary">
|
||||
Psát
|
||||
</ToggleButton>
|
||||
<ToggleButton
|
||||
id={`${flavorId}-note-preview`}
|
||||
value="preview"
|
||||
variant="outline-secondary"
|
||||
disabled={!form.note.trim()}
|
||||
>
|
||||
Náhled
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</div>
|
||||
{notePreview && form.note.trim()
|
||||
? <div className="recipe-note-preview"><RecipeNote note={form.note} /></div>
|
||||
: (
|
||||
<Form.Control
|
||||
as="textarea"
|
||||
rows={8}
|
||||
value={form.note}
|
||||
placeholder={NOTE_PLACEHOLDER}
|
||||
onChange={event => update({ note: event.target.value })}
|
||||
/>
|
||||
)}
|
||||
<Form.Text>
|
||||
Markdown: <code>## nadpis</code>, <code>- odrážka</code>, <code>1. krok</code>,
|
||||
{' '}<code>**tučně**</code>, <code>*kurzíva*</code>
|
||||
</Form.Text>
|
||||
</Form.Group>
|
||||
|
||||
<div className="workout-form-footer">
|
||||
|
||||
Reference in new issue
Block a user