feat: předělání historie a profilu
This commit is contained in:
1 parent
9e72f431a1
commit
8fa7f601f2
97 files changed
+7502
-1034
No files matched your search
@@ -1,10 +1,8 @@
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faPenToSquare, faTrash } from "@fortawesome/free-solid-svg-icons";
|
||||
import { MealTemplate, MealTemplateKind } from "../../../types";
|
||||
import { MealTemplate } from "../../../types";
|
||||
import { MEAL_TYPE_ICONS, MEAL_TYPE_NAMES } from "../enums";
|
||||
import {
|
||||
deriveAmounts, deriveRecipe, formatCalories, formatPrice, formatWeight, getIngredientCalories,
|
||||
} from "../Utils";
|
||||
import { deriveRecipe, formatCalories, formatPrice, formatWeight, getIngredientCalories } from "../Utils";
|
||||
|
||||
type Props = {
|
||||
template: MealTemplate,
|
||||
@@ -14,18 +12,11 @@ type Props = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Karta šablony jídla na stránce Šablony.
|
||||
*
|
||||
* U receptu ukazuje suroviny, hodnoty celého hrnce i jedné porce a postup;
|
||||
* u hotového jídla jen výsledné hodnoty, které se do dne zakládají.
|
||||
* Karta receptu na stránce Šablony — suroviny, hodnoty celého hrnce i jedné
|
||||
* porce a postup.
|
||||
*/
|
||||
const MealTemplateCard = ({ template, busy, onEdit, onDelete }: Readonly<Props>) => {
|
||||
const isRecipe = template.kind === MealTemplateKind.RECEPT;
|
||||
const derived = deriveAmounts(template.price, template.pricePer100g, template.weight, template.caloriesPer100g);
|
||||
const calories = derived.calories ?? template.calories;
|
||||
const recipe = isRecipe
|
||||
? deriveRecipe(template.ingredients ?? [], template.servings, template.cookedWeight)
|
||||
: undefined;
|
||||
const recipe = deriveRecipe(template.ingredients, template.servings, template.cookedWeight);
|
||||
|
||||
return (
|
||||
<div className="card-panel template-card">
|
||||
@@ -38,18 +29,18 @@ const MealTemplateCard = ({ template, busy, onEdit, onDelete }: Readonly<Props>)
|
||||
</span>
|
||||
)}
|
||||
{template.source && <span className="tag">{template.source}</span>}
|
||||
{derived.weight != null && (
|
||||
<span className="tag">{isRecipe ? 'porce ' : ''}{formatWeight(derived.weight)}</span>
|
||||
)}
|
||||
{isRecipe && (template.servings ?? 1) > 1 && (
|
||||
{template.weight != null && <span className="tag">porce {formatWeight(template.weight)}</span>}
|
||||
{(template.servings ?? 1) > 1 && (
|
||||
<span className="tag">{template.servings} porcí</span>
|
||||
)}
|
||||
</div>
|
||||
{calories != null && <span className="template-calories">{formatCalories(calories)}</span>}
|
||||
{template.calories != null && (
|
||||
<span className="template-calories">{formatCalories(template.calories)}</span>
|
||||
)}
|
||||
{template.price != null && (
|
||||
<span className="meal-template-price">{formatPrice(template.price)}</span>
|
||||
)}
|
||||
<button className="btn-icon" onClick={() => onEdit()} title="Upravit" aria-label="Upravit šablonu">
|
||||
<button className="btn-icon" onClick={() => onEdit()} title="Upravit" aria-label="Upravit recept">
|
||||
<FontAwesomeIcon icon={faPenToSquare} />
|
||||
</button>
|
||||
<button
|
||||
@@ -57,13 +48,13 @@ const MealTemplateCard = ({ template, busy, onEdit, onDelete }: Readonly<Props>)
|
||||
onClick={() => onDelete()}
|
||||
disabled={busy}
|
||||
title="Smazat"
|
||||
aria-label="Smazat šablonu"
|
||||
aria-label="Smazat recept"
|
||||
>
|
||||
<FontAwesomeIcon icon={faTrash} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{isRecipe && !!template.ingredients?.length && (
|
||||
{!!template.ingredients.length && (
|
||||
<ul className="template-items">
|
||||
{template.ingredients.map((ingredient, index) => (
|
||||
// Suroviny nemají vlastní id, v rámci jednoho receptu je index stabilní
|
||||
@@ -80,14 +71,12 @@ const MealTemplateCard = ({ template, busy, onEdit, onDelete }: Readonly<Props>)
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{recipe && (
|
||||
<div className="recipe-summary">
|
||||
Celkem {formatCalories(recipe.totalCalories)}
|
||||
{recipe.totalWeight != null && <> · {formatWeight(recipe.totalWeight)}</>}
|
||||
{recipe.caloriesPer100g != null && <> · {recipe.caloriesPer100g} kcal/100 g</>}
|
||||
{recipe.totalPrice != null && <> · {formatPrice(recipe.totalPrice)}</>}
|
||||
</div>
|
||||
)}
|
||||
<div className="recipe-summary">
|
||||
Celkem {formatCalories(recipe.totalCalories)}
|
||||
{recipe.totalWeight != null && <> · {formatWeight(recipe.totalWeight)}</>}
|
||||
{recipe.caloriesPer100g != null && <> · {recipe.caloriesPer100g} kcal/100 g</>}
|
||||
{recipe.totalPrice != null && <> · {formatPrice(recipe.totalPrice)}</>}
|
||||
</div>
|
||||
|
||||
{template.note && <p className="meal-template-note">{template.note}</p>}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user