From 40f72278a99689734cc9a2c83bc13542d1c39beb Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Fri, 6 Oct 2023 11:34:44 +0530 Subject: [PATCH] fix: team collection resetting on unmount within app lifecycle (#3396) * fix: team collection resetting on unmount within app lifecycle * chore: linting * refactor: eliminate redundancy * chore: update comment about the watcher purpose --------- Co-authored-by: jamesgeorge007 --- .../src/components/collections/index.vue | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/hoppscotch-common/src/components/collections/index.vue b/packages/hoppscotch-common/src/components/collections/index.vue index a7bd98fe9..1d015572e 100644 --- a/packages/hoppscotch-common/src/components/collections/index.vue +++ b/packages/hoppscotch-common/src/components/collections/index.vue @@ -377,22 +377,26 @@ const updateSelectedTeam = (team: SelectedTeam) => { const workspace = workspaceService.currentWorkspace // Used to switch collection type and team when user switch workspace in the global workspace switcher -// Check if there is a teamID in the workspace, if yes, switch to team collection and select the team -// If there is no teamID, switch to my environment +// Check if there is a teamID in the workspace, if yes, switch to team collections and select the team +// If there is no teamID, switch to my collections watch( () => { const space = workspace.value - - if (space.type === "personal") return undefined - else return space.teamID + return space.type === "personal" ? undefined : space.teamID }, (teamID) => { - if (!teamID) { - switchToMyCollections() - } else if (teamID) { + if (teamID) { const team = myTeams.value?.find((t) => t.id === teamID) - if (team) updateSelectedTeam(team) + if (team) { + updateSelectedTeam(team) + } + return } + + return switchToMyCollections() + }, + { + immediate: true, } )