From 1f232c331c6730891396fbe10fb101336340f3c6 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 10 Sep 2022 12:56:34 +0100 Subject: [PATCH] Abstract out allTabs mutation so it doesn't end in a reactive infinite loop --- chartered-frontend/src/routes/(authed)/crates/[organisation]/+page.svelte | 10 +++++++++- chartered-frontend/src/routes/(authed)/crates/[organisation]/[crate]/+page.svelte | 10 +++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/chartered-frontend/src/routes/(authed)/crates/[organisation]/+page.svelte b/chartered-frontend/src/routes/(authed)/crates/[organisation]/+page.svelte index 408c393..2ff9192 100644 --- a/chartered-frontend/src/routes/(authed)/crates/[organisation]/+page.svelte +++ a/chartered-frontend/src/routes/(authed)/crates/[organisation]/+page.svelte @@ -50,7 +50,13 @@ // binding to the current tab the user has selected let currentTab = Tab.CRATES; - $: organisationPromise.then((org) => { + $: organisationPromise.then(filterTabsForOrg); + + /** + * Filters the tabs displayed to the user depending on their current permissions for the + * organisation. + */ + function filterTabsForOrg(org: CrateMembers) { if (org.members) { // user has access to the member page but the tab isn't currently being shown, so we should // add it @@ -75,7 +81,7 @@ currentTab = Tab.CRATES; } } - }); + } // contains the member the user is currently considering adding to the org & has not yet persisted to // the server. diff --git a/chartered-frontend/src/routes/(authed)/crates/[organisation]/[crate]/+page.svelte b/chartered-frontend/src/routes/(authed)/crates/[organisation]/[crate]/+page.svelte index d3a22c4..501024e 100644 --- a/chartered-frontend/src/routes/(authed)/crates/[organisation]/[crate]/+page.svelte +++ a/chartered-frontend/src/routes/(authed)/crates/[organisation]/[crate]/+page.svelte @@ -42,7 +42,13 @@ // binding to the current tab the user has selected let currentTab = Tab.README; - $: cratePromise.then((crate) => { + $: cratePromise.then(filterTabsForCrate); + + /** + * Filters the tabs displayed to the user depending on their current permissions for the + * crate. + */ + function filterTabsForCrate(crate: Crate) { if (crate.permissions.includes('MANAGE_USERS')) { // user has access to the member page but the tab isn't currently being shown, so we should // add it @@ -67,7 +73,7 @@ currentTab = Tab.README; } } - }); + }
-- rgit 0.1.3