Skip to content

Commit

Permalink
put distance settings in the redux store
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaya committed Jun 25, 2020
1 parent 6a82e7d commit 1c1b325
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
19 changes: 11 additions & 8 deletions src/components/ConfigureRun/ConfigureRun.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
import React, {
FormEvent, useCallback, useEffect, useRef, useState,
} from 'react';
import { useSelector } from 'react-redux';
import {
useRecoilState,
useRecoilValue,
useRecoilValueLoadable,
useSetRecoilState,
} from 'recoil';

import {
Button,
CircularProgress,
Grid,
Theme,
} from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';

import { makeStyles } from '@material-ui/core/styles';
import {
routeDataQuery,
routeLocationState,
routeParams,
} from '../../state/route';
import { isLoading, randomSeed } from '../../state/utils';
import { RouteTypeValue } from '../../types';
import {
defaultDistanceSelector,
maximumDistanceSelector,
minimumDistanceSelector,
} from '../../store/app/selectors';

import { RouteTypeValue } from '../../types';
import Distance from './Distance';
import StartingPoint from './StartingPoint';
import RouteType from './RouteType';
import { setQueryParameters } from '../../utils/history';
import { defaultDistanceState, maximumDistanceState, minimumDistanceState } from '../../state/app';
import { setOnCompleteLocation } from '../../state/location';

const routeTypes: RouteTypeValue[] = [
Expand Down Expand Up @@ -78,9 +81,9 @@ const ConfigureRun: React.FC<ConfigureRunProps> = ({ onCompleteLoading }) => {
const setRouteLocation = useSetRecoilState(routeLocationState);
const location = params.location || null;

const defaultDistance = useRecoilValue(defaultDistanceState);
const minDistance = useRecoilValue(minimumDistanceState);
const maxDistance = useRecoilValue(maximumDistanceState);
const defaultDistance = useSelector(defaultDistanceSelector);
const maxDistance = useSelector(maximumDistanceSelector);
const minDistance = useSelector(minimumDistanceSelector);

const [distance, setDistance] = useState<number>(params.distance || defaultDistance);
const [routeType, setRouteType] = useState<RouteTypeValue['id']>(params.routeType || routeTypes[0].id);
Expand Down
19 changes: 0 additions & 19 deletions src/state/app.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
import { atom } from 'recoil';

import { safeStoredDistance } from '../utils/localStorage';

export const drawerOpenState = atom<boolean>({
key: 'DrawerOpenState',
default: true,
});

const storedDistanceSettings = safeStoredDistance();

export const defaultDistanceState = atom<number>({
key: 'DefaultDistanceState',
default: storedDistanceSettings?.defaultDistance || 10,
});

export const minimumDistanceState = atom<number>({
key: 'MinimumDistanceState',
default: storedDistanceSettings?.min || 1,
});

export const maximumDistanceState = atom<number>({
key: 'MaximumDistanceState',
default: storedDistanceSettings?.max || 50,
});

0 comments on commit 1c1b325

Please sign in to comment.