Skip to content

fix(genie): allow genie to sort wishes properly #1013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion packages/app/src/app/pages/Sandbox/QuickActions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
} from './elements';

class QuickActions extends React.Component {
// we'll just keep track of what the user changes the inputValue to be
// so when the user makes a wish we can provide that info to genie
inputValue = ''
updateGenie = () => {
const keybindings = this.props.store.preferences.keybindings;
const signals = this.props.signals;
Expand Down Expand Up @@ -44,6 +47,7 @@ class QuickActions extends React.Component {

componentDidMount() {
this.updateGenie();
this.loadGenie();
}

componentDidUpdate() {
Expand All @@ -63,10 +67,28 @@ class QuickActions extends React.Component {
};

onChange = item => {
genie.makeWish(item);
genie.makeWish(item, this.inputValue);
this.persistGenie();
this.closeQuickActions();
};

persistGenie() {
const { enteredMagicWords } = genie.options();
window.localStorage.setItem('genie', JSON.stringify({ enteredMagicWords }))
}

loadGenie() {
try {
const { enteredMagicWords } = JSON.parse(window.localStorage.getItem('genie'))
genie.options({ enteredMagicWords })
} catch (error) {
// it may not exist in localStorage yet, or the JSON was malformed somehow
// so we'll persist it to update localStorage so it doesn't throw an error
// next time the page is loaded.
this.persistGenie()
}
}

itemToString = item => item && item.magicWords.join(', ');

render() {
Expand All @@ -92,6 +114,9 @@ class QuickActions extends React.Component {
highlightedIndex,
}) => {
const inputProps = getInputProps({
onChange: ev => {
this.inputValue = ev.target.value
},
innerRef: el => el && el.focus(),
onKeyUp: this.handleKeyUp,
// Timeout so the fuzzy handler can still select the module
Expand Down