Skip to content

Commit

Permalink
fix: restructured
Browse files Browse the repository at this point in the history
  • Loading branch information
JureSotosek committed Sep 16, 2018
1 parent af4a186 commit 2c29005
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/emma.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ class Emma extends Component {

this.handleKeyPress = this.handleKeyPress.bind(this);
this.handleQueryChange = this.handleQueryChange.bind(this);
this.handleInstall = this.handleInstall.bind(this);
this.handleTogglePackage = this.handleTogglePackage.bind(this);
this.fetchSearch = this.fetchSearch.bind(this);
this.fetchSuggestions = this.fetchSuggestions.bind(this);
this.handleInstall = this.handleInstall.bind(this);
}

componentDidMount() {
Expand Down Expand Up @@ -351,25 +351,6 @@ class Emma extends Component {
this.fetchSearch();
}

async handleTogglePackage(pkg) {
const { selectedPackages: selectedPackagesOld } = this.state;

const exists = selectedPackagesOld.some(
({ objectID }) => objectID === pkg.objectID
);

if (exists) {
return;
}

await this.setState({
query: '',
selectedPackages: [...selectedPackagesOld, pkg]
});

this.fetchSuggestions();
}

async fetchSearch() {
const { query } = this.state;

Expand All @@ -395,6 +376,25 @@ class Emma extends Component {
}
}

async handleTogglePackage(pkg) {
const { selectedPackages: selectedPackagesOld } = this.state;

const exists = selectedPackagesOld.some(
({ objectID }) => objectID === pkg.objectID
);

if (exists) {
return;
}

await this.setState({
query: '',
selectedPackages: [...selectedPackagesOld, pkg]
});

this.fetchSuggestions();
}

async fetchSuggestions() {
const { selectedPackages } = this.state;
const { dev: isDev } = this.props;
Expand Down Expand Up @@ -441,7 +441,6 @@ class Emma extends Component {
const args = [...arg, ...packages, ...(isDev ? [devArg] : [])];

// Install the queries

try {
await execa.sync(env, args, { stdio: `inherit` });
} catch (err) {
Expand Down

0 comments on commit 2c29005

Please sign in to comment.