import Controller from '@ember/controller';
import { action, computed } from '@ember/object';
import { bool, readOnly } from '@ember/object/computed';

import { task } from 'ember-concurrency';

import { pagination } from '../utils/pagination';

export default class SearchController extends Controller {
  queryParams = ['all_keywords', 'page', 'per_page', 'q', 'sort'];
  q = null;
  page = '1';
  per_page = 10;

  @readOnly('dataTask.lastSuccessful.value') model;

  @computed('dataTask.{lastSuccessful,isRunning}')
  get hasData() {
    return this.dataTask.lastSuccessful || !this.dataTask.isRunning;
  }

  @computed('dataTask.{lastComplete,isRunning}')
  get firstResultPending() {
    return !this.dataTask.lastComplete && this.dataTask.isRunning;
  }

  @readOnly('model.meta.total') totalItems;

  @pagination() pagination;

  @computed('sort')
  get currentSortBy() {
    if (this.sort === 'downloads') {
      return 'All-Time Downloads';
    } else if (this.sort === 'recent-downloads') {
      return 'Recent Downloads';
    } else if (this.sort === 'recent-updates') {
      return 'Recent Updates';
    } else if (this.sort === 'new') {
      return 'Newly Added';
    } else {
      return 'Relevance';
    }
  }

  @bool('totalItems') hasItems;

  @action fetchData() {
    this.dataTask.perform().catch(() => {
      // we ignore errors here because they are handled in the template already
    });
  }

  @(task(function* () {
    let { all_keywords, page, per_page, q, sort } = this;

    if (q !== null) {
      q = q.trim();
    }

    return yield this.store.query('crate', { all_keywords, page, per_page, q, sort });
  }).restartable())
  dataTask;

  get exactMatch() {
    return this.model.find(it => it.exact_match);
  }

  get otherCrates() {
    return this.model.filter(it => !it.exact_match);
  }
}

@@ -56,18 +56,8 @@
 tion
-, computed
  %7D f
@@ -90,96 +90,132 @@
 t %7B 
-bool, readOnly %7D from '@ember/object/computed';%0A%0Aimport %7B task %7D from 'ember-concurrency
+tracked %7D from '@glimmer/tracking';%0A%0Aimport %7B task %7D from 'ember-concurrency';%0Aimport %7B bool, reads %7D from 'macro-decorators
 ';%0A%0A
@@ -393,16 +393,50 @@
 rt'%5D;%0A  
+@tracked all_keywords;%0A  @tracked 
 q = null
@@ -439,16 +439,25 @@
 null;%0A  
+@tracked 
 page = '
@@ -462,16 +462,25 @@
  '1';%0A  
+@tracked 
 per_page
@@ -485,16 +485,33 @@
 ge = 10;
+%0A  @tracked sort;
 %0A%0A  @rea
@@ -511,20 +511,17 @@
 %0A  @read
-Only
+s
 ('dataTa
@@ -558,59 +558,8 @@
 l;%0A%0A
-  @computed('dataTask.%7BlastSuccessful,isRunning%7D')%0A
   ge
@@ -650,57 +650,8 @@
  %7D%0A%0A
-  @computed('dataTask.%7BlastComplete,isRunning%7D')%0A
   ge
@@ -758,12 +758,9 @@
 read
-Only
+s
 ('mo
@@ -822,28 +822,8 @@
 n;%0A%0A
-  @computed('sort')%0A
   ge

Use `macro-decorators` instead of computed properties