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 <jamesgeorge998001@gmail.com>
This commit is contained in:
Andrew Bastin
2023-10-06 11:34:44 +05:30
committed by GitHub
parent f717704731
commit 40f72278a9

View File

@@ -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,
}
)