Skip to content

Commit

Permalink
Merge pull request #183 from VasylievYurii/fixingBugs3
Browse files Browse the repository at this point in the history
some fixes with profiles/target
  • Loading branch information
VasylievYurii authored Nov 22, 2023
2 parents bbd1777 + b1a5b20 commit 2befe07
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 51 deletions.
35 changes: 10 additions & 25 deletions src/components/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,33 @@ const SignUp = lazy(() => import('../../pages/SignUp'));
const SignIn = lazy(() => import('../../pages/SignIn'));
import { AppWrapper, ToastContainerStyled } from './App.styled';
import ExercisesList from '../ExercisesList';
import { selectUserAuthenticated } from '../../redux/selectors.js';
import { selectWorkoutsIsLoading } from '../../redux/selectors.js';
import { selectUserProfileIsLoading } from '../../redux/selectors.js';
import { selectProductsIsLoading } from '../../redux/selectors.js';
import { selectMealsIsLoading } from '../../redux/selectors.js';
import { getUserProfile } from '../../redux/userProfile/userProfileOperations.js';
// import { getUserProfile } from '../redux/userProfile/userProfileOperations';

function App() {
const location = useLocation();
const dispatch = useDispatch();
const { isRefreshing, isLoggedIn } = useAuth();

useEffect(() => {
const fetchData = async () => {
await dispatch(getUserProfile());
};
fetchData();
}, [dispatch]);

const { profile } = useSelector((state) => state.profile);
// const auth = useSelector(selectUserAuthenticated);
const workoutIsLoading = useSelector(selectWorkoutsIsLoading);
const profileIsLoading = useSelector(selectUserProfileIsLoading);
const productIsLoading = useSelector(selectProductsIsLoading);
const mealsIsLoading = useSelector(selectMealsIsLoading);

let isFilled = isLoggedIn && profile ? true : false;

// if (isLoggedIn && profile) {
// const profileArray = profile
// ? [
// profile.height,
// profile.currentWeight,
// profile.desiredWeight,
// profile.blood,
// profile.sex,
// profile.levelActivity,
// profile.birthday,
// ]
// : [];

// for (let item of profileArray) {
// if (item) {
// isFilled = true;
// } else {
// isFilled = false;
// break;
// }
// }
// }

useEffect(() => {
dispatch(refreshUser());
}, [dispatch]);
Expand Down
26 changes: 1 addition & 25 deletions src/pages/Diary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import { getUserProfile } from '../redux/userProfile/userProfileOperations';
const Diary = () => {
const dispatch = useDispatch();
const { indicators } = useSelector((state) => state.indicators);
// console.log('indicators:', indicators);
const [selectedDate, setSelectedDate] = useState(
format(new Date(), 'yyyy-MM-dd'),
);
// const { indicators } = useSelector((state) => state.indicators);

const handleDateChange = (date) => {
const newDate = date.toISOString();
setSelectedDate(newDate);
Expand All @@ -36,33 +35,10 @@ const Diary = () => {
await dispatch(getUserProfile());
dispatch(getDiaryMealsThunk(selectedDate));
dispatch(getDiaryWorkoutThunk(selectedDate));
// if (indicators.targetBmr === 0) {
// dispatch(getIndicatorsThunk());
// }
};
fetchData();
}, [dispatch, selectedDate]);

// useEffect(() => {
// const fetchData = async () => {
// await dispatch(getUserProfile());
// dispatch(getDiaryMealsThunk(selectedDate));
// dispatch(getDiaryWorkoutThunk(selectedDate));
// if (indicators.targetBmr !== 0) {
// dispatch(getIndicatorsThunk());
// }
// };
// fetchData();
// }, [dispatch, selectedDate]);

// useEffect(() => {
// dispatch(getDiaryMealsThunk(selectedDate));
// }, [selectedDate]);

// useEffect(() => {
// dispatch(getDiaryWorkoutThunk(selectedDate));
// }, [selectedDate]);

useEffect(() => {
dispatch(getIndicatorsThunk());
}, []);
Expand Down
2 changes: 1 addition & 1 deletion src/redux/products/productsOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getProducts = createAsyncThunk(
}

const queryString = queryParams.join('&');
const url = `products?${queryString}&page=1&limit=20`;
const url = `products?${queryString}&page=1&limit=60`;

const { data } = await instance.get(url);
return data;
Expand Down
1 change: 1 addition & 0 deletions src/redux/userProfile/userProfileOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const getUserProfile = createAsyncThunk(
if (userToken) {
token.set(userToken);
const { data } = await instance.get('profiles');
console.log('data:', data);
return data;
}
return;
Expand Down

0 comments on commit 2befe07

Please sign in to comment.