diff --git a/client/src/components/recipe/RecipeDetail.tsx b/client/src/components/recipe/RecipeDetail.tsx index 6e310ff..1517048 100644 --- a/client/src/components/recipe/RecipeDetail.tsx +++ b/client/src/components/recipe/RecipeDetail.tsx @@ -1,6 +1,7 @@ import type { Recipe } from '../../types/recipe'; import RestaurantIcon from '@mui/icons-material/Restaurant'; import AccessTimeIcon from '@mui/icons-material/AccessTime'; +import { useState } from 'react'; import { Rating } from '@mui/material'; import Checkbox from '@mui/material/Checkbox'; import FormControlLabel from '@mui/material/FormControlLabel'; @@ -11,6 +12,14 @@ type RecipeDetailProps = { }; export function RecipeDetail({ recipe }: RecipeDetailProps) { + const [checkedIds, setCheckedIds] = useState([]); + + function toggeIngredient(id: string) { + setCheckedIds((prev)=> + prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id] + ); + } + return (
@@ -55,13 +64,19 @@ export function RecipeDetail({ recipe }: RecipeDetailProps) { toggeIngredient(ingredient.id)} sx={{ - color: 'var(--color-olive)', - '&.Mui-checked': { color: 'var(--color-olive)' }, + color: 'var(--color-primary)', + '&.Mui-checked': { color: 'var(--color-primary)' }, }} /> } - label={`${ingredient.amount} ${ingredient.unit} ${ingredient.name}`} + label={ + + {`${ingredient.amount} ${ingredient.unit} ${ingredient.name}`} + + } /> ))} @@ -76,8 +91,8 @@ export function RecipeDetail({ recipe }: RecipeDetailProps) { control={ } diff --git a/client/src/components/slideshow/RecipeSlideshow.tsx b/client/src/components/slideshow/RecipeSlideshow.tsx index 9f9ec76..93333bd 100644 --- a/client/src/components/slideshow/RecipeSlideshow.tsx +++ b/client/src/components/slideshow/RecipeSlideshow.tsx @@ -2,35 +2,41 @@ import type { Recipe } from '../../types/recipe'; import useEmblaCarousel from 'embla-carousel-react'; import { Link } from 'react-router'; import { useEffect, useState } from 'react'; +import Autoplay from 'embla-carousel-autoplay'; import AccessTimeIcon from '@mui/icons-material/AccessTime'; import RestaurantIcon from '@mui/icons-material/Restaurant'; import ArrowForwardIcon from '@mui/icons-material/ArrowForward'; import ArrowBackIcon from '@mui/icons-material/ArrowBack'; - -// Fargetemaer for slidesene. panel er tekstboksen, button er knappen for å se en oppskrift -type SlideshowTheme = 'light' | 'dark' | 'rose'; - -const themes = { - light: { panel: 'bg-secondary/50 text-olive-dark', button: 'bg-olive-dark text-background', dot: 'border-olive-dark', dotActive: 'bg-olive-dark' }, - dark: { panel: 'bg-olive-dark text-background', button: 'bg-pink-light text-olive-dark', dot: 'border-background', dotActive: 'bg-background' }, - rose: { panel: 'bg-pink text-pink-light', button: 'bg-primary-hover text-pink-light', dot: 'border-background', dotActive: 'bg-background' }, -} +import PauseIcon from '@mui/icons-material/Pause'; +import PlayArrowIcon from '@mui/icons-material/PlayArrow'; type RecipeSlideshowProps = { - recipes: Recipe[]; - reversed?: boolean; // Denne er valgfri, og gjør at karusellen i midten er speilvendt - theme?: SlideshowTheme; + recipes: Recipe[]; }; // Slideshow på forsiden som viser én oppskrift av gangen. // Det er mulig å bla med piler, prikkene, sveiping eller med tastaturet. -export function RecipeSlideshow({ recipes, reversed = false, theme = 'light' }: RecipeSlideshowProps) { +export function RecipeSlideshow({ recipes }: RecipeSlideshowProps) { // emblaRef kobler Embla opp til vinduet, også brukes emblaAPI til å styre slideshowet. - const [emblaRef, emblaApi] = useEmblaCarousel({ loop: true }); + const [emblaRef, emblaApi] = useEmblaCarousel({ loop: true }, [ + Autoplay({ delay: 5000, stopOnMouseEnter: true, stopOnFocusIn: true}), + ]); // Husker hvilken av sidene i slideshowet som vises, sånn at riktig prikk blir farget inn. const [selectedIndex, setSelectedIndex] = useState(0); - const colors = themes[theme]; + const [isPlaying, setIsPlaying] = useState(true); + + function togglePlay() { + const autoplay = emblaApi?.plugins().autoplay; + if(!autoplay) return; + + if (isPlaying) { + autoplay.stop(); + } else { + autoplay.play(); + } + setIsPlaying(!isPlaying); + } // Oppdaterer selectedIndex hver gang det byttes hvilken side som vises. useEffect(() => { @@ -45,7 +51,7 @@ export function RecipeSlideshow({ recipes, reversed = false, theme = 'light' }: }, [emblaApi]); return ( -
+
{/* Vinduet: det skjuler slidene som ikke vises */}
{/* Raden med alle slidene som Embla flytter sidelengs */} @@ -53,10 +59,15 @@ export function RecipeSlideshow({ recipes, reversed = false, theme = 'light' }: {recipes.map((recipe) => ( // Én slide som bruker hele bredden i vinduet
-
- {/* Tomt alternativ for bildet, ettersom tittelen allerede står rett ved siden av bildet. */} - -
+
+
+
+ UKENS OPPSKRIFT +

{recipe.title}

{recipe.description}

@@ -70,8 +81,10 @@ export function RecipeSlideshow({ recipes, reversed = false, theme = 'light' }: ))} - Se oppskrift + Se oppskrift
+ {/* Tomt alternativ for bildet, ettersom tittelen allerede står rett ved siden av bildet. */} +
))} @@ -83,7 +96,7 @@ export function RecipeSlideshow({ recipes, reversed = false, theme = 'light' }: type="button" aria-label="Forrige oppskrift" onClick={() => emblaApi?.scrollPrev()} - className="absolute left-4 top-1/2 -translate-y-1/2 flex h-12 w-12 items-center justify-center rounded-full bg-background/80 hover:bg-background focus-visible:outline-2 focus-visible:outline-primary" + className="absolute left-0 top-1/2 -translate-y-1/2 flex h-12 w-12 items-center justify-center rounded-full bg-background/80 hover:bg-background focus-visible:outline-2 focus-visible:outline-primary" > @@ -91,13 +104,13 @@ export function RecipeSlideshow({ recipes, reversed = false, theme = 'light' }: type="button" aria-label="Neste oppskrift" onClick={() => emblaApi?.scrollNext()} - className="absolute right-4 top-1/2 -translate-y-1/2 flex h-12 w-12 items-center justify-center rounded-full bg-background/80 hover:bg-background focus-visible:outline-2 focus-visible:outline-primary" + className="absolute right-0 top-1/2 -translate-y-1/2 flex h-12 w-12 items-center justify-center rounded-full bg-background/80 hover:bg-background focus-visible:outline-2 focus-visible:outline-primary" > {/* Prikker: én prikk per oppskrift. Den siden som vises er fylt inn. Dersom du trykker på en annen prikk hopper du til den siden. */} -
+
{recipes.map((recipe, index) => (
); diff --git a/client/src/routes/HomePage.tsx b/client/src/routes/HomePage.tsx index bbbdac4..1353b24 100644 --- a/client/src/routes/HomePage.tsx +++ b/client/src/routes/HomePage.tsx @@ -12,10 +12,10 @@ export default function HomePage() { return (
-
+
- +