Skip to content

Commit

Permalink
fix(xod-client, xod-client-electron): do not update last saved projec…
Browse files Browse the repository at this point in the history
…t on `Save as a Copy`
  • Loading branch information
brusherru committed Jun 13, 2018
1 parent c99ee92 commit 6da8d70
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 2 additions & 4 deletions packages/xod-client-electron/src/app/workspaceActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ const requestCreateWorkspace = R.curry((send, workspacePath, force = false) =>
const requestShowProject = R.curry((send, project) =>
send(EVENTS.REQUEST_SHOW_PROJECT, project)
);
// :: (String -> a -> ()) -> ()
const notifySaveAllComplete = send => () => send(EVENTS.SAVE_ALL, true);

// :: (String -> a -> ()) -> Path -> Path -> Promise Path Error
export const updateWorkspace = R.curry((send, oldPath, newPath) => {
Expand Down Expand Up @@ -184,12 +182,12 @@ export const onSaveAll = R.curry(
saveData.oldProject,
saveData.newProject
),
R.tap(notifySaveAllComplete(send)),
R.tap(() => {
if (saveData.updateProjectPath) {
updateProjectPath(saveData.projectPath);
}
})
}),
R.always(saveData) // To keep payload in `complete` state of event
)().catch(handleError(send))
);

Expand Down
9 changes: 5 additions & 4 deletions packages/xod-client-electron/src/view/containers/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,21 +339,22 @@ class App extends client.App {

onSave(onAfterSave = noop) {
if (this.state.projectPath) {
this.saveAs(this.state.projectPath, false)
this.saveAs(this.state.projectPath, false, true)
.then(onAfterSave)
.catch(noop);
} else {
this.onSaveAs(onAfterSave);
}
}

saveAs(filePath, shouldUpdateProjectPath) {
saveAs(filePath, shouldUpdateProjectPath, shouldUpdateLastSavedProject) {
return new Promise((resolve, reject) => {
this.props.actions.saveAll({
oldProject: this.props.lastSavedProject,
newProject: this.props.project,
projectPath: filePath,
updateProjectPath: shouldUpdateProjectPath,
updateLastSavedProject: shouldUpdateLastSavedProject,
});

ipcRenderer.once(
Expand All @@ -376,7 +377,7 @@ class App extends client.App {
),
filePath => {
if (!filePath) return;
this.saveAs(filePath, true)
this.saveAs(filePath, true, true)
.then(onAfterSave)
.catch(noop);
}
Expand All @@ -391,7 +392,7 @@ class App extends client.App {
),
filePath => {
if (!filePath) return;
this.saveAs(filePath, false).catch(noop);
this.saveAs(filePath, false, false).catch(noop);
}
);
}
Expand Down
12 changes: 10 additions & 2 deletions packages/xod-client/src/core/trackLastSavedChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ import {
SAVE_ALL,
} from '../project/actionTypes';

const updateLastSavedProject = state =>
R.assoc('lastSavedProject', getProject(state), state);

export default function trackLastSavedChanges(state, action) {
switch (action.type) {
case PROJECT_CREATE:
case PROJECT_OPEN:
case PROJECT_IMPORT:
case SAVE_ALL:
case PROJECT_OPEN_WORKSPACE: {
return R.assoc('lastSavedProject', getProject(state), state);
return updateLastSavedProject(state);
}
case SAVE_ALL: {
if (R.path(['data', 'updateLastSavedProject'], action)) {
return updateLastSavedProject(state);
}
return state;
}

default:
Expand Down

0 comments on commit 6da8d70

Please sign in to comment.