diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index f51296606..f7d8352a2 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -24,7 +24,6 @@ declare module 'vue' { AppShortcutsEntry: typeof import('./components/app/ShortcutsEntry.vue')['default'] AppShortcutsPrompt: typeof import('./components/app/ShortcutsPrompt.vue')['default'] AppSidenav: typeof import('./components/app/Sidenav.vue')['default'] - AppSocial: typeof import('./components/app/Social.vue')['default'] AppSpotlight: typeof import('./components/app/spotlight/index.vue')['default'] AppSpotlightEntry: typeof import('./components/app/spotlight/Entry.vue')['default'] AppSpotlightEntryGQLHistory: typeof import('./components/app/spotlight/entry/GQLHistory.vue')['default'] diff --git a/packages/hoppscotch-common/src/components/app/Header.vue b/packages/hoppscotch-common/src/components/app/Header.vue index 459d18552..533c96cd4 100644 --- a/packages/hoppscotch-common/src/components/app/Header.vue +++ b/packages/hoppscotch-common/src/components/app/Header.vue @@ -249,12 +249,11 @@ import { platform } from "~/platform" import { useI18n } from "@composables/i18n" import { useReadonlyStream } from "@composables/stream" import { defineActionHandler, invokeAction } from "@helpers/actions" -import { workspaceStatus$, updateWorkspaceTeamName } from "~/newstore/workspace" -import TeamListAdapter from "~/helpers/teams/TeamListAdapter" -import { onLoggedIn } from "~/composables/auth" import { GetMyTeamsQuery } from "~/helpers/backend/graphql" import { getPlatformSpecialKey } from "~/helpers/platformutils" import { useToast } from "~/composables/toast" +import { WorkspaceService } from "~/services/workspace.service" +import { useService } from "dioc/vue" const t = useI18n() const toast = useToast() @@ -282,10 +281,11 @@ const currentUser = useReadonlyStream( const selectedTeam = ref() // TeamList-Adapter -const teamListAdapter = new TeamListAdapter(true) +const workspaceService = useService(WorkspaceService) +const teamListAdapter = workspaceService.acquireTeamListAdapter(null) const myTeams = useReadonlyStream(teamListAdapter.teamList$, null) -const workspace = useReadonlyStream(workspaceStatus$, { type: "personal" }) +const workspace = workspaceService.currentWorkspace const workspaceName = computed(() => workspace.value.type === "personal" @@ -297,20 +297,18 @@ const refetchTeams = () => { teamListAdapter.fetchList() } -onLoggedIn(() => { - !teamListAdapter.isInitialized && teamListAdapter.initialize() -}) - watch( () => myTeams.value, (newTeams) => { - if (newTeams && workspace.value.type === "team" && workspace.value.teamID) { - const team = newTeams.find((team) => team.id === workspace.value.teamID) + const space = workspace.value + + if (newTeams && space.type === "team" && space.teamID) { + const team = newTeams.find((team) => team.id === space.teamID) if (team) { selectedTeam.value = team // Update the workspace name if it's not the same as the updated team name - if (team.name !== workspace.value.teamName) { - updateWorkspaceTeamName(workspace.value, team.name) + if (team.name !== space.teamName) { + workspaceService.updateWorkspaceTeamName(team.name) } } } diff --git a/packages/hoppscotch-common/src/components/collections/index.vue b/packages/hoppscotch-common/src/components/collections/index.vue index 05de6b7d7..217cb4036 100644 --- a/packages/hoppscotch-common/src/components/collections/index.vue +++ b/packages/hoppscotch-common/src/components/collections/index.vue @@ -162,10 +162,8 @@ import { computed, nextTick, PropType, ref, watch } from "vue" import { useToast } from "@composables/toast" import { useI18n } from "@composables/i18n" import { Picked } from "~/helpers/types/HoppPicked" -import TeamListAdapter from "~/helpers/teams/TeamListAdapter" import { useReadonlyStream } from "~/composables/stream" import { useLocalState } from "~/newstore/localstate" -import { onLoggedIn } from "~/composables/auth" import { GetMyTeamsQuery } from "~/helpers/backend/graphql" import { pipe } from "fp-ts/function" import * as TE from "fp-ts/TaskEither" @@ -221,7 +219,6 @@ import { import * as E from "fp-ts/Either" import { platform } from "~/platform" import { createCollectionGists } from "~/helpers/gist" -import { workspaceStatus$ } from "~/newstore/workspace" import { createNewTab, currentActiveTab, @@ -240,6 +237,8 @@ import { } from "~/helpers/collection/collection" import { currentReorderingStatus$ } from "~/newstore/reordering" import { defineActionHandler } from "~/helpers/actions" +import { WorkspaceService } from "~/services/workspace.service" +import { useService } from "dioc/vue" const t = useI18n() const toast = useToast() @@ -316,7 +315,8 @@ const creatingGistCollection = ref(false) const importingMyCollections = ref(false) // TeamList-Adapter -const teamListAdapter = new TeamListAdapter(true) +const workspaceService = useService(WorkspaceService) +const teamListAdapter = workspaceService.acquireTeamListAdapter(null) const myTeams = useReadonlyStream(teamListAdapter.teamList$, null) const REMEMBERED_TEAM_ID = useLocalState("REMEMBERED_TEAM_ID") const teamListFetched = ref(false) @@ -374,17 +374,18 @@ const updateSelectedTeam = (team: SelectedTeam) => { } } -onLoggedIn(() => { - !teamListAdapter.isInitialized && teamListAdapter.initialize() -}) - -const workspace = useReadonlyStream(workspaceStatus$, { type: "personal" }) +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 watch( - () => workspace.value.teamID, + () => { + const space = workspace.value + + if (space.type === "personal") return undefined + else return space.teamID + }, (teamID) => { if (!teamID) { switchToMyCollections() diff --git a/packages/hoppscotch-common/src/components/environments/Selector.vue b/packages/hoppscotch-common/src/components/environments/Selector.vue index 1b0b0236f..70c1218fa 100644 --- a/packages/hoppscotch-common/src/components/environments/Selector.vue +++ b/packages/hoppscotch-common/src/components/environments/Selector.vue @@ -308,7 +308,6 @@ import { selectedEnvironmentIndex$, setSelectedEnvironmentIndex, } from "~/newstore/environments" -import { changeWorkspace, workspaceStatus$ } from "~/newstore/workspace" import TeamEnvironmentAdapter from "~/helpers/teams/TeamEnvironmentAdapter" import { useColorMode } from "@composables/theming" import { breakpointsTailwind, useBreakpoints } from "@vueuse/core" @@ -316,10 +315,10 @@ import { invokeAction } from "~/helpers/actions" import { TeamEnvironment } from "~/helpers/teams/TeamEnvironment" import { Environment } from "@hoppscotch/data" import { onMounted } from "vue" -import { onLoggedIn } from "~/composables/auth" -import TeamListAdapter from "~/helpers/teams/TeamListAdapter" import { useLocalState } from "~/newstore/localstate" import { GetMyTeamsQuery } from "~/helpers/backend/graphql" +import { useService } from "dioc/vue" +import { WorkspaceService } from "~/services/workspace.service" type Scope = | { @@ -353,21 +352,18 @@ type EnvironmentType = "my-environments" | "team-environments" const myEnvironments = useReadonlyStream(environments$, []) -const workspace = useReadonlyStream(workspaceStatus$, { type: "personal" }) +const workspaceService = useService(WorkspaceService) +const workspace = workspaceService.currentWorkspace // TeamList-Adapter -const teamListAdapter = new TeamListAdapter(true) +const teamListAdapter = workspaceService.acquireTeamListAdapter(null) 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({ + workspaceService.changeWorkspace({ teamID: team.id, teamName: team.name, type: "team", diff --git a/packages/hoppscotch-common/src/components/environments/index.vue b/packages/hoppscotch-common/src/components/environments/index.vue index b2a5ff0ab..6b4aab1e8 100644 --- a/packages/hoppscotch-common/src/components/environments/index.vue +++ b/packages/hoppscotch-common/src/components/environments/index.vue @@ -58,16 +58,15 @@ import { } from "~/newstore/environments" import TeamEnvironmentAdapter from "~/helpers/teams/TeamEnvironmentAdapter" import { defineActionHandler } from "~/helpers/actions" -import { workspaceStatus$ } from "~/newstore/workspace" -import TeamListAdapter from "~/helpers/teams/TeamListAdapter" import { useLocalState } from "~/newstore/localstate" -import { onLoggedIn } from "~/composables/auth" import { pipe } from "fp-ts/function" import * as TE from "fp-ts/TaskEither" import { GQLError } from "~/helpers/backend/GQLClient" import { deleteEnvironment } from "~/newstore/environments" import { deleteTeamEnvironment } from "~/helpers/backend/mutations/TeamEnvironment" import { useToast } from "~/composables/toast" +import { WorkspaceService } from "~/services/workspace.service" +import { useService } from "dioc/vue" const t = useI18n() const toast = useToast() @@ -99,7 +98,8 @@ const currentUser = useReadonlyStream( ) // TeamList-Adapter -const teamListAdapter = new TeamListAdapter(true) +const workspaceService = useService(WorkspaceService) +const teamListAdapter = workspaceService.acquireTeamListAdapter(null) const myTeams = useReadonlyStream(teamListAdapter.teamList$, null) const teamListFetched = ref(false) const REMEMBERED_TEAM_ID = useLocalState("REMEMBERED_TEAM_ID") @@ -152,11 +152,7 @@ watch( } ) -onLoggedIn(() => { - !teamListAdapter.isInitialized && teamListAdapter.initialize() -}) - -const workspace = useReadonlyStream(workspaceStatus$, { type: "personal" }) +const workspace = workspaceService.currentWorkspace // Switch to my environments if workspace is personal and to team environments if workspace is team // also resets selected environment if workspace is personal and the previous selected environment was a team environment diff --git a/packages/hoppscotch-common/src/components/http/TestResult.vue b/packages/hoppscotch-common/src/components/http/TestResult.vue index 307e70fed..90045d884 100644 --- a/packages/hoppscotch-common/src/components/http/TestResult.vue +++ b/packages/hoppscotch-common/src/components/http/TestResult.vue @@ -216,7 +216,8 @@ import IconClose from "~icons/lucide/x" import { useColorMode } from "~/composables/theming" import { useVModel } from "@vueuse/core" -import { workspaceStatus$ } from "~/newstore/workspace" +import { useService } from "dioc/vue" +import { WorkspaceService } from "~/services/workspace.service" const props = defineProps<{ modelValue: HoppTestResult | null | undefined @@ -231,7 +232,8 @@ const testResults = useVModel(props, "modelValue", emit) const t = useI18n() const colorMode = useColorMode() -const workspace = useReadonlyStream(workspaceStatus$, { type: "personal" }) +const workspaceService = useService(WorkspaceService) +const workspace = workspaceService.currentWorkspace const showMyEnvironmentDetailsModal = ref(false) const showTeamEnvironmentDetailsModal = ref(false) diff --git a/packages/hoppscotch-common/src/components/teams/index.vue b/packages/hoppscotch-common/src/components/teams/index.vue index aa5704bef..cd883e631 100644 --- a/packages/hoppscotch-common/src/components/teams/index.vue +++ b/packages/hoppscotch-common/src/components/teams/index.vue @@ -69,11 +69,11 @@