Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

chore: cleanup

liyasthomasd0386ef86f16
diff --git a/packages/hoppscotch-app/components/http/Request.vue b/packages/hoppscotch-app/components/http/Request.vue
index b692a8e00..20f8a29b4 100644
--- a/packages/hoppscotch-app/components/http/Request.vue
+++ b/packages/hoppscotch-app/components/http/Request.vue
@@ -168,7 +168,7 @@
/>
<SmartItem
ref="copyRequest"
- :label="shareLinkStatus"
+ :label="shareButtonText"
:svg="copyLinkIcon"
:loading="fetchingShareLink"
@click.native="
@@ -221,6 +221,7 @@ import {
useRESTRequestName,
getRESTSaveContext,
getRESTRequest,
+ restRequest$,
} from "~/newstore/RESTSession"
import { editRESTRequest } from "~/newstore/collections"
import { runRESTRequest$ } from "~/helpers/RequestRunner"
@@ -230,6 +231,7 @@ import {
useNuxt,
useI18n,
useToast,
+ useReadonlyStream,
} from "~/helpers/utils/composables"
import { defineActionHandler } from "~/helpers/actions"
import { copyToClipboard } from "~/helpers/utils/clipboard"
@@ -331,31 +333,41 @@ const clearContent = () => {
}
const copyLinkIcon = hasNavigatorShare ? ref("share-2") : ref("copy")
-const shareLink = ref("")
-const shareLinkStatus = ref(t("request.copy_link"))
+const shareLink = ref<string | null>("")
const fetchingShareLink = ref(false)
-const shareLinkAvailable = ref(false)
+
+const shareButtonText = computed(() => {
+ if (shareLink.value) {
+ return shareLink.value
+ } else if (fetchingShareLink.value) {
+ return t("state.loading")
+ } else {
+ return t("request.copy_link")
+ }
+})
+
+const request = useReadonlyStream(restRequest$, getRESTRequest())
+
+watch(request, () => {
+ shareLink.value = null
+})
const copyRequest = async () => {
- if (shareLinkAvailable.value) {
+ if (shareLink.value) {
copyShareLink(shareLink.value)
} else {
shareLink.value = ""
fetchingShareLink.value = true
- shareLinkStatus.value = t("state.loading")
const request = getRESTRequest()
const shortcodeResult = await createShortcode(request)()
if (E.isLeft(shortcodeResult)) {
- $toast.error(`${shortcodeResult.left.error}`)
+ toast.error(`${shortcodeResult.left.error}`)
shareLink.value = `${t("error.something_went_wrong")}`
- shareLinkAvailable.value = false
} else if (E.isRight(shortcodeResult)) {
shareLink.value = `/${shortcodeResult.right.createShortcode.id}`
- shareLinkAvailable.value = true
copyShareLink(shareLink.value)
}
fetchingShareLink.value = false
- shareLinkStatus.value = shareLink.value
}
}
diff --git a/packages/hoppscotch-app/helpers/backend/gql/queries/GetRequestFromShortcode.graphql b/packages/hoppscotch-app/helpers/backend/gql/queries/GetRequestFromShortcode.graphql
deleted file mode 100644
index da9c61811..000000000
--- a/packages/hoppscotch-app/helpers/backend/gql/queries/GetRequestFromShortcode.graphql
+++ /dev/null
@@ -1,6 +0,0 @@
-query GetRequestFromShortcode($shortcode: ID!) {
- shortcode(code: $shortcode) {
- request
- id
- }
-}
diff --git a/packages/hoppscotch-app/pages/r/_id.vue b/packages/hoppscotch-app/pages/r/_id.vue
index 7663f3e2d..62bf59181 100644
--- a/packages/hoppscotch-app/pages/r/_id.vue
+++ b/packages/hoppscotch-app/pages/r/_id.vue
@@ -62,11 +62,11 @@ import {
import * as E from "fp-ts/Either"
import { useGQLQuery } from "~/helpers/backend/GQLClient"
import {
- GetRequestFromShortcodeDocument,
- GetRequestFromShortcodeQuery,
- GetRequestFromShortcodeQueryVariables,
+ ResolveShortcodeDocument,
+ ResolveShortcodeQuery,
+ ResolveShortcodeQueryVariables,
} from "~/helpers/backend/graphql"
-import { HoppRESTRequest } from "~/helpers/types/HoppRESTRequest"
+import { makeRESTRequest } from "~/helpers/types/HoppRESTRequest"
import { setRESTRequest } from "~/newstore/RESTSession"
export default defineComponent({
@@ -76,13 +76,13 @@ export default defineComponent({
const { localePath } = useContext() as any
const shortcodeDetails = useGQLQuery<
- GetRequestFromShortcodeQuery,
- GetRequestFromShortcodeQueryVariables,
+ ResolveShortcodeQuery,
+ ResolveShortcodeQueryVariables,
""
>({
- query: GetRequestFromShortcodeDocument,
+ query: ResolveShortcodeDocument,
variables: {
- shortcode: route.value.params.id as string,
+ code: route.value.params.id as string,
},
})
@@ -96,7 +96,7 @@ export default defineComponent({
if (E.isRight(data)) {
const request = JSON.parse(data.right.shortcode?.request as string)
- setRESTRequest(request as unknown as HoppRESTRequest)
+ setRESTRequest(makeRESTRequest(request))
router.push({ path: localePath("/") })
}
}