Skip to content

Commit

Permalink
Merge pull request #23 from Bohdan100/feature/shoppinglist-page
Browse files Browse the repository at this point in the history
rewrote on typescript shoppinglist page
  • Loading branch information
Bohdan100 authored Jul 24, 2023
2 parents 6562c49 + d9040a6 commit 3d223bf
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useDispatch } from 'react-redux';
import {FC} from 'react'
import { useAppDispatch } from 'hooks/reduxHooks';

import {
IngredientItem,
Expand All @@ -13,8 +14,15 @@ import {
import { deleteProduct } from 'redux/ShoppingList/shoppingListOperations';
import NotPhoto from '../../images/bgPages/recipePage/not-photo.png';

const IngredientsShoppingItem = ({ image, id, nameIngredient, weight }) => {
const dispatch = useDispatch();
interface IProps{
image: string;
id: string;
nameIngredient: string;
weight: string;
}

const IngredientsShoppingItem:FC<IProps> = ({ image, id, nameIngredient, weight }) => {
const dispatch = useAppDispatch();

return (
<IngredientItem>
Expand All @@ -29,7 +37,7 @@ const IngredientsShoppingItem = ({ image, id, nameIngredient, weight }) => {
<NameIngredient>{nameIngredient}</NameIngredient>
</TextContainer>
<WeighIngredient>{weight}</WeighIngredient>
<DeleteButton type="buton" onClick={() => dispatch(deleteProduct(id))}>
<DeleteButton type="button" onClick={() => dispatch(deleteProduct({id}))}>
<DelIconStyled />
</DeleteButton>
</IngredientItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { FC } from 'react';

import IngredientsShoppingItem from 'components/IngredientsShoppingItem';
import { IngredientsListStyled } from './IngredientsShoppingList.styled';

const IngredientsShoppingList = ({ ingredients }) => {
import { IProduct } from 'types';

interface IProps {
ingredients: IProduct[];
}

const IngredientsShoppingList: FC<IProps> = ({ ingredients }) => {
return (
<>
<IngredientsListStyled>
Expand All @@ -11,7 +19,6 @@ const IngredientsShoppingList = ({ ingredients }) => {
image={ingredient.image}
nameIngredient={ingredient.strIngredient}
weight={ingredient.weight ? ingredient.weight : 'any'}
recipeId={ingredient.recipeId}
id={ingredient._id}
/>
))}
Expand Down
14 changes: 0 additions & 14 deletions src/hooks/useShoppingList.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/hooks/useShoppingList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useAppSelector } from 'hooks/reduxHooks';
import {
selectProducts,
selectIsLoading,
selectError,
} from 'redux/ShoppingList/shoppingListSelectors';

export const useShoppingList = () => {
return {
products: useAppSelector(selectProducts),
isLoading: useAppSelector(selectIsLoading),
error: useAppSelector(selectError),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ import { HeaderTable, StyledLoaderWrapper } from './ShoppingListPage.styled';
import Loader from 'components/Loader';
import NotFoundWrapp from 'components/ReusableComponents/NotFoundWrapp';

import {useShoppingList} from 'hooks/useShoppingList'
import { IProduct } from 'types';

const isLoading = false;

const ShoppingListPage = () => {
const { t } = useTranslation();
const shoppingList = useSelector(selectProducts);

const revers = arr => arr.map((_, index) => arr[arr.length - 1 - index]);
const reversedShoppingList = revers(shoppingList);


const shoppingList = useShoppingList().products;
console.log(shoppingList);


const reverse = (arr: IProduct[]): IProduct[] => arr.map((_, index) => arr[arr.length - 1 - index]);

const reversedShoppingList = reverse(shoppingList);

return (
<MainContainer>
Expand All @@ -30,7 +39,7 @@ const ShoppingListPage = () => {
<span>{t('shoppingListPage.remove')}</span>
</p>
</HeaderTable>
{isLoading ? (
{isLoading ? (
<StyledLoaderWrapper>
<Loader />
</StyledLoaderWrapper>
Expand Down
File renamed without changes.
6 changes: 0 additions & 6 deletions src/services/favorite-API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ export const fetchOneRacipes = async (id: string) => {
return data;
};

// export const fetchOwnRacipes = async () => {
// const url = `/ownRecipe/`;
// const { data } = await axios.get(url);
// return data;
// };

export const fetchFavoriteRacipes = async (page?: number, limit?: number) => {
const url = `/favorite`;
const { data }: AxiosResponse<IFavoriteRecipesGetResponse> = await axios.get(
Expand Down

0 comments on commit 3d223bf

Please sign in to comment.