Skip to content

Commit

Permalink
Style fix to loader and settings navigation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MAKCKACHKA committed Dec 26, 2023
1 parent fbea002 commit fff1dbd
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/components/Loader/Loader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const override = {
display: 'flex',
margin: '30vh auto 100vh',
justifyContent: 'center',
position: 'fixed',
top: '20%',
left: '50%',
transform: 'translate(-50%, -50%) scale(2)',
};

export const Loader = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import StyledRecommendedFoodSection from './RecommendedFood.styled';
import icons from '../../../assets/icons.svg';
import { useDispatch, useSelector } from 'react-redux';
import { selectRecFood, selectIsLoading } from '../../../redux/selesctors';
import {
selectRecFood,
selectIsLoadAuth,
selectIsLoadData,
} 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 isLoading = useSelector(selectIsLoadAuth && selectIsLoadData);
const food = useSelector(selectRecFood);
let reducedArr = [];

Expand Down
7 changes: 6 additions & 1 deletion src/components/SharedLayout/SharedLayout.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Suspense } from 'react';
import { Suspense, useState } from 'react';
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 { useSelector } from 'react-redux';
import { selectIsLoadAuth, selectIsLoadData } from '../../redux/selesctors';
// import { setToken } from '../../redux/auth/auth';

const SharedLayout = () => {
const isLoadData = useSelector(selectIsLoadData);
const isLoadAuth = useSelector(selectIsLoadAuth);
return (
<>
<Header />
Expand All @@ -16,6 +20,7 @@ const SharedLayout = () => {
</Suspense>
</Container>
<Toaster reverseOrder={false} />
{isLoadData && isLoadAuth && <Loader />}
</>
);
};
Expand Down
8 changes: 6 additions & 2 deletions src/pages/RecommendedFoodPage/RecommendedFoodPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import StyledRecommendedFoodPage from './RecommendedFoodPage.styled';
import Illustration from '../../assets/pageIllustrations.svg';
import { useDispatch } from 'react-redux';
import { refreshRecommendedFood } from '../../redux/operations';
import { selectRecFood, selectIsLoading } from '../../redux/selesctors';
import {
selectRecFood,
selectIsLoadAuth,
selectIsLoadData,
} 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 isLoading = useSelector(selectIsLoadAuth && selectIsLoadData);
const food = useSelector(selectRecFood);
let reducedArr = [];

Expand Down
6 changes: 4 additions & 2 deletions src/pages/SettingsPage/SettingsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import {
getCurrentUser,
updateUserInformation,
} from '../../redux/operations';
import { useState } from 'react';
import { useEffect } from 'react';
import { useState, useEffect } from 'react';

export default function SettingsPage() {
const { user } = useSelector(selectUserData);
Expand Down Expand Up @@ -76,13 +75,16 @@ export default function SettingsPage() {
dispatch(getCurrentUser());
setAvatar(user.avatarURL);
avatar !== '' && typeof avatar === 'object' && setObjectURL(false);

window.location.href = '/healthy_hub/main ';
}, 2300);
};

const handleCancel = (resetForm) => {
resetForm({ values: initialValues });
setAvatar(user ? user.avatarURL : '');
setObjectURL(false);
window.location.href = '/healthy_hub/main ';
};

const validationSchema = Yup.object().shape({
Expand Down
7 changes: 4 additions & 3 deletions src/redux/selesctors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ export const selectToken = (state) => state.auth.token;

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

export const selectIsLoading = (state) => state.data.isLoading;
export const selectIsLoadData = (state) => state.data.isLoading;
export const selectIsLoadAuth = (state) => state.auth.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 fff1dbd

Please sign in to comment.