feat: export částečných receptů omezen jen na chybějící
fix: změna fontu pro českou část hell girl feat: export receptů grupován dle typu feat: přidány filtery jídel
This commit is contained in:
1 parent
8377ce2205
commit
af424313b9
11 files changed
+201
-43
No files matched your search
@@ -75,7 +75,8 @@ cd client && yarn build # tsc --noEmit + vite build → client/dist
|
|||||||
### Client (client/src/)
|
### Client (client/src/)
|
||||||
- **Entry:** `index.tsx` → `AppRoutes.tsx`; `Login.tsx` je přihlašovací obrazovka
|
- **Entry:** `index.tsx` → `AppRoutes.tsx`; `Login.tsx` je přihlašovací obrazovka
|
||||||
- **Pages:** `pages/` — `DayPage` (přehled dne se záložkami Příjem/Výdej),
|
- **Pages:** `pages/` — `DayPage` (přehled dne se záložkami Příjem/Výdej),
|
||||||
`MealGroupsPage` (`/jidla` — seznam jídel podle názvu a zdroje s filtrem zdroje,
|
`MealGroupsPage` (`/jidla` — seznam jídel podle názvu a zdroje s filtry zdroje,
|
||||||
|
receptu, typu receptu a chybějících údajů (`MissingFilter`),
|
||||||
hromadným doplněním údajů a přejmenováním),
|
hromadným doplněním údajů a přejmenováním),
|
||||||
`WorkoutsPage` (`/treninky` — plány a šablony tréninků), `ProfilePage` (Profil — ukazatele,
|
`WorkoutsPage` (`/treninky` — plány a šablony tréninků), `ProfilePage` (Profil — ukazatele,
|
||||||
vývoj hmotnosti, tělesné údaje, cíle a klidový výdej),
|
vývoj hmotnosti, tělesné údaje, cíle a klidový výdej),
|
||||||
@@ -420,12 +421,15 @@ Markdownu v jedné cestě, je potřeba upravit i druhou.**
|
|||||||
exportu) jde u jednoho receptu (ikona na kartě receptu) i hromadně tlačítkem
|
exportu) jde u jednoho receptu (ikona na kartě receptu) i hromadně tlačítkem
|
||||||
na stránce Jídla (`RecipeExportButton`) — exportují se recepty, které seznam
|
na stránce Jídla (`RecipeExportButton`) — exportují se recepty, které seznam
|
||||||
po filtrech ukazuje, bez filtru všechny. Hlavní tlačítko bere jen úplné recepty,
|
po filtrech ukazuje, bez filtru všechny. Hlavní tlačítko bere jen úplné recepty,
|
||||||
nabídka u něj i neúplné. Víc receptů dostane titulní stranu s klikacím obsahem, každý
|
nabídka u něj jen recepty bez surovin (k doplnění). Víc receptů dostane titulní
|
||||||
recept začíná na nové stránce. PDF nese suroviny, hodnoty porce, postup a fotky
|
stranu s klikacím obsahem a seskupí se podle typu (`createSections` — typy podle
|
||||||
|
abecedy, bez typu na konec, uvnitř oddílu podle názvu); každý oddíl má úvodní
|
||||||
|
stránku s názvem a počtem receptů, každý recept začíná na nové stránce. PDF nese suroviny, hodnoty porce, postup a fotky
|
||||||
jídla (první přes šířku, ostatní menší); pdfmake umí jen JPEG a PNG, jiné
|
jídla (první přes šířku, ostatní menší); pdfmake umí jen JPEG a PNG, jiné
|
||||||
formáty se vynechají. Server se exportu neúčastní.
|
formáty se vynechají. Server se exportu neúčastní.
|
||||||
|
|
||||||
**PDF k doplnění** (volba v nabídce exportu, neúplný recept ho dostane vždy):
|
**PDF k doplnění** (volba v nabídce exportu jen pro recepty bez surovin; pole
|
||||||
|
dostane i neúplný recept v jakémkoli jiném exportu):
|
||||||
každý recept má vyplnitelná pole pro čas přípravy, počet porcí a hmotnost
|
každý recept má vyplnitelná pole pro čas přípravy, počet porcí a hmotnost
|
||||||
hotového jídla, předvyplněná tím, co recept už má, aby šla i opravit. Suroviny
|
hotového jídla, předvyplněná tím, co recept už má, aby šla i opravit. Suroviny
|
||||||
a postup jsou pole (jedno volné textové) jen tam, kde chybí; chybu v hotových
|
a postup jsou pole (jedno volné textové) jen tam, kde chybí; chybu v hotových
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
<title>Food Tracer</title>
|
<title>Food Tracer</title>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Shippori+Mincho:wght@600;700;800&display=swap" rel="stylesheet" />
|
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif:wght@400;600;700;800&family=Shippori+Mincho:wght@600;700;800&display=swap" rel="stylesheet" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>Pro běh aplikace je potřeba zapnutý JavaScript.</noscript>
|
<noscript>Pro běh aplikace je potřeba zapnutý JavaScript.</noscript>
|
||||||
|
|||||||
@@ -387,6 +387,21 @@ body {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bez vlastního stylu by zůstala bootstrapová modrá, která nesedí k žádnému vzhledu
|
||||||
|
.btn-outline-primary {
|
||||||
|
--bs-btn-color: var(--ft-primary);
|
||||||
|
--bs-btn-border-color: var(--ft-primary);
|
||||||
|
--bs-btn-hover-color: #fff;
|
||||||
|
--bs-btn-hover-bg: var(--ft-primary);
|
||||||
|
--bs-btn-hover-border-color: var(--ft-primary);
|
||||||
|
--bs-btn-active-color: #fff;
|
||||||
|
--bs-btn-active-bg: var(--ft-primary-hover);
|
||||||
|
--bs-btn-active-border-color: var(--ft-primary-hover);
|
||||||
|
--bs-btn-disabled-color: var(--ft-primary);
|
||||||
|
--bs-btn-disabled-border-color: var(--ft-primary);
|
||||||
|
--bs-btn-focus-shadow-rgb: 128, 128, 128;
|
||||||
|
}
|
||||||
|
|
||||||
.btn-outline-secondary {
|
.btn-outline-secondary {
|
||||||
color: var(--ft-text-secondary);
|
color: var(--ft-text-secondary);
|
||||||
border-color: var(--ft-border);
|
border-color: var(--ft-border);
|
||||||
|
|||||||
@@ -16,12 +16,13 @@ type Props = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Hromadný export receptů do PDF. Hlavní tlačítko stáhne jen úplné recepty
|
* Hromadný export receptů do PDF. Hlavní tlačítko stáhne jen úplné recepty
|
||||||
* (se surovinami i postupem); v nabídce je export všech včetně neúplných
|
* (se surovinami i postupem); v nabídce je export receptů bez surovin s poli
|
||||||
* s poli k doplnění a opravě — PDF se pošle někomu, kdo recepty zná.
|
* k doplnění — PDF se pošle někomu, kdo recepty zná.
|
||||||
*/
|
*/
|
||||||
const RecipeExportButton = ({ itemList, filtered, loading }: Readonly<Props>) => {
|
const RecipeExportButton = ({ itemList, filtered, loading }: Readonly<Props>) => {
|
||||||
const { exporting, exportRecipes } = useRecipeExport();
|
const { exporting, exportRecipes } = useRecipeExport();
|
||||||
const completeList = itemList.filter(item => isRecipeComplete(item.recipe));
|
const completeList = itemList.filter(item => isRecipeComplete(item.recipe));
|
||||||
|
const emptyList = itemList.filter(item => !item.recipe.ingredients.length);
|
||||||
const scope = filtered ? 'zobrazené' : 'všechny';
|
const scope = filtered ? 'zobrazené' : 'všechny';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -35,11 +36,11 @@ const RecipeExportButton = ({ itemList, filtered, loading }: Readonly<Props>) =>
|
|||||||
{exporting ? <Spinner animation="border" size="sm" /> : <FontAwesomeIcon icon={faFilePdf} />}
|
{exporting ? <Spinner animation="border" size="sm" /> : <FontAwesomeIcon icon={faFilePdf} />}
|
||||||
{' '}Recepty do PDF{!loading && ` (${completeList.length})`}
|
{' '}Recepty do PDF{!loading && ` (${completeList.length})`}
|
||||||
</Button>
|
</Button>
|
||||||
<Dropdown.Toggle split variant="outline-secondary" disabled={exporting || !itemList.length} />
|
<Dropdown.Toggle split variant="outline-secondary" disabled={exporting || !emptyList.length} />
|
||||||
<Dropdown.Menu align="end">
|
<Dropdown.Menu align="end">
|
||||||
<Dropdown.Item onClick={() => exportRecipes(itemList, true)}>
|
<Dropdown.Item onClick={() => exportRecipes(emptyList, true)}>
|
||||||
K doplnění, včetně neúplných ({itemList.length})
|
K doplnění, recepty bez surovin ({emptyList.length})
|
||||||
<div className="small text-muted">čas, porce, hmotnost, chybějící suroviny a postup i poznámky jde dopsat přímo v PDF</div>
|
<div className="small text-muted">suroviny, postup, čas, porce, hmotnost i poznámky jde dopsat přímo v PDF</div>
|
||||||
</Dropdown.Item>
|
</Dropdown.Item>
|
||||||
</Dropdown.Menu>
|
</Dropdown.Menu>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
outline: 1px solid rgb(200 16 46 / 0.4);
|
outline: 1px solid rgb(200 16 46 / 0.4);
|
||||||
outline-offset: 2px;
|
outline-offset: 2px;
|
||||||
color: #fff4ee;
|
color: #fff4ee;
|
||||||
font-family: 'Shippori Mincho', 'Noto Serif JP', serif;
|
font-family: 'Noto Serif', 'Shippori Mincho', 'Noto Serif JP', serif;
|
||||||
font-weight: 800;
|
font-weight: 800;
|
||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
letter-spacing: 1px;
|
letter-spacing: 1px;
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
padding: 14px 48px;
|
padding: 14px 48px;
|
||||||
font-family: 'Shippori Mincho', 'Noto Serif JP', serif;
|
font-family: 'Noto Serif', 'Shippori Mincho', 'Noto Serif JP', serif;
|
||||||
font-weight: 800;
|
font-weight: 800;
|
||||||
font-size: clamp(2rem, 7vw, 4rem);
|
font-size: clamp(2rem, 7vw, 4rem);
|
||||||
letter-spacing: 0.3em;
|
letter-spacing: 0.3em;
|
||||||
@@ -118,7 +118,7 @@
|
|||||||
border: 1px solid var(--speaker, #c8102e);
|
border: 1px solid var(--speaker, #c8102e);
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
box-shadow: 0 0 16px rgb(0 0 0 / 0.6), 0 0 10px rgb(200 16 46 / 0.3);
|
box-shadow: 0 0 16px rgb(0 0 0 / 0.6), 0 0 10px rgb(200 16 46 / 0.3);
|
||||||
font-family: 'Shippori Mincho', 'Noto Serif JP', serif;
|
font-family: 'Noto Serif', 'Shippori Mincho', 'Noto Serif JP', serif;
|
||||||
|
|
||||||
p {
|
p {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|||||||
@@ -214,6 +214,33 @@ export const RECIPE_FILTER_NAMES: Record<RecipeFilter, string> = {
|
|||||||
BEZ_RECEPTU: 'Bez receptu',
|
BEZ_RECEPTU: 'Bez receptu',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filtr seznamu jídel podle chybějících údajů. Živiny chybí skoro všude (recept
|
||||||
|
* je nemá nikdy), proto jde hledat i jen chybějící gramáž nebo kalorie.
|
||||||
|
*/
|
||||||
|
export enum MissingFilter {
|
||||||
|
VSE = 'VSE',
|
||||||
|
COKOLI = 'COKOLI',
|
||||||
|
GRAMAZ_NEBO_KALORIE = 'GRAMAZ_NEBO_KALORIE',
|
||||||
|
GRAMAZ = 'GRAMAZ',
|
||||||
|
KALORIE = 'KALORIE',
|
||||||
|
ZIVINY = 'ZIVINY',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MISSING_FILTER_NAMES: Record<MissingFilter, string> = {
|
||||||
|
VSE: 'Doplněná i nedoplněná',
|
||||||
|
COKOLI: 'Chybí cokoli',
|
||||||
|
GRAMAZ_NEBO_KALORIE: 'Chybí gramáž nebo kalorie',
|
||||||
|
GRAMAZ: 'Chybí gramáž',
|
||||||
|
KALORIE: 'Chybí kalorie',
|
||||||
|
ZIVINY: 'Chybí živiny',
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Zvláštní volba filtru typu receptu; jinak se filtruje konkrétním typem. */
|
||||||
|
export enum RecipeCategoryFilter {
|
||||||
|
VSE = 'VSE',
|
||||||
|
}
|
||||||
|
|
||||||
/** Popisky chuti receptu. */
|
/** Popisky chuti receptu. */
|
||||||
export const RECIPE_FLAVOR_NAMES: Record<RecipeFlavor, string> = {
|
export const RECIPE_FLAVOR_NAMES: Record<RecipeFlavor, string> = {
|
||||||
SLANE: 'Slané',
|
SLANE: 'Slané',
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
Bar, CartesianGrid, Cell, ComposedChart, Legend, Line, Pie, PieChart, ResponsiveContainer, Tooltip, XAxis, YAxis,
|
Bar, CartesianGrid, Cell, ComposedChart, Legend, Line, Pie, PieChart, ResponsiveContainer, Tooltip, XAxis, YAxis,
|
||||||
} from "recharts";
|
} from "recharts";
|
||||||
import { IntakeStats, MealType, getIntakeStats } from "../../../types";
|
import { IntakeStats, MealType, getIntakeStats } from "../../../types";
|
||||||
import { MEAL_TYPE_NAMES, NUTRIENT_NAMES, NUTRIENTS_IN_ORDER, StatsRange } from "../enums";
|
import { MEAL_TYPE_NAMES, MissingFilter, NUTRIENT_NAMES, NUTRIENTS_IN_ORDER, StatsRange } from "../enums";
|
||||||
import { formatBalance, formatCalories, formatNutrient } from "../Utils";
|
import { formatBalance, formatCalories, formatNutrient } from "../Utils";
|
||||||
import { JIDLA_URL } from "../routes";
|
import { JIDLA_URL } from "../routes";
|
||||||
import { StatsBounds, TOOLTIP_STYLE, buildSourceSlices } from "./statsShared";
|
import { StatsBounds, TOOLTIP_STYLE, buildSourceSlices } from "./statsShared";
|
||||||
@@ -130,7 +130,7 @@ const IntakeStatsPanel = ({ range, mode, reloadKey }: Readonly<Props>) => {
|
|||||||
{stats.missingCaloriesCount} z {stats.entryCount} jídel nemá kalorie, do součtů nevstupují
|
{stats.missingCaloriesCount} z {stats.entryCount} jídel nemá kalorie, do součtů nevstupují
|
||||||
a příjem tak vychází nižší, než byl.
|
a příjem tak vychází nižší, než byl.
|
||||||
</span>
|
</span>
|
||||||
<Button variant="outline-secondary" size="sm" onClick={() => navigate(JIDLA_URL, { state: { onlyIncomplete: true } })}>
|
<Button variant="outline-secondary" size="sm" onClick={() => navigate(JIDLA_URL, { state: { missingFilter: MissingFilter.KALORIE } })}>
|
||||||
<FontAwesomeIcon icon={faPenToSquare} /> Doplnit
|
<FontAwesomeIcon icon={faPenToSquare} /> Doplnit
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,9 +15,11 @@
|
|||||||
flex: 0 1 200px;
|
flex: 0 1 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-check {
|
// Popisky volby jsou delší, pole bere šířku podle nejdelší z nich
|
||||||
margin: 0;
|
.meal-groups-category,
|
||||||
white-space: nowrap;
|
.meal-groups-missing {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.meal-groups-count {
|
.meal-groups-count {
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import { useLocation } from "react-router";
|
|||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faBookOpen, faCircleCheck } from "@fortawesome/free-solid-svg-icons";
|
import { faBookOpen, faCircleCheck } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { MealGroup, MealTemplate, getMealGroups } from "../../../types";
|
import { MealGroup, MealTemplate, getMealGroups } from "../../../types";
|
||||||
import { MealGroupAction, RECIPE_FILTER_NAMES, RecipeFilter, SourceFilter } from "../enums";
|
import {
|
||||||
|
MISSING_FILTER_NAMES, MealGroupAction, MissingFilter, RECIPE_FILTER_NAMES, RecipeCategoryFilter, RecipeFilter, SourceFilter,
|
||||||
|
} from "../enums";
|
||||||
import { getMealKey, normalizeSearch } from "../Utils";
|
import { getMealKey, normalizeSearch } from "../Utils";
|
||||||
import MealGroupRow from "../components/MealGroupRow";
|
import MealGroupRow from "../components/MealGroupRow";
|
||||||
import MealTemplateForm from "../components/MealTemplateForm";
|
import MealTemplateForm from "../components/MealTemplateForm";
|
||||||
@@ -12,8 +14,22 @@ import RecipeExportButton from "../components/RecipeExportButton";
|
|||||||
import "./templates.scss";
|
import "./templates.scss";
|
||||||
import "./MealGroupsPage.scss";
|
import "./MealGroupsPage.scss";
|
||||||
|
|
||||||
const isIncomplete = (group: MealGroup): boolean =>
|
const matchesMissing = (group: MealGroup, missingFilter: MissingFilter): boolean => {
|
||||||
group.missingCaloriesCount + group.missingWeightCount + group.missingNutrientsCount > 0;
|
switch (missingFilter) {
|
||||||
|
case MissingFilter.VSE:
|
||||||
|
return true;
|
||||||
|
case MissingFilter.COKOLI:
|
||||||
|
return group.missingCaloriesCount + group.missingWeightCount + group.missingNutrientsCount > 0;
|
||||||
|
case MissingFilter.GRAMAZ_NEBO_KALORIE:
|
||||||
|
return group.missingCaloriesCount + group.missingWeightCount > 0;
|
||||||
|
case MissingFilter.GRAMAZ:
|
||||||
|
return group.missingWeightCount > 0;
|
||||||
|
case MissingFilter.KALORIE:
|
||||||
|
return group.missingCaloriesCount > 0;
|
||||||
|
case MissingFilter.ZIVINY:
|
||||||
|
return group.missingNutrientsCount > 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** Hodnota výběru pro konkrétní zdroj; předpona ji odliší od zvláštních voleb filtru. */
|
/** Hodnota výběru pro konkrétní zdroj; předpona ji odliší od zvláštních voleb filtru. */
|
||||||
const toSourceOption = (source: string): string => `zdroj:${normalizeSearch(source)}`;
|
const toSourceOption = (source: string): string => `zdroj:${normalizeSearch(source)}`;
|
||||||
@@ -35,6 +51,27 @@ const listSources = (groupList: MealGroup[]): { value: string, label: string }[]
|
|||||||
.map(([value, item]) => ({ value, label: item.label }));
|
.map(([value, item]) => ({ value, label: item.label }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Hodnota výběru pro konkrétní typ receptu; předpona ji odliší od zvláštní volby filtru. */
|
||||||
|
const toCategoryOption = (category: string): string => `typ:${normalizeSearch(category)}`;
|
||||||
|
|
||||||
|
/** Typy receptů pro filtr, každý jednou, podle abecedy. */
|
||||||
|
const listCategories = (recipeList: MealTemplate[]): { value: string, label: string }[] => {
|
||||||
|
const labelMap = new Map<string, string>();
|
||||||
|
for (const recipe of recipeList) {
|
||||||
|
const category = recipe.category?.trim();
|
||||||
|
if (category && !labelMap.has(toCategoryOption(category))) labelMap.set(toCategoryOption(category), category);
|
||||||
|
}
|
||||||
|
return [...labelMap.entries()]
|
||||||
|
.map(([value, label]) => ({ value, label }))
|
||||||
|
.sort((a, b) => a.label.localeCompare(b.label, 'cs'));
|
||||||
|
};
|
||||||
|
|
||||||
|
const matchesCategory = (group: MealGroup, categoryFilter: string): boolean => {
|
||||||
|
if (categoryFilter === RecipeCategoryFilter.VSE) return true;
|
||||||
|
const category = group.recipe?.category?.trim();
|
||||||
|
return !!category && toCategoryOption(category) === categoryFilter;
|
||||||
|
};
|
||||||
|
|
||||||
const matchesRecipe = (group: MealGroup, recipeFilter: RecipeFilter): boolean => {
|
const matchesRecipe = (group: MealGroup, recipeFilter: RecipeFilter): boolean => {
|
||||||
if (recipeFilter === RecipeFilter.S_RECEPTEM) return !!group.recipe;
|
if (recipeFilter === RecipeFilter.S_RECEPTEM) return !!group.recipe;
|
||||||
if (recipeFilter === RecipeFilter.BEZ_RECEPTU) return !group.recipe;
|
if (recipeFilter === RecipeFilter.BEZ_RECEPTU) return !group.recipe;
|
||||||
@@ -47,7 +84,7 @@ const matchesSearch = (group: MealGroup, search: string): boolean =>
|
|||||||
|| (!!group.recipe?.category && normalizeSearch(group.recipe.category).includes(search));
|
|| (!!group.recipe?.category && normalizeSearch(group.recipe.category).includes(search));
|
||||||
|
|
||||||
/** Stav, se kterým stránku může otevřít odkaz odjinud (statistiky, výběr z historie). */
|
/** Stav, se kterým stránku může otevřít odkaz odjinud (statistiky, výběr z historie). */
|
||||||
type LocationState = { onlyIncomplete?: boolean, recipeFilter?: RecipeFilter } | null;
|
type LocationState = { missingFilter?: MissingFilter, recipeFilter?: RecipeFilter } | null;
|
||||||
|
|
||||||
const matchesSource = (group: MealGroup, sourceFilter: string): boolean => {
|
const matchesSource = (group: MealGroup, sourceFilter: string): boolean => {
|
||||||
if (sourceFilter === SourceFilter.VSE) return true;
|
if (sourceFilter === SourceFilter.VSE) return true;
|
||||||
@@ -69,7 +106,9 @@ const MealGroupsPage = () => {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [query, setQuery] = useState('');
|
const [query, setQuery] = useState('');
|
||||||
const [sourceFilter, setSourceFilter] = useState<string>(SourceFilter.VSE);
|
const [sourceFilter, setSourceFilter] = useState<string>(SourceFilter.VSE);
|
||||||
const [onlyIncomplete, setOnlyIncomplete] = useState(() => !!(location.state as LocationState)?.onlyIncomplete);
|
const [missingFilter, setMissingFilter] = useState<MissingFilter>(() =>
|
||||||
|
(location.state as LocationState)?.missingFilter ?? MissingFilter.VSE);
|
||||||
|
const [categoryFilter, setCategoryFilter] = useState<string>(RecipeCategoryFilter.VSE);
|
||||||
const [recipeFilter, setRecipeFilter] = useState<RecipeFilter>(() =>
|
const [recipeFilter, setRecipeFilter] = useState<RecipeFilter>(() =>
|
||||||
(location.state as LocationState)?.recipeFilter ?? RecipeFilter.VSE);
|
(location.state as LocationState)?.recipeFilter ?? RecipeFilter.VSE);
|
||||||
const [opened, setOpened] = useState<{ key: string, action: MealGroupAction } | undefined>();
|
const [opened, setOpened] = useState<{ key: string, action: MealGroupAction } | undefined>();
|
||||||
@@ -89,15 +128,17 @@ const MealGroupsPage = () => {
|
|||||||
() => groupList.flatMap(group => group.recipe ? [group.recipe] : []),
|
() => groupList.flatMap(group => group.recipe ? [group.recipe] : []),
|
||||||
[groupList],
|
[groupList],
|
||||||
);
|
);
|
||||||
|
const categoryList = useMemo(() => listCategories(recipeList), [recipeList]);
|
||||||
|
|
||||||
const visibleList = useMemo(() => {
|
const visibleList = useMemo(() => {
|
||||||
const search = normalizeSearch(query);
|
const search = normalizeSearch(query);
|
||||||
return groupList.filter(group =>
|
return groupList.filter(group =>
|
||||||
(!onlyIncomplete || isIncomplete(group))
|
matchesMissing(group, missingFilter)
|
||||||
&& matchesSource(group, sourceFilter)
|
&& matchesSource(group, sourceFilter)
|
||||||
&& matchesRecipe(group, recipeFilter)
|
&& matchesRecipe(group, recipeFilter)
|
||||||
|
&& matchesCategory(group, categoryFilter)
|
||||||
&& (!search.length || matchesSearch(group, search)));
|
&& (!search.length || matchesSearch(group, search)));
|
||||||
}, [groupList, query, sourceFilter, recipeFilter, onlyIncomplete]);
|
}, [groupList, query, sourceFilter, recipeFilter, categoryFilter, missingFilter]);
|
||||||
|
|
||||||
// Exportují se recepty, které seznam právě ukazuje — bez filtru tedy všechny
|
// Exportují se recepty, které seznam právě ukazuje — bez filtru tedy všechny
|
||||||
const visibleRecipeList = useMemo(() => visibleList
|
const visibleRecipeList = useMemo(() => visibleList
|
||||||
@@ -119,13 +160,18 @@ const MealGroupsPage = () => {
|
|||||||
setQuery('');
|
setQuery('');
|
||||||
setSourceFilter(SourceFilter.VSE);
|
setSourceFilter(SourceFilter.VSE);
|
||||||
setRecipeFilter(RecipeFilter.VSE);
|
setRecipeFilter(RecipeFilter.VSE);
|
||||||
setOnlyIncomplete(false);
|
setCategoryFilter(RecipeCategoryFilter.VSE);
|
||||||
|
setMissingFilter(MissingFilter.VSE);
|
||||||
}
|
}
|
||||||
setOpened({ key, action: MealGroupAction.RECEPT });
|
setOpened({ key, action: MealGroupAction.RECEPT });
|
||||||
setScrollKey(key);
|
setScrollKey(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
const filtered = !!query.trim().length || sourceFilter !== SourceFilter.VSE || recipeFilter !== RecipeFilter.VSE;
|
const otherFiltered = !!query.trim().length
|
||||||
|
|| sourceFilter !== SourceFilter.VSE
|
||||||
|
|| recipeFilter !== RecipeFilter.VSE
|
||||||
|
|| categoryFilter !== RecipeCategoryFilter.VSE;
|
||||||
|
const filtered = otherFiltered || missingFilter !== MissingFilter.VSE;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -175,13 +221,23 @@ const MealGroupsPage = () => {
|
|||||||
<option key={value} value={value}>{RECIPE_FILTER_NAMES[value]}</option>
|
<option key={value} value={value}>{RECIPE_FILTER_NAMES[value]}</option>
|
||||||
))}
|
))}
|
||||||
</Form.Select>
|
</Form.Select>
|
||||||
<Form.Check
|
<Form.Select
|
||||||
type="switch"
|
className="meal-groups-category"
|
||||||
id="meal-groups-incomplete"
|
value={categoryFilter}
|
||||||
label="K doplnění"
|
onChange={event => setCategoryFilter(event.target.value)}
|
||||||
checked={onlyIncomplete}
|
>
|
||||||
onChange={event => setOnlyIncomplete(event.target.checked)}
|
<option value={RecipeCategoryFilter.VSE}>Všechny typy receptů</option>
|
||||||
/>
|
{categoryList.map(category => <option key={category.value} value={category.value}>{category.label}</option>)}
|
||||||
|
</Form.Select>
|
||||||
|
<Form.Select
|
||||||
|
className="meal-groups-missing"
|
||||||
|
value={missingFilter}
|
||||||
|
onChange={event => setMissingFilter(event.target.value as MissingFilter)}
|
||||||
|
>
|
||||||
|
{Object.values(MissingFilter).map(value => (
|
||||||
|
<option key={value} value={value}>{MISSING_FILTER_NAMES[value]}</option>
|
||||||
|
))}
|
||||||
|
</Form.Select>
|
||||||
{!loading && (
|
{!loading && (
|
||||||
<span className="meal-groups-count">
|
<span className="meal-groups-count">
|
||||||
Zobrazeno {visibleList.length === groupList.length
|
Zobrazeno {visibleList.length === groupList.length
|
||||||
@@ -201,7 +257,7 @@ const MealGroupsPage = () => {
|
|||||||
<div className="card-panel empty-state">
|
<div className="card-panel empty-state">
|
||||||
<div className="empty-icon"><FontAwesomeIcon icon={faCircleCheck} /></div>
|
<div className="empty-icon"><FontAwesomeIcon icon={faCircleCheck} /></div>
|
||||||
<div className="empty-title">
|
<div className="empty-title">
|
||||||
{onlyIncomplete && !filtered ? 'Všechna jídla mají údaje vyplněné' : 'Nic nenalezeno'}
|
{missingFilter !== MissingFilter.VSE && !otherFiltered ? 'Všechna jídla mají údaje vyplněné' : 'Nic nenalezeno'}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
+57
-6
@@ -11,6 +11,9 @@ import {
|
|||||||
/** Recept s počtem fotek jídla — fotky se stahují jen tam, kde nějaké jsou. */
|
/** Recept s počtem fotek jídla — fotky se stahují jen tam, kde nějaké jsou. */
|
||||||
type RecipeItem = Pick<MealGroup, 'photoCount'> & { recipe: MealTemplate };
|
type RecipeItem = Pick<MealGroup, 'photoCount'> & { recipe: MealTemplate };
|
||||||
|
|
||||||
|
/** Recepty jednoho typu (polévky, omáčky…) v pořadí, v jakém jdou do PDF. */
|
||||||
|
type RecipeSection = { title: string, itemList: RecipeItem[] };
|
||||||
|
|
||||||
const PRIMARY_COLOR = '#156080';
|
const PRIMARY_COLOR = '#156080';
|
||||||
const MUTED_COLOR = '#6b7280';
|
const MUTED_COLOR = '#6b7280';
|
||||||
const BORDER_COLOR = '#e5e7eb';
|
const BORDER_COLOR = '#e5e7eb';
|
||||||
@@ -29,6 +32,11 @@ const INGREDIENTS_FIELD_HEIGHT = 150;
|
|||||||
const NOTE_FIELD_HEIGHT = 230;
|
const NOTE_FIELD_HEIGHT = 230;
|
||||||
const REMARKS_FIELD_HEIGHT = 90;
|
const REMARKS_FIELD_HEIGHT = 90;
|
||||||
|
|
||||||
|
/** Název oddílu pro recepty bez typu. */
|
||||||
|
const NO_CATEGORY_TITLE = 'Bez typu';
|
||||||
|
/** Odsazení názvu oddílu od horního okraje, aby stál zhruba ve třetině stránky. */
|
||||||
|
const SECTION_TOP_MARGIN = 220;
|
||||||
|
|
||||||
/** Předpony `id` uzlů, podle kterých se v rozvržení pdfmake najdou pole a jejich popisky. */
|
/** Předpony `id` uzlů, podle kterých se v rozvržení pdfmake najdou pole a jejich popisky. */
|
||||||
const FIELD_ID_PREFIX = 'pole:';
|
const FIELD_ID_PREFIX = 'pole:';
|
||||||
const LABEL_ID_PREFIX = 'popisek:';
|
const LABEL_ID_PREFIX = 'popisek:';
|
||||||
@@ -56,6 +64,42 @@ const getRecipeMeta = (recipe: MealTemplate, editable: boolean): string => {
|
|||||||
].filter(item => !!item).join(' · ');
|
].filter(item => !!item).join(' · ');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rozdělí recepty do oddílů podle typu — typy podle abecedy, recepty bez typu
|
||||||
|
* na konec, uvnitř oddílu podle názvu. Typ je volný text, „Polévka" a „polévka"
|
||||||
|
* jsou tentýž oddíl pojmenovaný podle prvního výskytu.
|
||||||
|
*/
|
||||||
|
const createSections = (itemList: RecipeItem[]): RecipeSection[] => {
|
||||||
|
const sectionMap = new Map<string, RecipeSection>();
|
||||||
|
for (const item of itemList) {
|
||||||
|
const category = item.recipe.category?.trim();
|
||||||
|
const key = category?.toLocaleLowerCase('cs') ?? '';
|
||||||
|
const section = sectionMap.get(key) ?? { title: category || NO_CATEGORY_TITLE, itemList: [] };
|
||||||
|
section.itemList.push(item);
|
||||||
|
sectionMap.set(key, section);
|
||||||
|
}
|
||||||
|
return [...sectionMap.entries()]
|
||||||
|
.sort(([a], [b]) => {
|
||||||
|
if (!a) return 1;
|
||||||
|
if (!b) return -1;
|
||||||
|
return a.localeCompare(b, 'cs');
|
||||||
|
})
|
||||||
|
.map(([, section]) => ({
|
||||||
|
title: section.title,
|
||||||
|
itemList: [...section.itemList].sort((a, b) => a.recipe.name.localeCompare(b.recipe.name, 'cs')),
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Úvodní stránka oddílu s jeho názvem a počtem receptů; v obsahu je tučně nad recepty oddílu. */
|
||||||
|
const createSectionPage = (section: RecipeSection): Content => ({
|
||||||
|
stack: [
|
||||||
|
{ text: section.title, style: 'coverTitle', tocItem: true, tocStyle: { bold: true }, tocMargin: [0, 6, 0, 2] },
|
||||||
|
{ text: formatCount(section.itemList.length, 'recept', 'recepty', 'receptů'), style: 'recipeMeta' },
|
||||||
|
],
|
||||||
|
margin: [0, SECTION_TOP_MARGIN, 0, 0],
|
||||||
|
pageBreak: 'before',
|
||||||
|
});
|
||||||
|
|
||||||
/** Kotva receptu v dokumentu — cíl odkazů z obsahu a z vazeb mezi recepty. */
|
/** Kotva receptu v dokumentu — cíl odkazů z obsahu a z vazeb mezi recepty. */
|
||||||
const getRecipeAnchor = (index: number): string => `recept-${index}`;
|
const getRecipeAnchor = (index: number): string => `recept-${index}`;
|
||||||
|
|
||||||
@@ -200,7 +244,7 @@ const createRecipe = (
|
|||||||
): Content => {
|
): Content => {
|
||||||
const fields = editable || !isRecipeComplete(recipe) ? createEditableFields(recipe, index, fieldList) : undefined;
|
const fields = editable || !isRecipeComplete(recipe) ? createEditableFields(recipe, index, fieldList) : undefined;
|
||||||
const header: Content[] = [
|
const header: Content[] = [
|
||||||
{ text: recipe.name, style: 'recipeTitle', id: getRecipeAnchor(index), tocItem: withToc },
|
{ text: recipe.name, style: 'recipeTitle', id: getRecipeAnchor(index), tocItem: withToc, tocMargin: [12, 2, 0, 2] },
|
||||||
...(recipe.source ? [{ text: recipe.source, style: 'recipeSource' }] : []),
|
...(recipe.source ? [{ text: recipe.source, style: 'recipeSource' }] : []),
|
||||||
{ text: getRecipeMeta(recipe, !!fields), style: 'recipeMeta' },
|
{ text: getRecipeMeta(recipe, !!fields), style: 'recipeMeta' },
|
||||||
...(fields
|
...(fields
|
||||||
@@ -271,15 +315,17 @@ const loadPdfMake = async () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Stáhne recepty jako PDF — suroviny, hodnoty porce, postup a fotky jídla.
|
* Stáhne recepty jako PDF — suroviny, hodnoty porce, postup a fotky jídla.
|
||||||
* Víc receptů dostane titulní stránku s klikacím obsahem a každý recept
|
* Víc receptů dostane titulní stránku s klikacím obsahem, recepty jsou
|
||||||
* začíná na nové stránce.
|
* seskupené podle typu (`createSections`), každý oddíl má úvodní stránku
|
||||||
|
* a každý recept začíná na nové stránce.
|
||||||
*
|
*
|
||||||
* S `editable` dostane každý recept vyplnitelná pole PDF k doplnění a opravě
|
* S `editable` dostane každý recept vyplnitelná pole PDF k doplnění a opravě
|
||||||
* (`createEditableFields`); neúplný recept (bez surovin nebo postupu) je
|
* (`createEditableFields`); neúplný recept (bez surovin nebo postupu) je
|
||||||
* dostane vždy.
|
* dostane vždy.
|
||||||
*/
|
*/
|
||||||
export const exportRecipesPdf = async (itemList: RecipeItem[], editable = false): Promise<void> => {
|
export const exportRecipesPdf = async (itemList: RecipeItem[], editable = false): Promise<void> => {
|
||||||
const sortedList = [...itemList].sort((a, b) => a.recipe.name.localeCompare(b.recipe.name, 'cs'));
|
const sectionList = createSections(itemList);
|
||||||
|
const sortedList = sectionList.flatMap(section => section.itemList);
|
||||||
const [{ pdfMake, vfs }, photoLists, recipeResponse] = await Promise.all([
|
const [{ pdfMake, vfs }, photoLists, recipeResponse] = await Promise.all([
|
||||||
loadPdfMake(),
|
loadPdfMake(),
|
||||||
Promise.all(sortedList.map(loadPhotos)),
|
Promise.all(sortedList.map(loadPhotos)),
|
||||||
@@ -306,8 +352,13 @@ export const exportRecipesPdf = async (itemList: RecipeItem[], editable = false)
|
|||||||
] : [];
|
] : [];
|
||||||
|
|
||||||
// Sestavením obsahu se naplní i fieldList, proto musí proběhnout před definicí
|
// Sestavením obsahu se naplní i fieldList, proto musí proběhnout před definicí
|
||||||
const recipeContent = sortedList.map((item, index) =>
|
const recipeContent = sortedList.flatMap((item, index) => {
|
||||||
createRecipe(item.recipe, photoLists[index], { index, withToc, recipeList, indexMap, fieldList, editable }));
|
const section = withToc ? sectionList.find(candidate => candidate.itemList[0] === item) : undefined;
|
||||||
|
return [
|
||||||
|
...(section ? [createSectionPage(section)] : []),
|
||||||
|
createRecipe(item.recipe, photoLists[index], { index, withToc, recipeList, indexMap, fieldList, editable }),
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
const definition: TDocumentDefinitions = {
|
const definition: TDocumentDefinitions = {
|
||||||
info: { title },
|
info: { title },
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ $hg-twilight: linear-gradient(90deg, #1e0a1c, #4a0f2a 35%, #8e0f24 70%, #c8452a)
|
|||||||
$hg-thread: linear-gradient(90deg, transparent, #c8102e 12%, #e8344f 50%, #c8102e 88%, transparent);
|
$hg-thread: linear-gradient(90deg, transparent, #c8102e 12%, #e8344f 50%, #c8102e 88%, transparent);
|
||||||
|
|
||||||
#{$hg} {
|
#{$hg} {
|
||||||
--hg-font: 'Shippori Mincho', 'Noto Serif JP', 'Georgia', serif;
|
// Latinku i s českou diakritikou kreslí Noto Serif, Shippori Mincho jen japonské
|
||||||
|
// znaky — v jeho latince ř, ž, č, ě… chybí a prohlížeč by je bral z jiného písma
|
||||||
|
--hg-font: 'Noto Serif', 'Shippori Mincho', 'Noto Serif JP', 'Georgia', serif;
|
||||||
--hg-crimson: #a3122a;
|
--hg-crimson: #a3122a;
|
||||||
--hg-crimson-deep: #7a0c1f;
|
--hg-crimson-deep: #7a0c1f;
|
||||||
--hg-crimson-shadow: #4a0612;
|
--hg-crimson-shadow: #4a0612;
|
||||||
|
|||||||
Reference in new issue
Block a user