Skip to content

Commit

Permalink
fix: solve blank screen bug when creating trainings
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmsa committed Dec 6, 2023
1 parent 6f89a47 commit d02e0d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
16 changes: 9 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import React, { useEffect } from 'react';
import Routes from './routes';
import Modal from 'react-modal';
import GlobalStyle from './styles/global';
import toast, { Toaster, useToasterStore } from 'react-hot-toast';
import { BrowserRouter } from 'react-router-dom';

function App() {
Modal.setAppElement('#root');

function App() {
const { toasts } = useToasterStore();

const TOAST_LIMIT = 1
const TOAST_LIMIT = 1;

useEffect(() => {
toasts
.filter(t => t.visible)
.filter((_, index) => index >= TOAST_LIMIT)
.forEach((t) => {
toast.dismiss(t.id);
});
.filter((t) => t.visible)
.filter((_, index) => index >= TOAST_LIMIT)
.forEach((t) => {
toast.dismiss(t.id);
});
}, [toasts]);

return (
Expand Down
12 changes: 4 additions & 8 deletions src/components/Desktop/Home/MidSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ import MountWorkout from '../MountWorkout';
import { useDispatch, useSelector } from 'react-redux';
import { Dispatch } from 'redux';
import { addSet, removeSet, updateCurrentSet } from '../../../../store/training/actionCreators';
import {
getCurrentSet,
getTrainingSetExercises,
getTrainSetLoops
} from '../../../../store/training/selectors';
import { getCurrentSet, getTrainSetLoops } from '../../../../store/training/selectors';
import toast from 'react-hot-toast';
import ErrorToast from '../../../../toasts/ErrorToast';
import { AnimatePresence, motion } from 'framer-motion/dist/framer-motion';
Expand All @@ -36,7 +32,7 @@ const MidSection = () => {
const dispatch: Dispatch<any> = useDispatch();
const trainingSets = useSelector(getTrainSetLoops);
const currentSet = useSelector(getCurrentSet);
const currentTrainingSetExercises = useSelector(getTrainingSetExercises);
const allTrainSetsContainExercises = trainingSets.every((set) => set.trainSet.exercises.length);
const setsQuantity = trainingSets.length;
const progressLineAnimation = {
initial: { offsetDistance: '0%', scale: 1.5 },
Expand Down Expand Up @@ -97,14 +93,14 @@ const MidSection = () => {
{trainingSets.length <= 4 && (
<AddSetContainer
onClick={() => {
if (currentTrainingSetExercises.length) {
if (allTrainSetsContainExercises) {
dispatch(addSet());
dispatch(updateCurrentSet(setsQuantity));
} else {
toast(
ErrorToast({
message:
'You must have at least one exercise on the current set before you add new ones'
'You must have at least one exercise on every set before you add new ones'
})
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/training/actionCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
UPDATE_CURRENT_SET,
UPDATE_EXERCISE_REST_TIME,
UPDATE_EXERCISE_TRAIN_TIME,
UPDATE_CURRENT_SET_LOOP_QUANTITY,
UPDATE_SET_REST_TIME,
UPDATE_CURRENT_SET_LOOP_QUANTITY,
UPDATE_DEFAULT_TRAINING_VALUES,
RESET_TRAINING
} from './actionTypes';
Expand Down

0 comments on commit d02e0d6

Please sign in to comment.