Fix highlighting of current user in contributor list

Fixes #72

Introduces a helper to determine if a contributor is the current user.
This commit is contained in:
2019-04-03 01:34:39 +02:00
parent 2954955e39
commit 88be3525b5
4 changed files with 56 additions and 5 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
<tbody> <tbody>
{{#each contributors as |contributor|}} {{#each contributors as |contributor|}}
<tr role="button" class={{if contributor.isCurrentUser "current-user"}} {{action "toggleContributorInfo" contributor}}> <tr role="button" class={{if (is-current-user contributor) "current-user"}} {{action "toggleContributorInfo" contributor}}>
<td class="person"> <td class="person">
<img class="avatar" src={{contributor.avatarURL}} alt=""> <img class="avatar" src={{contributor.avatarURL}} alt="">
{{contributor.name}} {{contributor.name}}
@@ -10,7 +10,7 @@
<span class="symbol">₭S</span> <span class="symbol">₭S</span>
</td> </td>
</tr> </tr>
<tr class="metadata {{if contributor.isCurrentUser "current-user"}} {{if contributor.showMetadata "visible"}}"> <tr class="metadata {{if (is-current-user contributor) "current-user"}} {{if contributor.showMetadata "visible"}}">
<td colspan="2"> <td colspan="2">
<ul> <ul>
<li><a href="https://testnet.etherscan.io/address/{{contributor.account}}">Inspect Ethereum transactions</a></li> <li><a href="https://testnet.etherscan.io/address/{{contributor.account}}">Inspect Ethereum transactions</a></li>
+16
View File
@@ -0,0 +1,16 @@
import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
import { isPresent } from '@ember/utils';
export default Helper.extend({
kredits: service(),
currentUser: alias('kredits.currentUser'),
compute([contributor]) {
return isPresent(contributor) && isPresent(this.currentUser) &&
contributor.account === this.currentUser.account;
}
});
-3
View File
@@ -19,9 +19,6 @@ export default EmberObject.extend({
wiki_username: null, wiki_username: null,
ipfsData: '', ipfsData: '',
// Deprecated
isCurrentUser: false,
avatarURL: computed('github_uid', function() { avatarURL: computed('github_uid', function() {
let github_uid = this.github_uid; let github_uid = this.github_uid;
if (github_uid) { if (github_uid) {
@@ -0,0 +1,38 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Helper | is-current-user', function (hooks) {
setupTest(hooks);
test('should be true if the given contributor is the current user', function (assert) {
const kredits = this.owner.lookup('service:kredits');
const currentUser = {
account: '0xD4264570B12dA659Ee4BBd41c3509B7b1F9c23AC'
}
kredits.set('currentUser', currentUser);
const contributor = {
account: '0xD4264570B12dA659Ee4BBd41c3509B7b1F9c23AC'
}
const isCurrentUser = this.owner.factoryFor('helper:is-current-user').create();
assert.ok(isCurrentUser.compute([contributor]));
});
test('should be false if the given contributor is not the current user', function (assert) {
const kredits = this.owner.lookup('service:kredits');
const currentUser = {
account: '0xD4264570B12dA659Ee4BBd41c3509B7b1F9c23AC'
}
kredits.set('currentUser', currentUser);
const contributor = {
account: '0xA4264570B12dA659Ee4BBd51c3509B7b1F9c23AC'
}
const isCurrentUser = this.owner.factoryFor('helper:is-current-user').create();
assert.notOk(isCurrentUser.compute([contributor]));
});
});