Skip to content

Commit

Permalink
Merge pull request #10182 from eth3lbert/fix-crate-header
Browse files Browse the repository at this point in the history
crate-header: Fix deprecation warnings
  • Loading branch information
Turbo87 authored Dec 11, 2024
2 parents 88ea6cb + 914964e commit 3dc5dd2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
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) ?? [];
});
}

0 comments on commit 3dc5dd2

Please sign in to comment.