Skip to content

Commit 8f62c4c

Browse files
committed
Merge keyword.index into parent route
1 parent a68c56e commit 8f62c4c

File tree

6 files changed

+26
-37
lines changed

6 files changed

+26
-37
lines changed

app/controllers/keyword/index.js renamed to app/controllers/keyword.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { tracked } from '@glimmer/tracking';
33

44
import { reads } from 'macro-decorators';
55

6-
import { pagination } from '../../utils/pagination';
6+
import { pagination } from '../utils/pagination';
77

88
export default class KeywordIndexController extends Controller {
99
queryParams = ['page', 'per_page', 'sort'];
1010
@tracked page = '1';
1111
@tracked per_page = 10;
1212
@tracked sort = 'recent-downloads';
1313

14-
@reads('model.meta.total') totalItems;
14+
@reads('model.crates.meta.total') totalItems;
1515

1616
@pagination() pagination;
1717

app/routes/keyword.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
import Route from '@ember/routing/route';
2+
import { inject as service } from '@ember/service';
23

3-
export default class KeywordRoute extends Route {
4-
model({ keyword_id }) {
5-
return keyword_id;
4+
export default class KeywordIndexRoute extends Route {
5+
@service router;
6+
@service store;
7+
8+
queryParams = {
9+
page: { refreshModel: true },
10+
sort: { refreshModel: true },
11+
};
12+
13+
async model(params, transition) {
14+
let { keyword_id: keyword, page, sort } = params;
15+
16+
try {
17+
let crates = await this.store.query('crate', { keyword, page, sort });
18+
return { keyword, crates };
19+
} catch (error) {
20+
let title = `${keyword}: Failed to load crates`;
21+
this.router.replaceWith('catch-all', { transition, error, title, tryAgain: true });
22+
}
623
}
724
}

app/routes/keyword/index.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

app/templates/index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
{{#each this.model.popular_keywords as |keyword|}}
166166
<li>
167167
<FrontPageList::Item
168-
@link={{link "keyword" keyword}}
168+
@link={{link "keyword" keyword.id}}
169169
@title={{keyword.id}}
170170
@subtitle="{{format-num keyword.crates_cnt}} crates"
171171
/>

app/templates/keyword/index.hbs renamed to app/templates/keyword.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{{page-title this.keyword ' - Keywords'}}
1+
{{page-title @model.keyword ' - Keywords'}}
22

3-
<PageHeader @title="All Crates" @suffix="for keyword '{{this.keyword}}'"/>
3+
<PageHeader @title="All Crates" @suffix="for keyword '{{@model.keyword}}'"/>
44

55
<div local-class="results-meta">
66
<ResultsCount
@@ -22,6 +22,6 @@
2222
</div>
2323
</div>
2424

25-
<CrateList @crates={{this.model}} local-class="list" />
25+
<CrateList @crates={{@model.crates}} local-class="list" />
2626

2727
<Pagination @pagination={{this.pagination}} />

app/templates/keyword/error.hbs

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)