feat:保存触发一次
This commit is contained in:
parent
beef468477
commit
5feda5bd83
|
@ -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 (
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue