mirror of https://github.com/usememos/memos
feat: `esc` key to exit multiple dialogs (#692)
* fix: `esc` key to exit multiple dialogs * update * update * update * Update web/src/components/Dialog/BaseDialog.tsx Co-authored-by: boojack <stevenlgtm@gmail.com>pull/780/head
parent
e79d67d127
commit
55695f2189
@ -0,0 +1,23 @@
|
||||
import store, { useAppSelector } from "..";
|
||||
import { pushDialogStack, popDialogStack } from "../reducer/dialog";
|
||||
import { last } from "lodash";
|
||||
|
||||
export const useDialogStore = () => {
|
||||
const state = useAppSelector((state) => state.editor);
|
||||
|
||||
return {
|
||||
state,
|
||||
getState: () => {
|
||||
return store.getState().dialog;
|
||||
},
|
||||
pushDialogStack: (dialogName: string) => {
|
||||
store.dispatch(pushDialogStack(dialogName));
|
||||
},
|
||||
popDialogStack: () => {
|
||||
store.dispatch(popDialogStack());
|
||||
},
|
||||
topDialogStack: () => {
|
||||
return last(store.getState().dialog.dialogStack);
|
||||
},
|
||||
};
|
||||
};
|
@ -0,0 +1,30 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface State {
|
||||
dialogStack: string[];
|
||||
}
|
||||
|
||||
const dialogSlice = createSlice({
|
||||
name: "dialog",
|
||||
initialState: {
|
||||
dialogStack: [],
|
||||
} as State,
|
||||
reducers: {
|
||||
pushDialogStack: (state, action: PayloadAction<string>) => {
|
||||
return {
|
||||
...state,
|
||||
dialogStack: [...state.dialogStack, action.payload],
|
||||
};
|
||||
},
|
||||
popDialogStack: (state) => {
|
||||
return {
|
||||
...state,
|
||||
dialogStack: state.dialogStack.slice(0, state.dialogStack.length - 1),
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { pushDialogStack, popDialogStack } = dialogSlice.actions;
|
||||
|
||||
export default dialogSlice.reducer;
|
Loading…
Reference in New Issue