Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix: team environment lost when route changes (#3113)
Nivedin1f3f8464ea89
diff --git a/packages/hoppscotch-common/src/components/environments/Selector.vue b/packages/hoppscotch-common/src/components/environments/Selector.vueindex 955e9af2f..604c1344e 100644--- a/packages/hoppscotch-common/src/components/environments/Selector.vue+++ b/packages/hoppscotch-common/src/components/environments/Selector.vue@@ -97,7 +97,7 @@<HoppSmartSpinner class="my-4" /><span class="text-secondaryLight">{{ t("state.loading") }}</span></div>- <div v-if="isTeamSelected" class="flex flex-col">+ <div v-else-if="isTeamSelected" class="flex flex-col"><HoppSmartItemv-for="(gen, index) in teamEnvironmentList":key="`gen-team-${index}`"@@ -161,10 +161,14 @@ import {selectedEnvironmentIndex$,setSelectedEnvironmentIndex,} from "~/newstore/environments"-import { workspaceStatus$ } from "~/newstore/workspace"+import { changeWorkspace, workspaceStatus$ } from "~/newstore/workspace"import TeamEnvironmentAdapter from "~/helpers/teams/TeamEnvironmentAdapter"import { useColorMode } from "@composables/theming"import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"+import TeamListAdapter from "~/helpers/teams/TeamListAdapter"+import { useLocalState } from "~/newstore/localstate"+import { onLoggedIn } from "~/composables/auth"+import { GetMyTeamsQuery } from "~/helpers/backend/graphql"const breakpoints = useBreakpoints(breakpointsTailwind)const mdAndLarger = breakpoints.greater("md")@@ -213,6 +217,38 @@ watch(})+// TeamList-Adapter+const teamListAdapter = new TeamListAdapter(true)+const myTeams = useReadonlyStream(teamListAdapter.teamList$, null)+const teamListFetched = ref(false)+const REMEMBERED_TEAM_ID = useLocalState("REMEMBERED_TEAM_ID")++onLoggedIn(() => {+ !teamListAdapter.isInitialized && teamListAdapter.initialize()+})++const switchToTeamWorkspace = (team: GetMyTeamsQuery["myTeams"][number]) => {+ REMEMBERED_TEAM_ID.value = team.id+ changeWorkspace({+ teamID: team.id,+ teamName: team.name,+ type: "team",+ })+}++watch(+ () => myTeams.value,+ (newTeams) => {+ if (newTeams && !teamListFetched.value) {+ teamListFetched.value = true+ if (REMEMBERED_TEAM_ID.value) {+ const team = newTeams.find((t) => t.id === REMEMBERED_TEAM_ID.value)+ if (team) switchToTeamWorkspace(team)+ }+ }+ }+)+const selectedEnv = computed(() => {if (selectedEnvironmentIndex.value.type === "MY_ENV") {return {