From 5e76c404fb5199d358f99ce694698a5ce5ec8136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20And=C4=9Bl?= Date: Thu, 5 Nov 2026 12:11:45 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20skryt=C3=A9=20tagu=20"chut=C4=9B"=20fix:?= =?UTF-8?q?=20zm=C4=9Bna=20form=C3=A1tu=20pdf=20recept=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/MealGroupRow.tsx | 3 - client/src/recipePdf.ts | 129 +++++++++++++++++-------- 2 files changed, 91 insertions(+), 41 deletions(-) diff --git a/client/src/components/MealGroupRow.tsx b/client/src/components/MealGroupRow.tsx index ae788eb..eaa8f65 100644 --- a/client/src/components/MealGroupRow.tsx +++ b/client/src/components/MealGroupRow.tsx @@ -67,9 +67,6 @@ const MealGroupRow = ({ {group.recipe.category ?? 'recept'} )} - {group.recipe?.flavor === RecipeFlavor.SLADKE && ( - {RECIPE_FLAVOR_NAMES[RecipeFlavor.SLADKE].toLowerCase()} - )} {group.missingCaloriesCount > 0 && ( bez kalorií {describeMissing(group.missingCaloriesCount, group.count)} diff --git a/client/src/recipePdf.ts b/client/src/recipePdf.ts index f85af6d..b157f4d 100644 --- a/client/src/recipePdf.ts +++ b/client/src/recipePdf.ts @@ -10,7 +10,7 @@ import { /** Recept s počtem fotek jídla — fotky se stahují jen tam, kde nějaké jsou. */ type RecipeItem = Pick & { recipe: MealTemplate }; -const PRIMARY_COLOR = '#15803d'; +const PRIMARY_COLOR = '#156080'; const MUTED_COLOR = '#6b7280'; const BORDER_COLOR = '#e5e7eb'; /** Šířka tisknutelné plochy A4 při okrajích 40 pt. */ @@ -63,25 +63,21 @@ const createLinks = (recipe: MealTemplate, recipeList: MealTemplate[], indexMap: return [{ text: [{ text: `${RECIPE_LINK_NAMES[kind]}: `, bold: true }, ...nameList], style: 'recipeLinks' }]; }); -/** První fotka přes celou šířku, ostatní menší v řadách po třech. */ +const PHOTO_COLUMN_WIDTH = 220; const createPhotos = (photoList: MealPhoto[]): Content[] => { - const [first, ...rest] = photoList; - if (!first) return []; - const result: Content[] = [{ image: first.image, fit: [CONTENT_WIDTH, 240], alignment: 'center', margin: [0, 0, 0, PHOTO_GAP] }]; - const smallWidth = (CONTENT_WIDTH - PHOTO_GAP * (SMALL_PHOTOS_PER_ROW - 1)) / SMALL_PHOTOS_PER_ROW; - for (let start = 0; start < rest.length; start += SMALL_PHOTOS_PER_ROW) { - const rowList = rest.slice(start, start + SMALL_PHOTOS_PER_ROW); - result.push({ - columns: [ - ...rowList.map(photo => ({ image: photo.image, fit: [smallWidth, 130] as [number, number], width: smallWidth })), - // Nedoplněná řada si drží šířku sloupců - ...Array.from({ length: SMALL_PHOTOS_PER_ROW - rowList.length }, () => ({ text: '', width: smallWidth })), - ], - columnGap: PHOTO_GAP, - margin: [0, 0, 0, PHOTO_GAP], - }); + const first = photoList[0]; + + if (!first) { + return []; } - return result; + + return [ + { + image: first.image, + width: PHOTO_COLUMN_WIDTH, + alignment: 'center', + }, + ]; }; const createIngredients = (recipe: MealTemplate): Content[] => { @@ -131,26 +127,83 @@ type RecipeContext = { const createRecipe = ( recipe: MealTemplate, photoList: MealPhoto[], { index, withToc, recipeList, indexMap }: RecipeContext, -): Content => ({ - stack: [ - { - text: recipe.name, - style: 'recipeTitle', - id: getRecipeAnchor(index), - tocItem: withToc, - }, - ...(recipe.source ? [{ text: recipe.source, style: 'recipeSource' }] : []), - { text: getRecipeMeta(recipe), style: 'recipeMeta' }, - ...createLinks(recipe, recipeList, indexMap), - ...createPhotos(photoList), - ...createIngredients(recipe), - ...(recipe.note?.trim() - ? [{ text: 'Postup', style: 'sectionHeading' }, ...convertMarkdownToPdf(recipe.note)] - : []), - ], - // Každý recept začíná na nové stránce, první hned za obsahem - ...(index > 0 || withToc ? { pageBreak: 'before' as const } : {}), -}); +): Content => { + const hasPhotos = photoList.length > 0; + return ({ + stack: [ + ...(hasPhotos + ? [{ + columns: [ + { + width: '*', + stack: [ + { + text: recipe.name, + style: 'recipeTitle', + id: getRecipeAnchor(index), + tocItem: withToc, + }, + + ...(recipe.source + ? [{ text: recipe.source, style: 'recipeSource' }] + : []), + + { + text: getRecipeMeta(recipe), + style: 'recipeMeta', + }, + + ...createLinks(recipe, recipeList, indexMap), + ...createIngredients(recipe), + ], + }, + + { + width: 220, + stack: createPhotos(photoList), + }, + ], + columnGap: 20, + }] + : [ + { + text: recipe.name, + style: 'recipeTitle', + id: getRecipeAnchor(index), + tocItem: withToc, + }, + + ...(recipe.source + ? [{ text: recipe.source, style: 'recipeSource' }] + : []), + + { + text: getRecipeMeta(recipe), + style: 'recipeMeta', + }, + + ...createLinks(recipe, recipeList, indexMap), + ...createIngredients(recipe), + ]), + + ...(recipe.note?.trim() + ? [ + { + text: 'Postup', + style: 'sectionHeading', + }, + ...convertMarkdownToPdf(recipe.note), + ] + : []), + ], + + // Každý recept začíná na nové stránce, první hned za obsahem + + ...(index > 0 || withToc + ? { pageBreak: 'before' as const } + : {}), + }); +} const loadPhotos = async (item: RecipeItem): Promise => { if (!item.photoCount) return [];