chore: cleanup

This commit is contained in:
liyasthomas
2021-11-22 14:52:14 +05:30
parent 56cdb79773
commit d0386ef86f
3 changed files with 31 additions and 25 deletions

View File

@@ -168,7 +168,7 @@
/> />
<SmartItem <SmartItem
ref="copyRequest" ref="copyRequest"
:label="shareLinkStatus" :label="shareButtonText"
:svg="copyLinkIcon" :svg="copyLinkIcon"
:loading="fetchingShareLink" :loading="fetchingShareLink"
@click.native=" @click.native="
@@ -221,6 +221,7 @@ import {
useRESTRequestName, useRESTRequestName,
getRESTSaveContext, getRESTSaveContext,
getRESTRequest, getRESTRequest,
restRequest$,
} from "~/newstore/RESTSession" } from "~/newstore/RESTSession"
import { editRESTRequest } from "~/newstore/collections" import { editRESTRequest } from "~/newstore/collections"
import { runRESTRequest$ } from "~/helpers/RequestRunner" import { runRESTRequest$ } from "~/helpers/RequestRunner"
@@ -230,6 +231,7 @@ import {
useNuxt, useNuxt,
useI18n, useI18n,
useToast, useToast,
useReadonlyStream,
} from "~/helpers/utils/composables" } from "~/helpers/utils/composables"
import { defineActionHandler } from "~/helpers/actions" import { defineActionHandler } from "~/helpers/actions"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
@@ -331,31 +333,41 @@ const clearContent = () => {
} }
const copyLinkIcon = hasNavigatorShare ? ref("share-2") : ref("copy") const copyLinkIcon = hasNavigatorShare ? ref("share-2") : ref("copy")
const shareLink = ref("") const shareLink = ref<string | null>("")
const shareLinkStatus = ref(t("request.copy_link"))
const fetchingShareLink = ref(false) 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 () => { const copyRequest = async () => {
if (shareLinkAvailable.value) { if (shareLink.value) {
copyShareLink(shareLink.value) copyShareLink(shareLink.value)
} else { } else {
shareLink.value = "" shareLink.value = ""
fetchingShareLink.value = true fetchingShareLink.value = true
shareLinkStatus.value = t("state.loading")
const request = getRESTRequest() const request = getRESTRequest()
const shortcodeResult = await createShortcode(request)() const shortcodeResult = await createShortcode(request)()
if (E.isLeft(shortcodeResult)) { if (E.isLeft(shortcodeResult)) {
$toast.error(`${shortcodeResult.left.error}`) toast.error(`${shortcodeResult.left.error}`)
shareLink.value = `${t("error.something_went_wrong")}` shareLink.value = `${t("error.something_went_wrong")}`
shareLinkAvailable.value = false
} else if (E.isRight(shortcodeResult)) { } else if (E.isRight(shortcodeResult)) {
shareLink.value = `/${shortcodeResult.right.createShortcode.id}` shareLink.value = `/${shortcodeResult.right.createShortcode.id}`
shareLinkAvailable.value = true
copyShareLink(shareLink.value) copyShareLink(shareLink.value)
} }
fetchingShareLink.value = false fetchingShareLink.value = false
shareLinkStatus.value = shareLink.value
} }
} }

View File

@@ -1,6 +0,0 @@
query GetRequestFromShortcode($shortcode: ID!) {
shortcode(code: $shortcode) {
request
id
}
}

View File

@@ -62,11 +62,11 @@ import {
import * as E from "fp-ts/Either" import * as E from "fp-ts/Either"
import { useGQLQuery } from "~/helpers/backend/GQLClient" import { useGQLQuery } from "~/helpers/backend/GQLClient"
import { import {
GetRequestFromShortcodeDocument, ResolveShortcodeDocument,
GetRequestFromShortcodeQuery, ResolveShortcodeQuery,
GetRequestFromShortcodeQueryVariables, ResolveShortcodeQueryVariables,
} from "~/helpers/backend/graphql" } from "~/helpers/backend/graphql"
import { HoppRESTRequest } from "~/helpers/types/HoppRESTRequest" import { makeRESTRequest } from "~/helpers/types/HoppRESTRequest"
import { setRESTRequest } from "~/newstore/RESTSession" import { setRESTRequest } from "~/newstore/RESTSession"
export default defineComponent({ export default defineComponent({
@@ -76,13 +76,13 @@ export default defineComponent({
const { localePath } = useContext() as any const { localePath } = useContext() as any
const shortcodeDetails = useGQLQuery< const shortcodeDetails = useGQLQuery<
GetRequestFromShortcodeQuery, ResolveShortcodeQuery,
GetRequestFromShortcodeQueryVariables, ResolveShortcodeQueryVariables,
"" ""
>({ >({
query: GetRequestFromShortcodeDocument, query: ResolveShortcodeDocument,
variables: { 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)) { if (E.isRight(data)) {
const request = JSON.parse(data.right.shortcode?.request as string) const request = JSON.parse(data.right.shortcode?.request as string)
setRESTRequest(request as unknown as HoppRESTRequest) setRESTRequest(makeRESTRequest(request))
router.push({ path: localePath("/") }) router.push({ path: localePath("/") })
} }
} }