Skip to content

Commit

Permalink
fix(selectedDate): at launch, set selectedDate to today
Browse files Browse the repository at this point in the history
  • Loading branch information
Clm-Roig committed May 18, 2022
1 parent 49b882a commit 6eb70bd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/app/CustomPersistGate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { PersistGate } from 'redux-persist/integration/react';

import { persistor } from '../store/store';
import { selectAllTrackers } from '../store/trackers/trackers.selectors';
import { setSelectedDate } from '../store/trackers/trackersSlice';
import isATracker from '../utils/isATracker';
import FullScreenLoading from './FullScreenLoading';
import { useAppSelector } from './hooks';
import { useAppDispatch, useAppSelector } from './hooks';

interface Props {
children: React.ReactNode;
Expand All @@ -15,8 +16,13 @@ interface Props {
const CustomPersistGate: FC<Props> = ({ children }) => {
const { trackers } = useAppSelector(selectAllTrackers);
const navigate = useNavigate();
const dispatch = useAppDispatch();

const handleBeforeLift = () => {
// Change date to today
dispatch(setSelectedDate(new Date().toString()));

// Check trackers
for (const tracker of trackers) {
const data = isATracker(tracker);
if (data.errors.length !== 0) {
Expand All @@ -25,6 +31,8 @@ const CustomPersistGate: FC<Props> = ({ children }) => {
});
}
}

// Move to the validate trackers page
if (trackers.length > 0) {
navigate('/trackers');
}
Expand Down

0 comments on commit 6eb70bd

Please sign in to comment.