diff --git a/src/pages/Note/Hlexical/index.jsx b/src/pages/Note/Hlexical/index.jsx index a96a61b..9d68c67 100644 --- a/src/pages/Note/Hlexical/index.jsx +++ b/src/pages/Note/Hlexical/index.jsx @@ -82,7 +82,7 @@ function ImportFilePlugin(props) { // editor.setEditorState(editorState); export default function Hlexical(props) { - console.log("this.props.filePath=============:", props.filePath) + console.log("this.props.filePath:", props.filePath) const [editorState, setEditorState] = useState(""); const [lastId ,setLastId]= useState(""); function onChange(editorState) { @@ -94,30 +94,35 @@ export default function Hlexical(props) { } function SaveFilePlugin(props) { - let unsubscribe = store.subscribe(() => { - console.log("触发保存") - console.log("props.editorState", props) - if (isEmpty(props.editorState)) { - return - } - const editorStateSave = {"editorState": JSON.parse(props.editorState)}; - let resultSave = JSON.stringify(editorStateSave); - console.log("store.getState().pushHotkeys", store.getState().pushHotkeys) - console.log("lastId", lastId) - if ((lastId === "" || lastId !== store.getState().pushHotkeys.id) && store.getState().pushHotkeys.data === SAVE) { - setLastId(store.getState().pushHotkeys.id); - importFile(props.filePath).then(value => { - let save = md5(resultSave) !== md5(JSON.stringify(JSON.parse(value.toString()))); - console.log("md5(resultSave)!==md5(JSON.stringify(JSON.parse(value.toString())))", resultSave, save) - if (save) { - console.log("保存重写") - overWriteFile(props.filePath, resultSave) - } - }).catch(error => - console.error(error) - ) - } - }); + useEffect(()=>{ + let unsubscribe = store.subscribe(() => { + console.log("触发保存") + console.log("props.editorState", props) + if (isEmpty(props.editorState)) { + return + } + const editorStateSave = {"editorState": JSON.parse(props.editorState)}; + let resultSave = JSON.stringify(editorStateSave); + console.log("store.getState().pushHotkeys", store.getState().pushHotkeys) + console.log("lastId", lastId) + if ((lastId === "" || lastId !== store.getState().pushHotkeys.id) && store.getState().pushHotkeys.data === SAVE) { + setLastId(store.getState().pushHotkeys.id); + importFile(props.filePath).then(value => { + let save = md5(resultSave) !== md5(JSON.stringify(JSON.parse(value.toString()))); + console.log("md5(resultSave)!==md5(JSON.stringify(JSON.parse(value.toString())))", resultSave, save) + if (save) { + console.log("保存重写") + overWriteFile(props.filePath, resultSave) + } + }).catch(error => + console.error(error) + ) + } + }); + console.log("return unsubscribe();") + return ()=>unsubscribe(); + },[props]) + } return ( diff --git a/src/redux/pushHotkeys_reducer.js b/src/redux/pushHotkeys_reducer.js index 8bbcd5b..a627e8f 100644 --- a/src/redux/pushHotkeys_reducer.js +++ b/src/redux/pushHotkeys_reducer.js @@ -9,8 +9,7 @@ export const pushHotkeysSlice = createSlice({ }, reducers: { pushHotkeys: (state, action) => { - console.log("pushHotkeys:pushHotkeys---------state", state) - console.log("pushHotkeys:pushHotkeys---------action", action) + console.log("pushHotkeys:pushHotkeys", action.payload) if(action.payload){ state.data = action.payload; state.id = nanoid();