Browse Source

fix: UI not reflecting underlying service level changes immediately

Remove redundant issued handle updates happening in the `create(REST/GQL)Request` methods since it is accounted for via returning `getRequestHandle`. This led to dissociating the handle undergoing updates at the service level with that of the UI.
jamesgeorge007 9 months ago
parent
commit
e212caffe2

+ 5 - 100
packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts

@@ -182,6 +182,7 @@ export class PersonalWorkspaceProviderService
 
     const newCollectionID =
       this.restCollectionState.value.state.length.toString()
+    const newCollectionName = newCollection.name
 
     const newRootCollection = makeCollection({
       folders: [],
@@ -405,8 +406,7 @@ export class PersonalWorkspaceProviderService
       return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
     }
 
-    const { collectionID, providerID, workspaceID } =
-      parentCollectionHandleRef.value.data
+    const { collectionID } = parentCollectionHandleRef.value.data
 
     const insertionIndex = saveRESTRequestAs(collectionID, newRequest)
 
@@ -419,53 +419,6 @@ export class PersonalWorkspaceProviderService
       platform: "rest",
     })
 
-    const handleRefData = ref({
-      type: "ok" as const,
-      data: {
-        providerID,
-        workspaceID,
-        collectionID,
-        requestID,
-        request: newRequest,
-      },
-    })
-
-    const writableHandle = computed({
-      get() {
-        return handleRefData.value
-      },
-      set(newValue) {
-        handleRefData.value = newValue
-      },
-    })
-
-    const handleIsAlreadyIssued = this.issuedHandles.some((handle) => {
-      if (handle.value.type === "invalid") {
-        return false
-      }
-
-      if (!("requestID" in handle.value.data)) {
-        return false
-      }
-
-      const { request, ...dataProps } = handle.value.data
-
-      if (
-        isEqual(dataProps, {
-          providerID,
-          workspaceID,
-          collectionID,
-          requestID,
-        })
-      ) {
-        return true
-      }
-    })
-
-    if (!handleIsAlreadyIssued) {
-      this.issuedHandles.push(writableHandle)
-    }
-
     // TODO: Verify whether a request update action is reflected correctly in the handle being returned below
 
     const createdRequestHandle = await this.getRequestHandle(
@@ -1852,8 +1805,7 @@ export class PersonalWorkspaceProviderService
       return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
     }
 
-    const { collectionID, providerID, workspaceID } =
-      parentCollectionHandleRef.value.data
+    const { collectionID } = parentCollectionHandleRef.value.data
 
     saveGraphqlRequestAs(collectionID, newRequest)
 
@@ -1869,53 +1821,6 @@ export class PersonalWorkspaceProviderService
       workspaceType: "personal",
     })
 
-    const handleRefData = ref({
-      type: "ok" as const,
-      data: {
-        providerID,
-        workspaceID,
-        collectionID,
-        requestID,
-        request: newRequest,
-      },
-    })
-
-    const writableHandle = computed({
-      get() {
-        return handleRefData.value
-      },
-      set(newValue) {
-        handleRefData.value = newValue
-      },
-    })
-
-    const handleIsAlreadyIssued = this.issuedHandles.some((handle) => {
-      if (handle.value.type === "invalid") {
-        return false
-      }
-
-      if (!("requestID" in handle.value.data)) {
-        return false
-      }
-
-      const { request, ...dataProps } = handle.value.data
-
-      if (
-        isEqual(dataProps, {
-          providerID,
-          workspaceID,
-          collectionID,
-          requestID,
-        })
-      ) {
-        return true
-      }
-    })
-
-    if (!handleIsAlreadyIssued) {
-      this.issuedHandles.push(writableHandle)
-    }
-
     // TODO: Verify whether a request update action is reflected correctly in the handle being returned below
 
     const createdRequestHandle = await this.getRequestHandle(
@@ -1948,7 +1853,7 @@ export class PersonalWorkspaceProviderService
 
     platform.analytics?.logEvent({
       type: "HOPP_SAVE_REQUEST",
-      platform: "rest",
+      platform: "gql",
       createdNow: false,
       workspaceType: "personal",
     })
@@ -2287,7 +2192,7 @@ export class PersonalWorkspaceProviderService
     platform.analytics?.logEvent({
       type: "HOPP_EXPORT_COLLECTION",
       exporter: "json",
-      platform: "rest",
+      platform: "gql",
     })
 
     return Promise.resolve(E.right(undefined))

+ 1 - 1
packages/hoppscotch-common/src/services/tab/tab.ts

@@ -29,7 +29,7 @@ export abstract class TabService<Doc>
 {
   private workspaceService = this.bind(NewWorkspaceService)
 
-  protected tabMap = reactive(new Map<string, HoppTab<Doc>>())
+  protected tabMap: Map<string, HoppTab<Doc>> = reactive(new Map())
   protected tabOrdering = ref<string[]>(["test"])
 
   public currentTabID = refWithControl("test", {