🐛 Fix sidebar members number not updated after member create & delete (#15378)

no issue

Dynamically updates member count on the sidebar when creating, deleting and uploading members.
This commit is contained in:
Hakim Razalan 2022-09-09 14:36:14 +08:00 committed by GitHub
parent 8935f53d63
commit f133c85258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 9 deletions

View File

@ -94,13 +94,13 @@
{{#if (eq this.router.currentRouteName "members.index")}}
<LinkTo @route="members" @current-when="members member" @query={{reset-query-params "members.index"}} data-test-nav="members">{{svg-jar "members"}}Members
{{#unless this.memberCountLoading}}
<span class="gh-nav-member-count">{{format-number this.memberCount}}</span>
<span class="gh-nav-member-count">{{format-number this.membersStats.memberCount}}</span>
{{/unless}}
</LinkTo>
{{else}}
<LinkTo @route="members" @current-when="members member" data-test-nav="members">{{svg-jar "members"}}Members
{{#unless this.memberCountLoading}}
<span class="gh-nav-member-count">{{format-number this.memberCount}}</span>
<span class="gh-nav-member-count">{{format-number this.membersStats.memberCount}}</span>
{{/unless}}
</LinkTo>
{{/if}}

View File

@ -31,7 +31,6 @@ export default class Main extends Component.extend(ShortcutsMixin) {
iconStyle = '';
iconClass = '';
memberCountLoading = true;
memberCount = 0;
shortcuts = null;
@match('router.currentRouteName', /^settings\.integration/)
@ -110,13 +109,8 @@ export default class Main extends Component.extend(ShortcutsMixin) {
@task(function* () {
try {
this.set('memberCountLoading', true);
const stats = yield this.membersStats.fetchMemberCount();
yield this.membersStats.fetchMemberCount();
this.set('memberCountLoading', false);
if (stats) {
const {free, paid, comped} = stats.meta.totals;
const total = free + paid + comped || 0;
this.set('memberCount', total);
}
} catch (e) {
return false;
}

View File

@ -234,6 +234,7 @@ export default class MembersController extends Controller {
this.fetchLabelsTask.perform();
this.membersStats.invalidate();
this.membersStats.fetchCounts();
this.membersStats.fetchMemberCount();
}
@action

View File

@ -18,6 +18,16 @@ export default class MembersStatsService extends Service {
@tracked newsletterStats = null;
@tracked totalMemberCount = null;
get memberCount() {
let stats = this.totalMemberCount;
if (!stats) {
return 0;
}
const {free, paid, comped} = stats.meta.totals;
const total = free + paid + comped || 0;
return total;
}
fetch() {
let daysChanged = this._lastFetchedDays !== this.days;
let staleData = this._lastFetched && (new Date() - this._lastFetched) > ONE_MINUTE;