diff --git a/packages/hoppscotch-app/helpers/backend/caching/optimistic.ts b/packages/hoppscotch-app/helpers/backend/caching/optimistic.ts index 0ab5065d3..30d86a00b 100644 --- a/packages/hoppscotch-app/helpers/backend/caching/optimistic.ts +++ b/packages/hoppscotch-app/helpers/backend/caching/optimistic.ts @@ -1,13 +1,3 @@ import { GraphCacheOptimisticUpdaters } from "../graphql" -export const optimisticDefs: GraphCacheOptimisticUpdaters = { - deleteTeam: () => true, - leaveTeam: () => true, - renameTeam: ({ teamID, newName }) => ({ - __typename: "Team", - id: teamID, - name: newName, - }), - removeTeamMember: () => true, - revokeTeamInvitation: () => true, -} +export const optimisticDefs: GraphCacheOptimisticUpdaters = {} diff --git a/packages/hoppscotch-app/helpers/teams/TeamCollectionAdapter.ts b/packages/hoppscotch-app/helpers/teams/TeamCollectionAdapter.ts index fdcd24113..dcfe57a8f 100644 --- a/packages/hoppscotch-app/helpers/teams/TeamCollectionAdapter.ts +++ b/packages/hoppscotch-app/helpers/teams/TeamCollectionAdapter.ts @@ -183,6 +183,9 @@ function findCollWithReqIDInTree( export default class NewTeamCollectionAdapter { collections$: BehaviorSubject + // Stream to the list of collections/folders that are being loaded in + loadingCollections$: BehaviorSubject + private teamCollectionAdded$: Subscription | null private teamCollectionUpdated$: Subscription | null private teamCollectionRemoved$: Subscription | null @@ -192,6 +195,7 @@ export default class NewTeamCollectionAdapter { constructor(private teamID: string | null) { this.collections$ = new BehaviorSubject([]) + this.loadingCollections$ = new BehaviorSubject([]) this.teamCollectionAdded$ = null this.teamCollectionUpdated$ = null @@ -206,6 +210,7 @@ export default class NewTeamCollectionAdapter { changeTeamID(newTeamID: string | null) { this.teamID = newTeamID this.collections$.next([]) + this.loadingCollections$.next([]) this.unsubscribeSubscriptions() @@ -262,6 +267,11 @@ export default class NewTeamCollectionAdapter { private async loadRootCollections() { if (this.teamID === null) throw new Error("Team ID is null") + this.loadingCollections$.next([ + ...this.loadingCollections$.getValue(), + "root", + ]) + const totalCollections: TeamCollection[] = [] while (true) { @@ -276,8 +286,13 @@ export default class NewTeamCollectionAdapter { }, }) - if (E.isLeft(result)) + if (E.isLeft(result)) { + this.loadingCollections$.next( + this.loadingCollections$.getValue().filter((x) => x !== "root") + ) + throw new Error(`Error fetching root collections: ${result}`) + } totalCollections.push( ...result.right.rootCollectionsOfTeam.map( @@ -294,6 +309,10 @@ export default class NewTeamCollectionAdapter { break } + this.loadingCollections$.next( + this.loadingCollections$.getValue().filter((x) => x !== "root") + ) + this.collections$.next(totalCollections) } @@ -503,6 +522,11 @@ export default class NewTeamCollectionAdapter { const collections: TeamCollection[] = [] + this.loadingCollections$.next([ + ...this.loadingCollections$.getValue(), + collectionID, + ]) + while (true) { const data = await runGQLQuery({ query: GetCollectionChildrenDocument, @@ -515,10 +539,15 @@ export default class NewTeamCollectionAdapter { }, }) - if (E.isLeft(data)) + if (E.isLeft(data)) { + this.loadingCollections$.next( + this.loadingCollections$.getValue().filter((x) => x !== collectionID) + ) + throw new Error( `Child Collection Fetch Error for ${collectionID}: ${data.left}` ) + } collections.push( ...data.right.collection!.children.map( @@ -548,8 +577,13 @@ export default class NewTeamCollectionAdapter { }, }) - if (E.isLeft(data)) + if (E.isLeft(data)) { + this.loadingCollections$.next( + this.loadingCollections$.getValue().filter((x) => x !== collectionID) + ) + throw new Error(`Child Request Fetch Error for ${data}: ${data.left}`) + } requests.push( ...data.right.requestsInCollection.map((el) => { @@ -569,6 +603,10 @@ export default class NewTeamCollectionAdapter { collection.children = collections collection.requests = requests + this.loadingCollections$.next( + this.loadingCollections$.getValue().filter((x) => x !== collectionID) + ) + this.collections$.next(tree) } }