Skip to content

Commit

Permalink
feat(client): complete integrating save options
Browse files Browse the repository at this point in the history
Closes #894
  • Loading branch information
nikku committed Sep 24, 2018
1 parent 8ac2e78 commit 4098188
Showing 1 changed file with 23 additions and 33 deletions.
56 changes: 23 additions & 33 deletions client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class App extends Component {
closeTab = async (tab) => {

if (this.isDirty(tab)) {
await this.saveTab(tab);
await this.saveTab(tab, { ask: true });
}

await this._removeTab(tab);
Expand Down Expand Up @@ -309,9 +309,7 @@ export class App extends Component {
console.log('%cApp#handleTabChanged', 'color: #52B415');

let {
activeTab,
dirtyTabs,
tabs
} = this.state;

if ('dirty' in properties) {
Expand All @@ -325,34 +323,23 @@ export class App extends Component {
dirtyTabs: newDirtyTabs
});
}
}

// TODO(nikku): SEPARATE METHOD
const updatedTabs = tabs.map((t) => {

if (t.id === tab.id) {

const newTab = {
...t,
...properties
};

this.tabHistory.replace(t, newTab);
tabSaved(tab, newFile) {

return newTab;
} else {
return t;
}
});
const {
dirtyTabs,
tabs
} = this.state;

const newActiveTab = (
activeTab.id === tab.id ?
updatedTabs.find(t => t.id === tab.id) :
activeTab
);
tab.file = newFile;

this.setState({
tabs: updatedTabs,
activeTab: newActiveTab
tabs: [ ...tabs ],
dirtyTabs: {
...dirtyTabs,
[tab.id]: false
}
});
}

Expand Down Expand Up @@ -413,6 +400,7 @@ export class App extends Component {

this.props.onToolStateChanged(activeTab, {
closable: activeTab !== EMPTY_TAB,
save: activeTab !== EMPTY_TAB,
dirty: this.isDirty(activeTab)
});
}
Expand All @@ -421,7 +409,12 @@ export class App extends Component {
async saveTab(tab, options = {}) {
await this.showTab(tab);

const action = await this.askSave(tab);
let {
saveAs,
ask
} = options;

const action = ask ? await this.askSave(tab) : 'save';

if (action === 'cancel') {
throw new Error('user canceled');
Expand All @@ -432,18 +425,15 @@ export class App extends Component {

// unsaved ?
if (!tab.file.path) {
options = {
...options,
saveAs: true
};
saveAs = true;
}

const newFile = await this.props.globals.fileSystem.writeFile({
...tab.file,
contents
}, options);
}, { saveAs });

tab.file = newFile;
this.tabSaved(tab, newFile);
}
}

Expand Down

0 comments on commit 4098188

Please sign in to comment.