-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use proper state management to handle opening the string list
- Loading branch information
Showing
7 changed files
with
69 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { AppDispatch } from '~/store'; | ||
|
||
export const TOGGLE = 'entitieslist/TOGGLE'; | ||
|
||
export type Action = ToggleAction; | ||
|
||
type ToggleAction = { | ||
readonly type: typeof TOGGLE; | ||
readonly show: boolean; | ||
}; | ||
|
||
/** | ||
* Toggle Entities List (used in mobile view). | ||
*/ | ||
export const toggleEntitiesList = () => async (dispatch: AppDispatch) => { | ||
dispatch({ | ||
type: TOGGLE, | ||
}); | ||
}; |
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,5 @@ | ||
import { useAppSelector } from '~/hooks'; | ||
import { ENTITIESLIST } from './reducer'; | ||
|
||
export const useEntitiesList = () => | ||
useAppSelector((state) => state[ENTITIESLIST]); |
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,28 @@ | ||
import { Action, TOGGLE } from './actions'; | ||
|
||
// Name of this module. | ||
// Used as the key to store this module's reducer. | ||
export const ENTITIESLIST = 'entitieslist'; | ||
|
||
export type EntitiesListState = { | ||
readonly show: boolean; | ||
}; | ||
|
||
const initial: EntitiesListState = { | ||
show: false, | ||
}; | ||
|
||
export function reducer( | ||
state: EntitiesListState = initial, | ||
action: Action, | ||
): EntitiesListState { | ||
switch (action.type) { | ||
case TOGGLE: | ||
return { | ||
...state, | ||
show: !state.show, | ||
}; | ||
default: | ||
return state; | ||
} | ||
} |
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