feat: fetch, display and copy short code
This commit is contained in:
@@ -210,6 +210,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, useContext, watch } from "@nuxtjs/composition-api"
|
import { computed, ref, useContext, watch } from "@nuxtjs/composition-api"
|
||||||
import { isRight } from "fp-ts/lib/Either"
|
import { isRight } from "fp-ts/lib/Either"
|
||||||
|
import * as E from "fp-ts/Either"
|
||||||
import {
|
import {
|
||||||
updateRESTResponse,
|
updateRESTResponse,
|
||||||
restEndpoint$,
|
restEndpoint$,
|
||||||
@@ -234,6 +235,7 @@ import { useSetting } from "~/newstore/settings"
|
|||||||
import { overwriteRequestTeams } from "~/helpers/teams/utils"
|
import { overwriteRequestTeams } from "~/helpers/teams/utils"
|
||||||
import { apolloClient } from "~/helpers/apollo"
|
import { apolloClient } from "~/helpers/apollo"
|
||||||
import useWindowSize from "~/helpers/utils/useWindowSize"
|
import useWindowSize from "~/helpers/utils/useWindowSize"
|
||||||
|
import { createShortcode } from "~/helpers/backend/mutations/Shortcode"
|
||||||
|
|
||||||
const methods = [
|
const methods = [
|
||||||
"GET",
|
"GET",
|
||||||
@@ -332,36 +334,39 @@ const shareLink = ref("")
|
|||||||
const shareLinkStatus = ref(t("request.copy_link"))
|
const shareLinkStatus = ref(t("request.copy_link"))
|
||||||
const fetchingShareLink = ref(false)
|
const fetchingShareLink = ref(false)
|
||||||
|
|
||||||
const copyRequest = () => {
|
const copyRequest = async () => {
|
||||||
shareLink.value = ""
|
shareLink.value = ""
|
||||||
fetchingShareLink.value = true
|
fetchingShareLink.value = true
|
||||||
// 1. init loading
|
|
||||||
shareLinkStatus.value = t("state.loading")
|
shareLinkStatus.value = t("state.loading")
|
||||||
// 2. TODO: fetch short code
|
const request = getRESTRequest()
|
||||||
shareLink.value = "/abcdefghij"
|
const shortcodeResult = await createShortcode(request)()
|
||||||
// 3. share / copy link to clipboard
|
if (E.isLeft(shortcodeResult)) {
|
||||||
if (navigator.share) {
|
$toast.error(`${shortcodeResult.left.error}`)
|
||||||
const time = new Date().toLocaleTimeString()
|
shareLink.value = `${t("error.something_went_wrong")}`
|
||||||
const date = new Date().toLocaleDateString()
|
} else if (E.isRight(shortcodeResult)) {
|
||||||
navigator
|
shareLink.value = shortcodeResult.right.createShortcode.id
|
||||||
.share({
|
if (navigator.share) {
|
||||||
title: "Hoppscotch",
|
const time = new Date().toLocaleTimeString()
|
||||||
text: `Hoppscotch • Open source API development ecosystem at ${time} on ${date}`,
|
const date = new Date().toLocaleDateString()
|
||||||
url: shareLink.value,
|
navigator
|
||||||
|
.share({
|
||||||
|
title: "Hoppscotch",
|
||||||
|
text: `Hoppscotch • Open source API development ecosystem at ${time} on ${date}`,
|
||||||
|
url: `https://hopp.sh/r/${shareLink.value}`,
|
||||||
|
})
|
||||||
|
.then(() => {})
|
||||||
|
.catch(() => {})
|
||||||
|
} else {
|
||||||
|
copyLinkIcon.value = "check"
|
||||||
|
copyToClipboard(`https://hopp.sh/r/${shareLink.value}`)
|
||||||
|
$toast.success(`${t("state.copied_to_clipboard")}`, {
|
||||||
|
icon: "content_paste",
|
||||||
})
|
})
|
||||||
.then(() => {})
|
setTimeout(() => (copyLinkIcon.value = "copy"), 2000)
|
||||||
.catch(() => {})
|
}
|
||||||
} else {
|
|
||||||
copyLinkIcon.value = "check"
|
|
||||||
copyToClipboard(shareLink.value)
|
|
||||||
$toast.success(`${t("state.copied_to_clipboard")}`, {
|
|
||||||
icon: "content_paste",
|
|
||||||
})
|
|
||||||
setTimeout(() => (copyLinkIcon.value = "copy"), 2000)
|
|
||||||
}
|
}
|
||||||
// 4. hide loading
|
|
||||||
fetchingShareLink.value = false
|
fetchingShareLink.value = false
|
||||||
shareLinkStatus.value = shareLink.value
|
shareLinkStatus.value = `/${shareLink.value}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const cycleUpMethod = () => {
|
const cycleUpMethod = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user