Merge pull request #1017 from embark-framework/chores/add-back-on-save-success

Add back event on file save sucess
This commit is contained in:
Eric Mastro 2018-10-31 18:36:20 +01:00 committed by GitHub
commit 13f0b766a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -289,7 +289,7 @@ export const file = {
export const SAVE_FILE = createRequestTypes('SAVE_FILE'); export const SAVE_FILE = createRequestTypes('SAVE_FILE');
export const saveFile = { export const saveFile = {
request: ({name, path, content}) => action(SAVE_FILE[REQUEST], {name, path, content}), request: ({name, path, content}) => action(SAVE_FILE[REQUEST], {name, path, content}),
success: (_, {name, path, content}) => action(SAVE_FILE[SUCCESS], {name, path, content}), success: (file) => action(SAVE_FILE[SUCCESS], {file}),
failure: (error) => action(SAVE_FILE[FAILURE], {error}) failure: (error) => action(SAVE_FILE[FAILURE], {error})
}; };

View File

@ -208,6 +208,10 @@ export function *watchPostFile() {
yield takeEvery(actions.SAVE_FILE[actions.REQUEST], postFile); yield takeEvery(actions.SAVE_FILE[actions.REQUEST], postFile);
} }
export function *watchPostFileSuccess() {
yield takeEvery(actions.SAVE_FILE[actions.SUCCESS], addEditorTabs);
}
export function *watchDeleteFile() { export function *watchDeleteFile() {
yield takeEvery(actions.REMOVE_FILE[actions.REQUEST], deleteFile); yield takeEvery(actions.REMOVE_FILE[actions.REQUEST], deleteFile);
} }
@ -539,5 +543,6 @@ export default function *root() {
fork(watchRemoveEditorTabs), fork(watchRemoveEditorTabs),
fork(watchAddEditorTabsSuccess), fork(watchAddEditorTabsSuccess),
fork(watchRemoveEditorTabsSuccess), fork(watchRemoveEditorTabsSuccess),
fork(watchPostFileSuccess)
]); ]);
} }

View File

@ -4,9 +4,10 @@ export function addEditorTabs({file}) {
editorTabs.forEach(f => f.active = false); editorTabs.forEach(f => f.active = false);
const alreadyAddedFile = editorTabs.find(f => f.name === file.name) const alreadyAddedFile = editorTabs.find(f => f.name === file.name)
if (alreadyAddedFile) { if (alreadyAddedFile) {
alreadyAddedFile.active = true alreadyAddedFile.active = true;
alreadyAddedFile.content = file.content;
} else { } else {
file.active = true file.active = true;
editorTabs.push(file); editorTabs.push(file);
} }
localStorage.setItem('editorTabs', JSON.stringify(editorTabs)); localStorage.setItem('editorTabs', JSON.stringify(editorTabs));