Skip to content

Commit

Permalink
Merge pull request #9 from domihustinova/domi/remove-language-info
Browse files Browse the repository at this point in the history
Remove language info
  • Loading branch information
domihustinova authored May 23, 2024
2 parents 0d06b8f + 7715e31 commit 52da079
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 104 deletions.
4 changes: 2 additions & 2 deletions app/__test__/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("HomePage", () => {
).toBeVisible()
})

it("displays 6 recipe cards", () => {
expect(screen.getAllByRole("link")).toHaveLength(6)
it("displays 5 recipe cards", () => {
expect(screen.getAllByRole("link")).toHaveLength(5)
})
})
18 changes: 6 additions & 12 deletions app/helpers/__test__/getRecipesDetails.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mockedRecipes } from "@/testUtils/mockedRecipes"

import { getRecipesDetails } from "../getRecipesDetails"
import getRecipesDetails from "../getRecipesDetails"

jest.mock("../../../data/recipes.ts", () => ({
recipes: mockedRecipes,
Expand All @@ -14,39 +14,33 @@ describe("getRecipesDetails", () => {
{
category: "bread",
title: "title1",
caloriesInfo: "99 kcal/kus",
caloriesInfo: "99 kcal/piece",
href: "/dummy-recipe1",
},
{
category: "dessert",
title: "title2",
caloriesInfo: "600 kcal/piece",
caloriesInfo: "600 kcal/serving",
href: "/dummy-recipe2",
},
{
category: "main",
title: "title3",
caloriesInfo: "133 kcal/kus",
caloriesInfo: "133 kcal/piece",
href: "/dummy-recipe3",
},
{
category: "bread",
title: "title4",
caloriesInfo: "250 kcal/porce",
caloriesInfo: "700 kcal/serving",
href: "/dummy-recipe4",
},
{
category: "dessert",
title: "title5",
caloriesInfo: "85 kcal/serving",
caloriesInfo: "85 kcal/piece",
href: "/dummy-recipe5",
},
{
category: "main",
title: "title6",
caloriesInfo: "700 kcal/porcia",
href: "/dummy-recipe6",
},
])
})
})
25 changes: 7 additions & 18 deletions app/helpers/getRecipesDetails.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import { recipes } from "@/data/recipes"
import { RecipeDetail } from "@/types"

const amountOptions = {
piece: {
czech: "kus",
english: "piece",
slovak: "kus",
},
serving: {
czech: "porce",
english: "serving",
slovak: "porcia",
},
}

