Skip to content

Commit

Permalink
Merge branch 'main' of github.com:seasonfood/seasonfood
Browse files Browse the repository at this point in the history
  • Loading branch information
aivuk committed Aug 17, 2023
2 parents 00db8df + 1abe69b commit 5c2f7e5
Show file tree
Hide file tree
Showing 13 changed files with 454 additions and 468 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"FoodOfTheMonth_fruitsNumber_other": "{{fruits}} fruits",
"FoodOfTheMonth_veggiesNumber_one": "and {{veggies}} veggie in season",
"FoodOfTheMonth_veggiesNumber_other": "and {{veggies}} veggies in season",
"FoodPage_notInSeasonText": "Not in season, check below when it's best to buy it.",
"FoodPage_notInSeasonText": "Not in season",
"FoodPage_inSeasonText": "Currently in season",
"FoodPage_checkMonths": "Check below when it's best to buy it.",
"FoodPage_monthsInSeason": "Months in season",
"backButton": "back",
"month_0": "January",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/it/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"FoodOfTheMonth_fruitsNumber_other": "{{fruits}} frutti",
"FoodOfTheMonth_veggiesNumber_one": "e {{veggies}} verdura di stagione",
"FoodOfTheMonth_veggiesNumber_other": "e {{veggies}} verdure di stagione",
"FoodPage_notInSeasonText": "Non è di stagione, controllate qui sotto quando è meglio acquistarlo.",
"FoodPage_notInSeasonText": "Non è di stagione",
"FoodPage_inSeasonText": "Attualmente è in stagione",
"FoodPage_checkMonths": "controllate qui sotto quando è meglio acquistarlo.",
"FoodPage_monthsInSeason": "Mesi di stagione",
"backButton": "indietro",
"month_0": "Gennaio",
Expand Down
107 changes: 52 additions & 55 deletions src/components/HeaderBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { FoodList, FoodObject } from "../types/food";
import Fuse from 'fuse.js'
import { useRef, useEffect } from "react"
import { useNavigate, useLocation } from "react-router-dom";
import i18next from "i18next";
import { useTranslation } from "react-i18next";
import { ArrowBackIosNew, Menu, Search } from "@mui/icons-material";
import {
AppBar,
styled,
Expand All @@ -8,13 +13,6 @@ import {
IconButton,
InputBase,
} from "@mui/material";
import MenuIcon from "@mui/icons-material/Menu";
import SearchIcon from "@mui/icons-material/Search";
import { useTranslation } from "react-i18next";
import { ArrowBackIosNew } from "@mui/icons-material";
import Fuse from 'fuse.js'
import { useRef, useEffect } from "react"
import { useNavigate, useLocation } from "react-router-dom";

type Props = {
ifSearched: boolean;
Expand Down Expand Up @@ -61,20 +59,53 @@ export default function HeaderBar(props: Props) {
return fuse.search(searchLanguage).map((i) => i.item)
};

const Search = styled("div")(({ theme }) => ({
const navigate = useNavigate();
const location = useLocation();

function leftButton() {
if (location.pathname.split("/")[1] === "foodpage") {
return (
<IconButton
size="large"
edge="start"
color="inherit"
aria-label="return"
onClick={() => navigate(-1)}
>
<ArrowBackIosNew />
</IconButton>
);
}
return (
<IconButton
size="large"
edge="start"
color="inherit"
aria-label="open drawer"
onClick={props.toggleDrawer}
>
<Menu />
</IconButton>
);
}

const SearchBar = styled("div")(({ theme }) => ({
position: "relative",
borderRadius: theme.shape.borderRadius,
backgroundColor: alpha(theme.palette.common.white, 0.15),
"&:hover": {
backgroundColor: alpha(theme.palette.common.white, 0.25),
},
"&:focus": {
backgroundColor: alpha(theme.palette.common.white, 0.25),
},
marginLeft: "auto",
width: "auto",
}));

const SearchIconWrapper = styled("div")(({ theme }) => ({
padding: theme.spacing(0, 2),
const SearchIconWrapper = styled("div")(() => ({
height: "100%",
aspectRatio: 1,
position: "absolute",
pointerEvents: "none",
display: "flex",
Expand All @@ -86,66 +117,32 @@ export default function HeaderBar(props: Props) {
color: "inherit",
"& .MuiInputBase-input": {
padding: theme.spacing(1, 1, 1, 0),
// vertical padding + font size from searchIcon
paddingLeft: `calc(1em + ${theme.spacing(4)})`,
transition: theme.transitions.create("width"),
width: "12ch",
paddingLeft: `calc(1em + ${theme.spacing(3)})`,
transition: theme.transitions.create("max-width"),
width: "100%",
maxWidth: "0ch",
"&:focus": {
width: "20ch",
maxWidth: "20ch",
},
},
}));

const StyledAppBar = styled(AppBar)(() => ({
borderRadius: "2%",
background: 'primary.main' ,
marginTop: "0",
}));

const navigate = useNavigate();
const location = useLocation();

function leftButton() {
if (location.pathname.split("/")[1] === "foodpage") {
return (
<IconButton
size="large"
edge="start"
color="inherit"
aria-label="open drawer"
onClick={() => navigate(-1)}
>
<ArrowBackIosNew />
</IconButton>
);
}
return (
<IconButton
size="large"
edge="start"
color="inherit"
aria-label="open drawer"
onClick={props.toggleDrawer}
>
<MenuIcon />
</IconButton>
);
}

return (
<StyledAppBar position="static">
<AppBar position="static" sx={{mb: 1, backgroundColor:"primary.dark"}}>
<Toolbar>
{leftButton()}
<Search>
<SearchBar>
<SearchIconWrapper>
<IconButton
sx={{m: 0}}
size="large"
edge="start"
color="inherit"
aria-label="open drawer"
sx={{ mr: 2 }}
>
<SearchIcon type="submit" />
<Search />
</IconButton>
</SearchIconWrapper>
<form onSubmit={(e) => handleSubmit(e)}>
Expand All @@ -156,8 +153,8 @@ export default function HeaderBar(props: Props) {
id="search-bar"
/>
</form>
</Search>
</SearchBar>
</Toolbar>
</StyledAppBar>
</AppBar>
);
}
59 changes: 36 additions & 23 deletions src/components/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
import type { FoodObject } from "../types/food"
import type { FoodObject } from "../types/food";

import { Link } from "react-router-dom";
import { Box, Typography, styled } from "@mui/material";
import { Box, Stack, Typography, styled } from "@mui/material";
import { useTranslation } from "react-i18next";


const ImgBox = styled(Box)(({ theme }) => ({
const ImgBox = styled(Stack)(({ theme }) => ({
borderRadius: theme.shape.borderRadius,
width: "6em",
width: "100%",
aspectRatio: 1,
boxShadow: "3px 4px 8px #888888",
textAlign: "center",
backgroundColor:"#fefefe",
[theme.breakpoints.down("xs")]: {
width: "115px",
},
overflow: "clip",
color: theme.palette.primary.light,
backgroundColor: theme.palette.primary.main,

}));

function Item(props: FoodObject) {
const { t } = useTranslation()
const { t } = useTranslation();
const image = props.image.toLowerCase();
return (
<Link to={`/foodpage/${props.description[0].slug}`}>
<ImgBox>
<img
className="food-image"
src={`../images/${image}.png`}
alt={`image of ${image}`}
/>
<Typography sx={{ paddingBottom: "0.25em" }}>
{t(props.description[0].name)}
</Typography>
</ImgBox>
</Link>
<Box
sx={{ flexGrow: 1, width: "100%", maxWidth: "30%", minWidth: 90 }}
>
<Link to={`/foodpage/${props.description[0].slug}`}>
<ImgBox>
<Box position="relative" flexGrow={1}>
<img
className="food-image"
src={`../images/${image}.png`}
alt={`image of ${image}`}
/>
</Box>
<Box position="relative" height="20%" sx={{ textAlign: 'center'}}>
<Typography

top={0}
fontSize="max(1rem, min(4.5vw, 3rem))"
fontWeight={400}
sx={{ p: "0.25em", transform: "translateY(-20%)" }}
>
{t(props.description[0].name)}
</Typography>
</Box>
</ImgBox>
</Link>
</Box>
);
}

Expand Down
10 changes: 4 additions & 6 deletions src/components/RenderFoods.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FoodList } from "../types/food";
import Item from "./Item";
import { Box, Stack } from "@mui/material";
import { Stack } from "@mui/material";
import { FunctionComponent } from "react";

interface RenderFoodProps {
Expand All @@ -14,15 +14,13 @@ interface RenderFoodProps {
//render the grid of foods
const RenderFoods:FunctionComponent<RenderFoodProps> = (props:RenderFoodProps) => {
const foodList = props.foodList
const foodItems = foodList.map((item, key) => {
const foodItems = foodList.map((item ) => {
return (
<Box sx={{mb: 1, mx: '5px', display: 'flex', flexGrow: 1, justifyContent: "center"}} key={key}>
<Item {...item} />
</Box>
<Item {...item} />
);
});
return (
<Stack direction="row" flexWrap="wrap">
<Stack direction="row" flexWrap="wrap" justifyContent="space-between" gap={1.5}>
{foodItems}
</Stack>
);
Expand Down
Loading

0 comments on commit 5c2f7e5

Please sign in to comment.