1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-28 17:20:13 +02:00

Add some more commands to commands palette.

Some refactoring also. Move palette events to commands.js.
This commit is contained in:
Kushagra Gour
2018-10-27 20:24:34 +05:30
parent 021f1390ab
commit f4de6572c2
6 changed files with 60 additions and 39 deletions

View File

@@ -57,9 +57,12 @@ import { Icons } from './Icons';
import JSZip from 'jszip';
import { CommandPalette } from './CommandPalette';
import {
commandPaletteService,
OPEN_SAVED_CREATIONS_EVENT
} from '../commandPaletteService';
OPEN_SAVED_CREATIONS_EVENT,
SAVE_EVENT,
OPEN_SETTINGS_EVENT,
NEW_CREATION_EVENT
} from '../commands';
import { commandPaletteService } from '../commandPaletteService';
if (module.hot) {
require('preact/debug');
@@ -497,6 +500,10 @@ export default class App extends Component {
this.editorWithFocus.focus();
}
}
openSettings() {
this.setState({ isSettingsModalOpen: true });
}
componentDidMount() {
document.body.style.height = `${window.innerHeight}px`;
@@ -560,10 +567,26 @@ export default class App extends Component {
}
}
});
commandPaletteService.subscribe(OPEN_SAVED_CREATIONS_EVENT, () => {
this.openSavedItemsPane();
});
const commandPalleteHooks = {
[NEW_CREATION_EVENT]: () => {
this.openNewCreationModal();
},
[OPEN_SAVED_CREATIONS_EVENT]: () => {
this.openSavedItemsPane();
},
[SAVE_EVENT]: () => {
this.saveItem();
},
[OPEN_SETTINGS_EVENT]: () => {
this.openSettings();
}
};
for (let eventName in commandPalleteHooks) {
commandPaletteService.subscribe(
eventName,
commandPalleteHooks[eventName]
);
}
}
closeAllOverlays() {
@@ -931,8 +954,7 @@ export default class App extends Component {
this.forkItem(item);
}, 350);
}
newBtnClickHandler() {
trackEvent('ui', 'newBtnClick');
openNewCreationModal() {
if (this.state.unsavedEditCount) {
var shouldDiscard = confirm(
'You have unsaved changes. Do you still want to create something new?'
@@ -948,6 +970,10 @@ export default class App extends Component {
});
}
}
newBtnClickHandler() {
trackEvent('ui', 'newBtnClick');
this.openNewCreationModal();
}
openBtnClickHandler() {
trackEvent('ui', 'openBtnClick');
this.openSavedItemsPane();
@@ -1412,9 +1438,7 @@ export default class App extends Component {
prefs={this.state.prefs}
layoutBtnClickHandler={this.layoutBtnClickHandler.bind(this)}
helpBtnClickHandler={() => this.setState({ isHelpModalOpen: true })}
settingsBtnClickHandler={() =>
this.setState({ isSettingsModalOpen: true })
}
settingsBtnClickHandler={this.openSettings.bind(this)}
notificationsBtnClickHandler={this.notificationsBtnClickHandler.bind(
this
)}