diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index f7d8352a2..b20e316ae 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -24,6 +24,7 @@ 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'] @@ -143,7 +144,6 @@ declare module 'vue' { IconLucideAlertTriangle: typeof import('~icons/lucide/alert-triangle')['default'] IconLucideArrowLeft: typeof import('~icons/lucide/arrow-left')['default'] IconLucideArrowUpRight: typeof import('~icons/lucide/arrow-up-right')['default'] - IconLucideBrush: typeof import('~icons/lucide/brush')['default'] IconLucideCheckCircle: typeof import('~icons/lucide/check-circle')['default'] IconLucideChevronRight: typeof import('~icons/lucide/chevron-right')['default'] IconLucideGlobe: typeof import('~icons/lucide/globe')['default'] diff --git a/packages/hoppscotch-common/src/components/app/Header.vue b/packages/hoppscotch-common/src/components/app/Header.vue index 533c96cd4..459d18552 100644 --- a/packages/hoppscotch-common/src/components/app/Header.vue +++ b/packages/hoppscotch-common/src/components/app/Header.vue @@ -249,11 +249,12 @@ 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() @@ -281,11 +282,10 @@ const currentUser = useReadonlyStream( const selectedTeam = ref() // TeamList-Adapter -const workspaceService = useService(WorkspaceService) -const teamListAdapter = workspaceService.acquireTeamListAdapter(null) +const teamListAdapter = new TeamListAdapter(true) const myTeams = useReadonlyStream(teamListAdapter.teamList$, null) -const workspace = workspaceService.currentWorkspace +const workspace = useReadonlyStream(workspaceStatus$, { type: "personal" }) const workspaceName = computed(() => workspace.value.type === "personal" @@ -297,18 +297,20 @@ const refetchTeams = () => { teamListAdapter.fetchList() } +onLoggedIn(() => { + !teamListAdapter.isInitialized && teamListAdapter.initialize() +}) + watch( () => myTeams.value, (newTeams) => { - const space = workspace.value - - if (newTeams && space.type === "team" && space.teamID) { - const team = newTeams.find((team) => team.id === space.teamID) + if (newTeams && workspace.value.type === "team" && workspace.value.teamID) { + const team = newTeams.find((team) => team.id === workspace.value.teamID) if (team) { selectedTeam.value = team // Update the workspace name if it's not the same as the updated team name - if (team.name !== space.teamName) { - workspaceService.updateWorkspaceTeamName(team.name) + if (team.name !== workspace.value.teamName) { + updateWorkspaceTeamName(workspace.value, team.name) } } } diff --git a/packages/hoppscotch-common/src/components/collections/index.vue b/packages/hoppscotch-common/src/components/collections/index.vue index 217cb4036..05de6b7d7 100644 --- a/packages/hoppscotch-common/src/components/collections/index.vue +++ b/packages/hoppscotch-common/src/components/collections/index.vue @@ -162,8 +162,10 @@ 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" @@ -219,6 +221,7 @@ 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, @@ -237,8 +240,6 @@ 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() @@ -315,8 +316,7 @@ const creatingGistCollection = ref(false) const importingMyCollections = ref(false) // TeamList-Adapter -const workspaceService = useService(WorkspaceService) -const teamListAdapter = workspaceService.acquireTeamListAdapter(null) +const teamListAdapter = new TeamListAdapter(true) const myTeams = useReadonlyStream(teamListAdapter.teamList$, null) const REMEMBERED_TEAM_ID = useLocalState("REMEMBERED_TEAM_ID") const teamListFetched = ref(false) @@ -374,18 +374,17 @@ const updateSelectedTeam = (team: SelectedTeam) => { } } -const workspace = workspaceService.currentWorkspace +onLoggedIn(() => { + !teamListAdapter.isInitialized && teamListAdapter.initialize() +}) + +const workspace = useReadonlyStream(workspaceStatus$, { type: "personal" }) // 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( - () => { - const space = workspace.value - - if (space.type === "personal") return undefined - else return space.teamID - }, + () => workspace.value.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 70c1218fa..1b0b0236f 100644 --- a/packages/hoppscotch-common/src/components/environments/Selector.vue +++ b/packages/hoppscotch-common/src/components/environments/Selector.vue @@ -308,6 +308,7 @@ 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" @@ -315,10 +316,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 = | { @@ -352,18 +353,21 @@ type EnvironmentType = "my-environments" | "team-environments" const myEnvironments = useReadonlyStream(environments$, []) -const workspaceService = useService(WorkspaceService) -const workspace = workspaceService.currentWorkspace +const workspace = useReadonlyStream(workspaceStatus$, { type: "personal" }) // TeamList-Adapter -const teamListAdapter = workspaceService.acquireTeamListAdapter(null) +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 - workspaceService.changeWorkspace({ + 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 6b4aab1e8..b2a5ff0ab 100644 --- a/packages/hoppscotch-common/src/components/environments/index.vue +++ b/packages/hoppscotch-common/src/components/environments/index.vue @@ -58,15 +58,16 @@ 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() @@ -98,8 +99,7 @@ const currentUser = useReadonlyStream( ) // TeamList-Adapter -const workspaceService = useService(WorkspaceService) -const teamListAdapter = workspaceService.acquireTeamListAdapter(null) +const teamListAdapter = new TeamListAdapter(true) const myTeams = useReadonlyStream(teamListAdapter.teamList$, null) const teamListFetched = ref(false) const REMEMBERED_TEAM_ID = useLocalState("REMEMBERED_TEAM_ID") @@ -152,7 +152,11 @@ watch( } ) -const workspace = workspaceService.currentWorkspace +onLoggedIn(() => { + !teamListAdapter.isInitialized && teamListAdapter.initialize() +}) + +const workspace = useReadonlyStream(workspaceStatus$, { type: "personal" }) // 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 90045d884..307e70fed 100644 --- a/packages/hoppscotch-common/src/components/http/TestResult.vue +++ b/packages/hoppscotch-common/src/components/http/TestResult.vue @@ -216,8 +216,7 @@ import IconClose from "~icons/lucide/x" import { useColorMode } from "~/composables/theming" import { useVModel } from "@vueuse/core" -import { useService } from "dioc/vue" -import { WorkspaceService } from "~/services/workspace.service" +import { workspaceStatus$ } from "~/newstore/workspace" const props = defineProps<{ modelValue: HoppTestResult | null | undefined @@ -232,8 +231,7 @@ const testResults = useVModel(props, "modelValue", emit) const t = useI18n() const colorMode = useColorMode() -const workspaceService = useService(WorkspaceService) -const workspace = workspaceService.currentWorkspace +const workspace = useReadonlyStream(workspaceStatus$, { type: "personal" }) 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 cd883e631..aa5704bef 100644 --- a/packages/hoppscotch-common/src/components/teams/index.vue +++ b/packages/hoppscotch-common/src/components/teams/index.vue @@ -69,11 +69,11 @@