From fe3816501cd630a933741094d8dfd836885a3c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sun, 15 Jan 2023 13:57:13 +0800 Subject: [PATCH] Fix dashboard hanging when loading app from contributor URL Loading the app from /dashboard/contributors/:id is failing, because the contributors are loaded later. This fetches the requested contributor separately when launching the app from a contributor profile URL. --- app/routes/dashboard/contributors/show.js | 8 +++++++- app/services/kredits.js | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/routes/dashboard/contributors/show.js b/app/routes/dashboard/contributors/show.js index c7e5d3b..950cf93 100644 --- a/app/routes/dashboard/contributors/show.js +++ b/app/routes/dashboard/contributors/show.js @@ -8,7 +8,13 @@ export default Route.extend({ contributors: alias('kredits.contributors'), model (params) { - return this.contributors.findBy('id', params.id); + const contributor = this.contributors.findBy('id', params.id); + + if (contributor) { + return contributor; + } else { + return this.kredits.fetchContributor(params.id); + } }, setupController (controller, model) { diff --git a/app/services/kredits.js b/app/services/kredits.js index dd8f24e..3436e7e 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -274,6 +274,12 @@ export default Service.extend({ }); }, + async fetchContributor (id) { + console.debug(`[kredits] Fetching contributor from the network`); + return this.kredits.Contributor.getById(id) + .then(data => this.loadContributorFromData(data)) + }, + fetchContributors () { console.debug(`[kredits] Fetching all contributors from the network`); return this.kredits.Contributor.all()