-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- The state is handled in Redux - No more ModalProvider - pop-up in pop-up is now supported (recursively)
- Loading branch information
Showing
12 changed files
with
139 additions
and
122 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,63 @@ | ||
import { PayloadAction } from '@reduxjs/toolkit' | ||
import { createSlice } from 'utils/@reduxjs/toolkit' | ||
|
||
import { Modal, ModalState } from './types' | ||
|
||
export const initialState: ModalState = { | ||
current: null, | ||
stash: [], | ||
} | ||
|
||
const slice = createSlice({ | ||
name: 'modal', | ||
initialState, | ||
reducers: { | ||
/** | ||
* Show a new modal | ||
*/ | ||
launch(state, action: PayloadAction<Modal>) { | ||
if (state.current) { | ||
state.stash.push(state.current) | ||
} | ||
state.current = action.payload | ||
}, | ||
|
||
/** | ||
* Close the current modal | ||
*/ | ||
close(state) { | ||
state.current = state.stash.pop() || null | ||
}, | ||
|
||
/** | ||
* Hide the current modal (with the intention of showing in again later) | ||
* | ||
* The semantics is the same as with git stash. | ||
*/ | ||
stash(state) { | ||
if (!state.current) { | ||
throw new Error("You can't call hideModal if no model is shown!") | ||
} | ||
state.stash.push(state.current) | ||
state.current = null | ||
}, | ||
|
||
/** | ||
* Show the previously hidden modal again. | ||
* | ||
* The semantics is the same as with `git stash pop`. | ||
*/ | ||
stashPop(state) { | ||
if (state.current) { | ||
throw new Error("You can't call showModal when a modal is already visible!") | ||
} | ||
const latest = state.stash.pop() | ||
if (!latest) return | ||
state.current = latest | ||
}, | ||
}, | ||
}) | ||
|
||
export const { actions: modalActions } = slice | ||
|
||
export default slice.reducer |
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,8 @@ | ||
import { createSelector } from '@reduxjs/toolkit' | ||
|
||
import { RootState } from 'types' | ||
import { initialState } from '.' | ||
|
||
const selectSlice = (state: RootState) => state.modal || initialState | ||
|
||
export const selectCurrentModal = createSelector([selectSlice], settings => settings.current) |
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,24 @@ | ||
export interface Modal { | ||
title: string | ||
description: string | ||
handleConfirm: () => void | ||
|
||
/** | ||
* Is this a dangerous operation? | ||
* | ||
* If marked as such, it will only be possible to execute it if the wallet is configured to run in dangerous mode. | ||
* | ||
* It also automatically implies a mandatory waiting time of 10 sec, unless specified otherwise. | ||
*/ | ||
isDangerous: boolean | ||
|
||
/** | ||
* How long does the user have to wait before he can actually confirm the action? | ||
*/ | ||
mustWaitSecs?: number | ||
} | ||
|
||
export interface ModalState { | ||
current: Modal | null | ||
stash: Modal[] | ||
} |
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
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
Oops, something went wrong.