Skip to content

Commit

Permalink
code-formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
g-marcin committed Jun 25, 2023
1 parent 8f14509 commit 67c6af8
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 80 deletions.
3 changes: 1 addition & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'bootstrap/dist/css/bootstrap.css';
import { RouterProvider } from 'react-router-dom';
import { ThemeContextProvider } from './contexts';
import { AppRouter } from './router';

import 'bootstrap/dist/css/bootstrap.css';

function App() {
return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./CustomPagination";
export * from './CustomPagination';
export * from './Loader';
export * from './layout';
32 changes: 16 additions & 16 deletions src/components/layout/CustomOffcanvas/CustomOffcanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@ type CustomOffcanvasProps = {
handleClose: () => void;
};

export const CustomOffcanvas: FC<CustomOffcanvasProps> = ({ show, handleClose, ...props }) => {
export const CustomOffcanvas: FC<CustomOffcanvasProps> = ({ show, handleClose, ...props }) => {
const { isDark, setIsDark } = useContext(ThemeContext);

return (
<>
<ReactFocusLock>
<Offcanvas show={show} onHide={handleClose} className={styles.offcanvas} {...props} placement={'end'}>
<ReactFocusLock>
<Offcanvas show={show} onHide={handleClose} className={styles.offcanvas} {...props} placement={'end'}>
<Offcanvas.Header closeButton>
<Offcanvas.Title>Menu:</Offcanvas.Title>
</Offcanvas.Header>
<Offcanvas.Body>
<div className={styles["menu-item"]}>
<div className={styles['menu-item']}>
Toggle page theme:
{isDark ? (
<button className={styles.button}>
<Sun size={36} onClick={() => setIsDark(isDark)} />
</button>
) : (
<button className={styles.button} onClick={() => setIsDark(isDark)}>
<Moon size={36} color='#000000' />
</button>
)}
</div>
{isDark ? (
<button className={styles.button}>
<Sun size={36} onClick={() => setIsDark(isDark)} />
</button>
) : (
<button className={styles.button} onClick={() => setIsDark(isDark)}>
<Moon size={36} color="#000000" />
</button>
)}
</div>
</Offcanvas.Body>
</Offcanvas>
</ReactFocusLock>
</Offcanvas>
</ReactFocusLock>
</>
);
};
4 changes: 2 additions & 2 deletions src/components/layout/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const Header: FC = () => {
<Menu className={styles.menu} color="#ffffff" />
</button>
</header>
<SubHeader/>
<CustomOffcanvas name={'hamburger-menu'} show={show} handleClose={handleClose} handleShow={handleShow} />
<SubHeader />
<CustomOffcanvas name={'hamburger-menu'} show={show} handleClose={handleClose} handleShow={handleShow} />
</>
);
};
45 changes: 25 additions & 20 deletions src/components/layout/SubHeader/SubHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import { FC } from "react";
import { NavLink, useParams } from "react-router-dom";
import { useBeerDetails } from "../../../hooks/useBeerDetails";
import styles from "./subheader.module.css";
import { FC } from 'react';
import { NavLink, useParams } from 'react-router-dom';
import { useBeerDetails } from '../../../hooks/useBeerDetails';
import styles from './subheader.module.css';

export const SubHeader: FC = () => {
const {id} = useParams()
const{beerDetails, isLoading} = useBeerDetails(id)
if(!beerDetails){
return
}
const { id } = useParams();
const { beerDetails, isLoading } = useBeerDetails(id);
if (!beerDetails) {
return;
}

return (
<nav className={`${styles.nav} text-decoration-none`}>
{
<NavLink
to="/"
className={`${styles.homeCrumb} text-decoration-none`}
>
Home
<NavLink to="/" className={`${styles.homeCrumb} text-decoration-none`}>
Home
</NavLink>
}
{isLoading? "": <>
{id? <NavLink to={`/details/${id}`} className={`${styles.authorCrumb} text-decoration-none`}>
{"> "}
{beerDetails.name}
</NavLink>: ""}
</>}
{isLoading ? (
''
) : (
<>
{id ? (
<NavLink to={`/details/${id}`} className={`${styles.authorCrumb} text-decoration-none`}>
{'> '}
{beerDetails.name}
</NavLink>
) : (
''
)}
</>
)}
</nav>
);
};
2 changes: 1 addition & 1 deletion src/components/layout/SubHeader/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./SubHeader";
export * from './SubHeader';
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useBeerDetails';
16 changes: 8 additions & 8 deletions src/hooks/useBeerDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ import { httpClient } from '../common';
import { BeerType, beerDataDTO } from '../types';
import { beerDetailsMapper } from './beerDetailsMapper';

export const useBeerDetails = (id:string|undefined) => {
export const useBeerDetails = (id: string | undefined) => {
const [beerDetails, setBeerDetails] = useState<BeerType>();
const [isLoading, setIsLoading] = useState(false);

useEffect(() => {
if (!id) {
return;
}
setIsLoading(true);
httpClient
.get(`/beers?ids=${id?id:""}`)
.get(`/beers?ids=${id}`)
.then((response: AxiosResponse<beerDataDTO[]>) => {
if (response.data) {
setBeerDetails(beerDetailsMapper(response.data));
}else{
throw new Error("no details data recieved")
} else {
throw new Error('no details data recieved');
}
setIsLoading(false)
})
.then(() => setIsLoading(false))
.catch(() => {
return;
});

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [id]);
return { beerDetails: beerDetails, isLoading: isLoading };
};
17 changes: 13 additions & 4 deletions src/modules/BeerBrowser/BeerBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { beerDataMapper } from './beerDataMapper';

const BeerBrowser: FC = () => {
const [isLoading, setIsLoading] = useState(false);
const [page, setPage] = useState(1);
const [page, setPage] = useState<number | undefined>();
const setPageHandler = (page: number) => {
setPage(page);
};
Expand All @@ -19,7 +19,7 @@ const BeerBrowser: FC = () => {
useEffect(() => {
setIsLoading(true);
httpClient
.get(`/beers?page=${page}&per_page=9`)
.get(`/beers?page=${page || 1}&per_page=9`)
.then((response: AxiosResponse<beerDataDTO[]>) => {
setBeerData(beerDataMapper(response.data));
})
Expand All @@ -37,10 +37,19 @@ const BeerBrowser: FC = () => {
<div>
<Container className={styles.beerCardsContainer}>
{beerData?.map((beer) => {
return <BeerCard name={beer.name} tagline={beer.tagline} image={beer.imageUrl} id={beer.id} key={beer.id} />;
return (
<BeerCard
name={beer.name}
tagline={beer.tagline}
image={beer.imageUrl}
id={beer.id}
key={beer.id}
isLoading={isLoading}
/>
);
})}
</Container>
<CustomPagination page={page} setPageHandler={setPageHandler} />
<CustomPagination page={page || 1} setPageHandler={setPageHandler} />
</div>
)}
</>
Expand Down
14 changes: 7 additions & 7 deletions src/modules/BeerDetails/IngredientsInfo/Hops/HopsGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export const HopsGroup: FC<HopsGroupProps> = ({ title, hops }) => {
<>
<h3 className={styles.categoryHeader}>{title}</h3>
{hops.length !== 0 ? (
hops.map((hop: HopType,index) => {
return (
<div className={styles.ingredient} key={index}>
<div>{hop.name}</div>
<div>
{hop.amount.value} {hop.amount.unit}
</div>
hops.map((hop: HopType, index) => {
return (
<div className={styles.ingredient} key={index}>
<div>{hop.name}</div>
<div>
{hop.amount.value} {hop.amount.unit}
</div>
</div>
);
})
) : (
Expand Down
35 changes: 17 additions & 18 deletions src/modules/BeerDetails/IngredientsInfo/IngredientsInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,24 @@ export const IngredientsInfo: FC<IngredientsInfoProps> = ({ beerDetails }) => {
<Card.Title>
<h1 className={styles.header}>Ingredients:</h1>
</Card.Title>

<h2 className={styles.subHeader}>Malts:</h2>
{beerDetails?.ingredients.malt.map((malt, index) => {
return (
<div className={styles.ingredient} key={index}>
<div>{malt.name}</div>
<div>
{malt.amount.value} {malt.amount.unit}
</div>

<h2 className={styles.subHeader}>Malts:</h2>
{beerDetails?.ingredients.malt.map((malt, index) => {
return (
<div className={styles.ingredient} key={index}>
<div>{malt.name}</div>
<div>
{malt.amount.value} {malt.amount.unit}
</div>
);
})}

<h2 className={styles.subHeader}>Hops:</h2>
<HopsGroup title={'--Start'} hops={hopsStart} />
<HopsGroup title={'--Middle'} hops={hopsMiddle} />
<HopsGroup title={'--End'} hops={hopsEnd} />
</div>
);
})}

<h2 className={styles.subHeader}>Hops:</h2>
<HopsGroup title={'--Start'} hops={hopsStart} />
<HopsGroup title={'--Middle'} hops={hopsMiddle} />
<HopsGroup title={'--End'} hops={hopsEnd} />

<h2 className={styles.subHeader}>Yeast:</h2>
<div className={styles.ingredient}>{beerDetails?.ingredients.yeast}</div>
</Card.Body>
Expand Down
1 change: 0 additions & 1 deletion src/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

0 comments on commit 67c6af8

Please sign in to comment.