export const getRecipesDetails = (): RecipeDetail[] => {
return recipes.map(({ id, category, language, amount, totalKcal, title }) => {
const { count, type } = amount
const recalculatedKcal = Math.floor(totalKcal / count)
const getRecipesDetails = (): RecipeDetail[] => {
return recipes.map(({ id, category, yields, totalKcal, title }) => {
const { amount, type } = yields
const recalculatedKcal = Math.floor(totalKcal / amount)

return {
category: category,
title: title,
caloriesInfo: `${recalculatedKcal} kcal/${amountOptions[type][language]}`,
caloriesInfo: `${recalculatedKcal} kcal/${type}`,
href: `/${id}`,
}
})
}

export default getRecipesDetails
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react"

import RecipeDetailCard from "@/app/components/RecipeDetailCard"

import { getRecipesDetails } from "./helpers/getRecipesDetails"
import getRecipesDetails from "./helpers/getRecipesDetails"

const Home = () => {
const recipesDetails = getRecipesDetails()
Expand Down
71 changes: 34 additions & 37 deletions data/recipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,56 @@ import { Recipe } from "@/types"

export const recipes: Recipe[] = [
{
id: "kefirova-buchta",
id: "kefir-cake",
category: "dessert",
language: "czech",
time: 50,
totalKcal: 2589,
nutrients: {
protein: 61.4,
carbohydrates: 316.8,
fat: 115.9,
},
amount: { count: 8, type: "piece" },
title: "Kefírová buchta",
yields: { amount: 8, type: "piece" },
title: "Kefir cake",
ingredients: [
{ amount: "2", ingredient: "vejce", unitType: "count", unit: "piece" },
{ amount: "120", ingredient: "cukr", unitType: "weight", unit: "grams" },
{ amount: "100", ingredient: "řepkový olej", unitType: "weight", unit: "grams" },
{ amount: "380", ingredient: "kefír", unitType: "weight", unit: "grams" },
{ amount: "135", ingredient: "hrubá mouka", unitType: "weight", unit: "grams" },
{ amount: "2", ingredient: "eggs", unitType: "count", unit: "piece" },
{ amount: "120", ingredient: "sugar", unitType: "weight", unit: "grams" },
{ amount: "100", ingredient: "rapeseed oil", unitType: "weight", unit: "grams" },
{ amount: "380", ingredient: "kefir", unitType: "weight", unit: "grams" },
{ amount: "135", ingredient: "coarse flour", unitType: "weight", unit: "grams" },
{
amount: "130",
ingredient: "celozrnná hladká ječná mouka",
ingredient: "whole-wheat flour",
unitType: "weight",
unit: "grams",
},
{ amount: "2", ingredient: "kakao", unitType: "volume", unit: "tablespoon" },
{ amount: "1", ingredient: "jedlá soda", unitType: "volume", unit: "teaspoon" },
{ amount: "1", ingredient: "sůl", unitType: "count", unit: "pinch" },
{ amount: "2", ingredient: "cocoa", unitType: "volume", unit: "tablespoon" },
{ amount: "1", ingredient: "baking soda", unitType: "volume", unit: "teaspoon" },
{ amount: "1", ingredient: "salt", unitType: "count", unit: "pinch" },
],
extraIngredients: [
"moučkový cukr na posypání",
"máslo na vymazání formy, strouhanka nebo hrubá mouka na vysypání",
"powdered sugar for sprinkling",
"butter for greasing the form, breadcrumbs or coarse flour for dusting",
],
instructions: [
"Troubu rozehřejte na 200 °C, kulatou formu vymažte máslem a vysypte hrubou moukou nebo strouhankou.",
"Vejce dobře prošlehejte s cukrem (můžete šlehat ručně kuchyňskou metlou), přilijte olej nebo máslo a nakonec i kefír. Důkladně prošlehejte, aby se všechny suroviny dobře spojily. Aby byl výsledek perfektní, pro jistotu si všechny studené suroviny vyndejte z lednice 30 minut předem.",
"V jiné misce si smíchejte obě mouky, kakao, jedlou sodu a špetku soli. Sypké suroviny můžete prosít, budou vzdušnější.Pokud jste na prosívání líní, alespoň je dobře promíchejte suchou metlou. Ta vás alespoň částečně zbaví hrudek a mouku provzdušní.",
"Nyní vešlehejte „suché“ ingredience po částech do těch „mokrých“. Míchejte jen tak dlouho, aby se spojily v hladké těsto.Pracujete se sodou, proto neztrácejte čas a nevymíchávejte těsto příliš dlouho, připravíte se tak o bublinky.",
"Těsto nalijte do připravené koláčové formy, vložte do předehřáté trouby a teplotu pečení snižte na 180 °C. Pečte přibližně 30-35 minut, ke konci pečení zkontrolujte dřevěnou špejlí nebo párátkem. Vyjde-li z těsta čisté a bez drobečků, máte hotovo.",
"Preheat the oven to 200 °C, grease a round form with butter and dust with coarse flour or breadcrumbs.",
"Beat the eggs well with the sugar (you can beat by hand with a kitchen whisk), add the oil or butter and finally the kefir. Whisk thoroughly to combine all the ingredients well. To ensure the best result, take all the cold ingredients out of the fridge 30 minutes beforehand.",
"In another bowl, mix both flours, cocoa, baking soda, and a pinch of salt. You can sift the dry ingredients to make them more airy. If you are too lazy to sift, at least mix them well with a dry whisk. This will help eliminate lumps and aerate the flour.",
"Now whisk the 'dry' ingredients into the 'wet' ones in parts. Mix just until they combine into a smooth batter. Since you are working with baking soda, don't waste time and don't overmix the batter to preserve the bubbles.",
"Pour the batter into the prepared cake form, place it in the preheated oven, and reduce the baking temperature to 180 °C. Bake for approximately 30-35 minutes, and towards the end of baking, check with a wooden skewer or toothpick. If it comes out clean and without crumbs, the cake is done.",
],
credit: "https://karolinafour.cz/recepty/rychla-kefirova-buchta/",
},
{
id: "pancakes-batter",
category: "dessert",
language: "english",
totalKcal: 1675,
nutrients: {
protein: 59.8,
carbohydrates: 199.5,
fat: 69,
},
amount: { count: 9, type: "piece" },
yields: { amount: 9, type: "piece" },
title: "Pancakes batter",
ingredients: [
{ amount: "3", ingredient: "eggs", unitType: "count", unit: "piece" },
Expand All @@ -73,31 +71,30 @@ export const recipes: Recipe[] = [
},

{
id: "housky",
id: "buns",
category: "bread",
language: "czech",
totalKcal: 1864,
nutrients: {
protein: 47.9,
carbohydrates: 302.6,
fat: 46.7,
},
amount: { count: 8, type: "piece" },
title: "Housky",
yields: { amount: 8, type: "piece" },
title: "Buns",
ingredients: [
{ amount: "400", ingredient: "hladká mouka", unitType: "weight", unit: "grams" },
{ amount: "200", ingredient: "voda", unitType: "weight", unit: "grams" },
{ amount: "50", ingredient: "řepkový olej/máslo", unitType: "weight", unit: "grams" },
{ amount: "1", ingredient: "cukr", unitType: "volume", unit: "teaspoon" },
{ amount: "1", ingredient: "sůl", unitType: "volume", unit: "teaspoon" },
{ amount: "25", ingredient: "droždí", unitType: "weight", unit: "grams" },
{ amount: "400", ingredient: "all-purpose flour", unitType: "weight", unit: "grams" },
{ amount: "200", ingredient: "water", unitType: "weight", unit: "grams" },
{ amount: "50", ingredient: "rapeseed oil", unitType: "weight", unit: "grams" },
{ amount: "1", ingredient: "sugar", unitType: "volume", unit: "teaspoon" },
{ amount: "1", ingredient: "salt", unitType: "volume", unit: "teaspoon" },
{ amount: "25", ingredient: "yeast", unitType: "weight", unit: "grams" },
],
instructions: [
"Vše dáme do mixéru s hákem a vypracujeme těsto.",
"Přendáme na vál, lehce pomoučníme.",
"Rozdělíme na 8 dílů a z každého vytvarujeme housky.",
"Troubu předehřejeme na 230 stupňů a než se trouba předehřeje jsou pletýnky nakynuté",
"Pečeme cca 12 minut dozlatova",
"Put everything into a mixer with a hook and work the dough.",
"Transfer to a work surface, lightly flour.",
"Divide into 8 parts and shape each into rolls.",
"Preheat the oven to 230 degrees and while the oven is preheating, the rolls will rise.",
"Bake for about 12 minutes until golden brown.",
],
},
]
12 changes: 11 additions & 1 deletion tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Config } from "tailwindcss"
import plugin from "tailwindcss/plugin"

const config: Config = {
content: [
Expand All @@ -21,6 +22,7 @@ const config: Config = {
dark: "#4A5759",
medium: "#B0C4B1",
light: "#DEDBD2",
lightest: "#EBEAE4",
},
red: {
primary: "#d8003e",
Expand All @@ -31,8 +33,16 @@ const config: Config = {
primary: "#ffd634",
},
},
backgroundImage: {
defaultGreen:
"linear-gradient(to right bottom, #dedbd2, #d5d5c8, #cacfbf, #bec9b7, #b0c4b1)",
},
},
},
plugins: [],
plugins: [
plugin(function ({ addVariant }) {
addVariant("hocus", ["&:hover", "&:focus"])
}),
],
}
export default config
30 changes: 7 additions & 23 deletions testUtils/mockedRecipes.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,39 @@
import { Recipe } from "@/types"

export const mockedRecipes: Pick<
Recipe,
"id" | "category" | "language" | "amount" | "totalKcal" | "title"
>[] = [
export const mockedRecipes: Pick<Recipe, "id" | "category" | "yields" | "totalKcal" | "title">[] = [
{
id: "dummy-recipe1",
category: "bread",
language: "czech",
amount: { count: 2, type: "piece" },
yields: { amount: 2, type: "piece" },
totalKcal: 199,
title: "title1",
},
{
id: "dummy-recipe2",
category: "dessert",
language: "english",
amount: { count: 3, type: "piece" },
yields: { amount: 3, type: "serving" },
totalKcal: 1800,
title: "title2",
},
{
id: "dummy-recipe3",
category: "main",
language: "slovak",
amount: { count: 3, type: "piece" },
yields: { amount: 3, type: "piece" },
totalKcal: 400,
title: "title3",
},
{
id: "dummy-recipe4",
category: "bread",
language: "czech",
amount: { count: 2, type: "serving" },
totalKcal: 500,
yields: { amount: 1, type: "serving" },
totalKcal: 700,
title: "title4",
},
{
id: "dummy-recipe5",
category: "dessert",
language: "english",
amount: { count: 7, type: "serving" },
yields: { amount: 7, type: "piece" },
totalKcal: 600,
title: "title5",
},
{
id: "dummy-recipe6",
category: "main",
language: "slovak",
amount: { count: 1, type: "serving" },
totalKcal: 700,
title: "title6",
},
]
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noImplicitAny": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
Expand Down
25 changes: 15 additions & 10 deletions types/index.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
export type Category = "bread" | "dessert" | "main"

export type Language = "czech" | "english" | "slovak"

type Nutrients = {
protein: number
carbohydrates: number
fat: number
}

export type Amount = {
count: number
export type Yields = {
amount: number
type: "serving" | "piece"
}

export type UnitType = "count" | "volume" | "weight"

export type CountUnit = "piece" | "pinch"

type CountUnitType = {
unitType: "count"
unit: "piece" | "pinch"
unit: CountUnit
}

export type VolumeUnit = "teaspoon" | "tablespoon" | "millilitre" | "litre"

type VolumeUnitType = {
unitType: "volume"
unit: "teaspoon" | "tablespoon" | "millilitre" | "litre"
unit: VolumeUnit
}

export type WeightUnit = "grams" | "kilograms"

type WeightUnitType = {
unitType: "weight"
unit: "grams" | "kilograms"
unit: WeightUnit
}

type Ingredient = {
export type Ingredient = {
amount: string
ingredient: string
} & (CountUnitType | VolumeUnitType | WeightUnitType)

export type Recipe = {
id: string
category: Category
language: Language
time?: number
totalKcal: number
nutrients: Nutrients
amount: Amount
yields: Yields
title: string
ingredients: Ingredient[]
extraIngredients?: string[]
Expand Down

0 comments on commit 52da079

Please sign in to comment.