Skip to content

Commit

Permalink
Merge pull request #42 from MAKCKACHKA/loader
Browse files Browse the repository at this point in the history
Loader
  • Loading branch information
MAKCKACHKA authored Dec 26, 2023
2 parents b3f02c7 + 4400d79 commit fbea002
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
35 changes: 29 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"react-modal": "^3.16.1",
"react-redux": "^9.0.4",
"react-router-dom": "^6.15.0",
"react-spinners": "^0.13.8",
"redux-persist": "^6.0.0",
"styled-components": "^6.1.1",
"vite-plugin-svgr": "^3.2.0",
Expand Down
10 changes: 10 additions & 0 deletions src/components/Loader/Loader.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BeatLoader } from 'react-spinners';
const override = {
display: 'flex',
margin: '30vh auto 100vh',
justifyContent: 'center',
};

export const Loader = () => {
return <BeatLoader cssOverride={override} color="#E3FFA8" size={9} />;
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import StyledRecommendedFoodSection from './RecommendedFood.styled';
import icons from '../../../assets/icons.svg';
import { useDispatch, useSelector } from 'react-redux';
import { selectRecFood } from '../../../redux/selesctors';
import { selectRecFood, selectIsLoading } from '../../../redux/selesctors';
import { useEffect } from 'react';
import { refreshRecommendedFood } from '../../../redux/operations';
import { NavLink } from 'react-router-dom';
import { Loader } from '../../Loader/Loader';

export default function RecommendedFoodPage() {
const dispatch = useDispatch();
const isLoading = useSelector(selectIsLoading);
const food = useSelector(selectRecFood);
let reducedArr = [];

Expand All @@ -22,6 +24,7 @@ export default function RecommendedFoodPage() {
return (
<StyledRecommendedFoodSection>
<h2>Recommended Food</h2>
{isLoading && <Loader />}
<div className="wrapper">
<ul>
{reducedArr?.map(({ amount, calories, img, name, _id }) => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/SharedLayout/SharedLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { Outlet } from 'react-router-dom';
import { Header } from 'components/Header/Header';
import { Container } from './SharedLayout.styled';
import { Toaster } from 'react-hot-toast';
import { Loader } from '../Loader/Loader';
// import { setToken } from '../../redux/auth/auth';

const SharedLayout = () => {
return (
<>
<Header />
<Container>
<Suspense fallback={null}>
<Suspense fallback={<Loader />}>
<Outlet />
</Suspense>
</Container>
Expand Down
5 changes: 4 additions & 1 deletion src/pages/RecommendedFoodPage/RecommendedFoodPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import StyledRecommendedFoodPage from './RecommendedFoodPage.styled';
import Illustration from '../../assets/pageIllustrations.svg';
import { useDispatch } from 'react-redux';
import { refreshRecommendedFood } from '../../redux/operations';
import { selectRecFood } from '../../redux/selesctors';
import { selectRecFood, selectIsLoading } from '../../redux/selesctors';
import { useSelector } from 'react-redux';
import { useEffect } from 'react';
import { Loader } from '../../components/Loader/Loader';

export default function RecommendedFoodPage() {
const dispatch = useDispatch();
const isLoading = useSelector(selectIsLoading);
const food = useSelector(selectRecFood);
let reducedArr = [];

Expand All @@ -27,6 +29,7 @@ export default function RecommendedFoodPage() {
<svg className="img_div">
<use href={`${Illustration}#icon-recommented-food`} />
</svg>
{isLoading && <Loader />}
<ul>
{reducedArr?.map(({ amount, calories, img, name, _id }) => {
return (
Expand Down
6 changes: 4 additions & 2 deletions src/redux/selesctors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ export const selectToken = (state) => state.auth.token;

export const selectUserStatistics = (state) => state.data.statistics;

export const selectIsLoading = (state) => state.data.isLoading;

export const selectUserData = (state) => state.data.data;

export const selectUserMeals = (state) => state.data.data.consumedMealsByDay;

export const selectDailyNutrition = (state) =>
state.data.data.user.dailyNutrition;
state.data.data.user.dailyNutrition;

export const selectRecFood = (state) => state.data.recommendedFood;
export const selectRecFood = (state) => state.data.recommendedFood;

0 comments on commit fbea002

Please sign in to comment.