-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
140 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export interface UpdateDistanceSettingsPayload { | ||
defaultDistance?: number; | ||
minimumDistance?: number; | ||
maximumDistance?: number; | ||
} | ||
|
||
interface UpdateDistanceSettings { | ||
type: 'APP_UPDATE_DISTANCE_SETTINGS'; | ||
payload: UpdateDistanceSettingsPayload; | ||
} | ||
|
||
export function updateDistanceSettings( | ||
payload: UpdateDistanceSettingsPayload, | ||
): UpdateDistanceSettings { | ||
return { | ||
type: 'APP_UPDATE_DISTANCE_SETTINGS', | ||
payload, | ||
}; | ||
} | ||
|
||
export type AppActions = UpdateDistanceSettings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { AppState } from '../types'; | ||
import { safeStoredDistance } from '../../utils/localStorage'; | ||
import { AppActions } from './actions'; | ||
|
||
const storedDistanceSettings = safeStoredDistance(); | ||
|
||
const initialState: AppState = { | ||
drawerOpened: true, | ||
defaultDistance: storedDistanceSettings?.defaultDistance || 10, | ||
minimumDistance: storedDistanceSettings?.min || 1, | ||
maximumDistance: storedDistanceSettings?.max || 50, | ||
}; | ||
|
||
function app(state = initialState, action: AppActions): AppState { | ||
switch (action.type) { | ||
case 'APP_UPDATE_DISTANCE_SETTINGS': | ||
return { | ||
...state, | ||
...action.payload, | ||
}; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createSelector } from 'reselect'; | ||
|
||
import { AppState, StoreState } from '../types'; | ||
|
||
const appState = (state: StoreState): AppState => state.app; | ||
|
||
export const defaultDistanceSelector = createSelector( | ||
appState, | ||
(state) => state.defaultDistance, | ||
); | ||
|
||
export const maximumDistanceSelector = createSelector( | ||
appState, | ||
(state) => state.maximumDistance, | ||
); | ||
|
||
export const minimumDistanceSelector = createSelector( | ||
appState, | ||
(state) => state.minimumDistance, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { applyMiddleware, combineReducers, createStore } from 'redux'; | ||
import { composeWithDevTools } from 'redux-devtools-extension'; | ||
|
||
import app from './app/reducer'; | ||
|
||
const reducers = combineReducers({ | ||
app, | ||
}); | ||
|
||
const store = createStore( | ||
reducers, | ||
undefined, | ||
composeWithDevTools( | ||
applyMiddleware(), | ||
), | ||
); | ||
|
||
export default store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface AppState { | ||
drawerOpened: boolean; | ||
defaultDistance: number; | ||
minimumDistance: number; | ||
maximumDistance: number; | ||
} | ||
|
||
export interface StoreState { | ||
app: AppState; | ||
} |