Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions app/components/crate-header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
</div>
{{/if}}

{{#if @crate.keywords}}
{{#if this.keywords}}
<ul local-class="keywords">
{{#each @crate.keywords as |keyword|}}
{{#each this.keywords as |keyword|}}
<li>
<LinkTo @route="keyword" @model={{keyword.id}} data-test-keyword={{keyword.id}}>
<span local-class="hash">#</span>{{keyword.id}}
Expand Down
29 changes: 28 additions & 1 deletion app/components/crate-header.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';

import { task } from 'ember-concurrency';
import { alias } from 'macro-decorators';

export default class CrateHeader extends Component {
@service session;

@alias('loadKeywordsTask.last.value') keywords;
@alias('loadOwnerUserTask.last.value') ownerUser;

constructor() {
super(...arguments);

this.loadKeywordsTask.perform().catch(() => {
// ignore all errors and just don't display keywords if the request fails
});
this.loadOwnerUserTask.perform().catch(() => {
// ignore all errors and just don't display settings if the request fails
});
}

get isOwner() {
return this.args.crate.owner_user.findBy('id', this.session.currentUser?.id);
let ownerUser = this.ownerUser ?? [];
let currentUserId = this.session.currentUser?.id;
return ownerUser.some(({ id }) => id === currentUserId);
}

loadKeywordsTask = task(async () => {
return (await this.args.crate?.keywords) ?? [];
});

loadOwnerUserTask = task(async () => {
return (await this.args.crate?.owner_user) ?? [];
});
}
Loading