refactor: use refAutoReset instead of settimeout (#2385)

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
Liyas Thomas
2022-06-01 16:54:37 +05:30
committed by GitHub
parent 39f72f8458
commit cf90d16f8a
18 changed files with 62 additions and 53 deletions

View File

@@ -22,7 +22,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "@nuxtjs/composition-api" import { refAutoReset } from "@vueuse/core"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import { import {
useI18n, useI18n,
@@ -45,7 +45,7 @@ const emit = defineEmits<{
(e: "hide-modal"): void (e: "hide-modal"): void
}>() }>()
const copyIcon = ref("copy") const copyIcon = refAutoReset<"copy" | "check">("copy", 1000)
// Copy user auth token to clipboard // Copy user auth token to clipboard
const copyUserAuthToken = () => { const copyUserAuthToken = () => {
@@ -53,7 +53,6 @@ const copyUserAuthToken = () => {
copyToClipboard(userAuthToken.value) copyToClipboard(userAuthToken.value)
copyIcon.value = "check" copyIcon.value = "check"
toast.success(`${t("state.copied_to_clipboard")}`) toast.success(`${t("state.copied_to_clipboard")}`)
setTimeout(() => (copyIcon.value = "copy"), 1000)
} else { } else {
toast.error(`${t("error.something_went_wrong")}`) toast.error(`${t("error.something_went_wrong")}`)
} }

View File

@@ -36,7 +36,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "@nuxtjs/composition-api" import { refAutoReset } from "@vueuse/core"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useI18n, useToast } from "~/helpers/utils/composables" import { useI18n, useToast } from "~/helpers/utils/composables"
@@ -60,7 +60,8 @@ const subject = "Checkout Hoppscotch - an open source API development ecosystem"
const summary = `Hi there!%0D%0A%0D%0AI thought you'll like this new platform that I joined called Hoppscotch - https://hoppscotch.io.%0D%0AIt is a simple and intuitive interface for creating and managing your APIs. You can build, test, document, and share your APIs.%0D%0A%0D%0AThe best part about Hoppscotch is that it is open source and free to get started.%0D%0A%0D%0A` const summary = `Hi there!%0D%0A%0D%0AI thought you'll like this new platform that I joined called Hoppscotch - https://hoppscotch.io.%0D%0AIt is a simple and intuitive interface for creating and managing your APIs. You can build, test, document, and share your APIs.%0D%0A%0D%0AThe best part about Hoppscotch is that it is open source and free to get started.%0D%0A%0D%0A`
const twitter = "hoppscotch_io" const twitter = "hoppscotch_io"
const copyIcon = ref("copy") const copyIcon = refAutoReset<"copy" | "check">("copy", 1000)
const platforms = [ const platforms = [
{ {
name: "Email", name: "Email",
@@ -93,7 +94,6 @@ const copyAppLink = () => {
copyToClipboard(url) copyToClipboard(url)
copyIcon.value = "check" copyIcon.value = "check"
toast.success(`${t("state.copied_to_clipboard")}`) toast.success(`${t("state.copied_to_clipboard")}`)
setTimeout(() => (copyIcon.value = "copy"), 1000)
} }
const hideModal = () => { const hideModal = () => {

View File

@@ -120,6 +120,7 @@ import clone from "lodash/clone"
import { computed, ref, watch } from "@nuxtjs/composition-api" import { computed, ref, watch } from "@nuxtjs/composition-api"
import * as E from "fp-ts/Either" import * as E from "fp-ts/Either"
import { Environment, parseTemplateStringE } from "@hoppscotch/data" import { Environment, parseTemplateStringE } from "@hoppscotch/data"
import { refAutoReset } from "@vueuse/core"
import { import {
createEnvironment, createEnvironment,
environments$, environments$,
@@ -160,7 +161,8 @@ const emit = defineEmits<{
const name = ref<string | null>(null) const name = ref<string | null>(null)
const vars = ref([{ key: "", value: "" }]) const vars = ref([{ key: "", value: "" }])
const clearIcon = ref("trash-2")
const clearIcon = refAutoReset<"trash-2" | "check">("trash-2", 1000)
const globalVars = useReadonlyStream(globalEnv$, []) const globalVars = useReadonlyStream(globalEnv$, [])
@@ -225,7 +227,6 @@ const clearContent = () => {
vars.value = [] vars.value = []
clearIcon.value = "check" clearIcon.value = "check"
toast.success(`${t("state.cleared")}`) toast.success(`${t("state.cleared")}`)
setTimeout(() => (clearIcon.value = "trash-2"), 1000)
} }
const addEnvironmentVariable = () => { const addEnvironmentVariable = () => {

View File

@@ -312,6 +312,7 @@ import {
import draggable from "vuedraggable" import draggable from "vuedraggable"
import isEqual from "lodash/isEqual" import isEqual from "lodash/isEqual"
import cloneDeep from "lodash/cloneDeep" import cloneDeep from "lodash/cloneDeep"
import { refAutoReset } from "@vueuse/core"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import { import {
useNuxt, useNuxt,
@@ -612,10 +613,13 @@ useCodemirror(queryEditor, gqlQueryString, {
environmentHighlights: false, environmentHighlights: false,
}) })
const copyQueryIcon = ref("copy") const copyQueryIcon = refAutoReset<"copy" | "check">("copy", 1000)
const copyVariablesIcon = ref("copy") const copyVariablesIcon = refAutoReset<"copy" | "check">("copy", 1000)
const prettifyQueryIcon = ref("wand") const prettifyQueryIcon = refAutoReset<"wand" | "check" | "info">("wand", 1000)
const prettifyVariablesIcon = ref("wand") const prettifyVariablesIcon = refAutoReset<"wand" | "check" | "info">(
"wand",
1000
)
const showSaveRequestModal = ref(false) const showSaveRequestModal = ref(false)
@@ -623,7 +627,6 @@ const copyQuery = () => {
copyToClipboard(gqlQueryString.value) copyToClipboard(gqlQueryString.value)
copyQueryIcon.value = "check" copyQueryIcon.value = "check"
toast.success(`${t("state.copied_to_clipboard")}`) toast.success(`${t("state.copied_to_clipboard")}`)
setTimeout(() => (copyQueryIcon.value = "copy"), 1000)
} }
const response = useStream(gqlResponse$, "", setGQLResponse) const response = useStream(gqlResponse$, "", setGQLResponse)
@@ -699,7 +702,6 @@ const prettifyQuery = () => {
toast.error(`${t("error.gql_prettify_invalid_query")}`) toast.error(`${t("error.gql_prettify_invalid_query")}`)
prettifyQueryIcon.value = "info" prettifyQueryIcon.value = "info"
} }
setTimeout(() => (prettifyQueryIcon.value = "wand"), 1000)
} }
const saveRequest = () => { const saveRequest = () => {
@@ -710,7 +712,6 @@ const copyVariables = () => {
copyToClipboard(variableString.value) copyToClipboard(variableString.value)
copyVariablesIcon.value = "check" copyVariablesIcon.value = "check"
toast.success(`${t("state.copied_to_clipboard")}`) toast.success(`${t("state.copied_to_clipboard")}`)
setTimeout(() => (copyVariablesIcon.value = "copy"), 1000)
} }
const prettifyVariableString = () => { const prettifyVariableString = () => {
@@ -723,7 +724,6 @@ const prettifyVariableString = () => {
prettifyVariablesIcon.value = "info" prettifyVariablesIcon.value = "info"
toast.error(`${t("error.json_prettify_invalid_body")}`) toast.error(`${t("error.json_prettify_invalid_body")}`)
} }
setTimeout(() => (prettifyVariablesIcon.value = "wand"), 1000)
} }
const clearGQLQuery = () => { const clearGQLQuery = () => {

View File

@@ -78,6 +78,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { reactive, ref } from "@nuxtjs/composition-api" import { reactive, ref } from "@nuxtjs/composition-api"
import { refAutoReset } from "@vueuse/core"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import { import {
@@ -111,14 +112,16 @@ useCodemirror(
}) })
) )
const downloadResponseIcon = ref("download") const downloadResponseIcon = refAutoReset<"download" | "check">(
const copyResponseIcon = ref("copy") "download",
1000
)
const copyResponseIcon = refAutoReset<"copy" | "check">("copy", 1000)
const copyResponse = () => { const copyResponse = () => {
copyToClipboard(responseString.value!) copyToClipboard(responseString.value!)
copyResponseIcon.value = "check" copyResponseIcon.value = "check"
toast.success(`${t("state.copied_to_clipboard")}`) toast.success(`${t("state.copied_to_clipboard")}`)
setTimeout(() => (copyResponseIcon.value = "copy"), 1000)
} }
const downloadResponse = () => { const downloadResponse = () => {
@@ -135,7 +138,6 @@ const downloadResponse = () => {
setTimeout(() => { setTimeout(() => {
document.body.removeChild(a) document.body.removeChild(a)
URL.revokeObjectURL(url) URL.revokeObjectURL(url)
downloadResponseIcon.value = "download"
}, 1000) }, 1000)
} }
</script> </script>

View File

@@ -193,6 +193,7 @@ import { computed, nextTick, reactive, ref } from "@nuxtjs/composition-api"
import { GraphQLField, GraphQLType } from "graphql" import { GraphQLField, GraphQLType } from "graphql"
import { map } from "rxjs/operators" import { map } from "rxjs/operators"
import { GQLHeader } from "@hoppscotch/data" import { GQLHeader } from "@hoppscotch/data"
import { refAutoReset } from "@vueuse/core"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import { GQLConnection } from "~/helpers/GQLConnection" import { GQLConnection } from "~/helpers/GQLConnection"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
@@ -306,8 +307,8 @@ const graphqlTypes = useReadonlyStream(
[] []
) )
const downloadSchemaIcon = ref("download") const downloadSchemaIcon = refAutoReset<"download" | "check">("download", 1000)
const copySchemaIcon = ref("copy") const copySchemaIcon = refAutoReset<"copy" | "check">("copy", 1000)
const graphqlFieldsFilterText = ref("") const graphqlFieldsFilterText = ref("")
@@ -423,7 +424,6 @@ const downloadSchema = () => {
setTimeout(() => { setTimeout(() => {
document.body.removeChild(a) document.body.removeChild(a)
URL.revokeObjectURL(url) URL.revokeObjectURL(url)
downloadSchemaIcon.value = "download"
}, 1000) }, 1000)
} }
@@ -432,7 +432,6 @@ const copySchema = () => {
copyToClipboard(schemaString.value) copyToClipboard(schemaString.value)
copySchemaIcon.value = "check" copySchemaIcon.value = "check"
setTimeout(() => (copySchemaIcon.value = "copy"), 1000)
} }
const handleUseHistory = (entry: GQLHistoryEntry) => { const handleUseHistory = (entry: GQLHistoryEntry) => {

View File

@@ -87,6 +87,7 @@
import { computed, ref, watch } from "@nuxtjs/composition-api" import { computed, ref, watch } from "@nuxtjs/composition-api"
import * as O from "fp-ts/Option" import * as O from "fp-ts/Option"
import { Environment, makeRESTRequest } from "@hoppscotch/data" import { Environment, makeRESTRequest } from "@hoppscotch/data"
import { refAutoReset } from "@vueuse/core"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import { import {
@@ -118,9 +119,10 @@ const options = ref<any | null>(null)
const request = ref(getRESTRequest()) const request = ref(getRESTRequest())
const codegenType = ref<CodegenName>("shell-curl") const codegenType = ref<CodegenName>("shell-curl")
const copyIcon = ref("copy")
const errorState = ref(false) const errorState = ref(false)
const copyIcon = refAutoReset<"copy" | "check">("copy", 1000)
const requestCode = computed(() => { const requestCode = computed(() => {
const aggregateEnvs = getAggregateEnvs() const aggregateEnvs = getAggregateEnvs()
const env: Environment = { const env: Environment = {
@@ -184,7 +186,6 @@ const copyRequestCode = () => {
copyToClipboard(requestCode.value) copyToClipboard(requestCode.value)
copyIcon.value = "check" copyIcon.value = "check"
toast.success(`${t("state.copied_to_clipboard")}`) toast.success(`${t("state.copied_to_clipboard")}`)
setTimeout(() => (copyIcon.value = "copy"), 1000)
} }
const searchQuery = ref("") const searchQuery = ref("")

View File

@@ -39,6 +39,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from "@nuxtjs/composition-api" import { ref, watch } from "@nuxtjs/composition-api"
import { refAutoReset } from "@vueuse/core"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import { setRESTRequest } from "~/newstore/RESTSession" import { setRESTRequest } from "~/newstore/RESTSession"
import { useI18n, useToast } from "~/helpers/utils/composables" import { useI18n, useToast } from "~/helpers/utils/composables"
@@ -95,7 +96,7 @@ const handleImport = () => {
hideModal() hideModal()
} }
const pasteIcon = ref("clipboard") const pasteIcon = refAutoReset<"clipboard" | "check">("clipboard", 1000)
const handlePaste = async () => { const handlePaste = async () => {
try { try {
@@ -103,7 +104,6 @@ const handlePaste = async () => {
if (text) { if (text) {
curl.value = text curl.value = text
pasteIcon.value = "check" pasteIcon.value = "check"
setTimeout(() => (pasteIcon.value = "clipboard"), 1000)
} }
} catch (e) { } catch (e) {
console.error("Failed to copy: ", e) console.error("Failed to copy: ", e)

View File

@@ -61,6 +61,7 @@ import { computed, reactive, Ref, ref } from "@nuxtjs/composition-api"
import * as TO from "fp-ts/TaskOption" import * as TO from "fp-ts/TaskOption"
import { pipe } from "fp-ts/function" import { pipe } from "fp-ts/function"
import { HoppRESTReqBody, ValidContentTypes } from "@hoppscotch/data" import { HoppRESTReqBody, ValidContentTypes } from "@hoppscotch/data"
import { refAutoReset } from "@vueuse/core"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import { getEditorLangForMimeType } from "~/helpers/editorutils" import { getEditorLangForMimeType } from "~/helpers/editorutils"
import { pluckRef, useI18n, useToast } from "~/helpers/utils/composables" import { pluckRef, useI18n, useToast } from "~/helpers/utils/composables"
@@ -91,7 +92,8 @@ const rawParamsBody = pluckRef(
>, >,
"body" "body"
) )
const prettifyIcon = ref("wand")
const prettifyIcon = refAutoReset<"wand" | "check" | "info">("wand", 1000)
const rawInputEditorLang = computed(() => const rawInputEditorLang = computed(() =>
getEditorLangForMimeType(props.contentType) getEditorLangForMimeType(props.contentType)
@@ -148,6 +150,5 @@ const prettifyRequestBody = () => {
prettifyIcon.value = "info" prettifyIcon.value = "info"
toast.error(`${t("error.json_prettify_invalid_body")}`) toast.error(`${t("error.json_prettify_invalid_body")}`)
} }
setTimeout(() => (prettifyIcon.value = "wand"), 1000)
} }
</script> </script>

View File

@@ -215,6 +215,7 @@ import { computed, ref, watch } from "@nuxtjs/composition-api"
import { isLeft, isRight } from "fp-ts/lib/Either" import { isLeft, isRight } from "fp-ts/lib/Either"
import * as E from "fp-ts/Either" import * as E from "fp-ts/Either"
import cloneDeep from "lodash/cloneDeep" import cloneDeep from "lodash/cloneDeep"
import { refAutoReset } from "@vueuse/core"
import { import {
updateRESTResponse, updateRESTResponse,
restEndpoint$, restEndpoint$,
@@ -393,7 +394,11 @@ const clearContent = () => {
resetRESTRequest() resetRESTRequest()
} }
const copyLinkIcon = hasNavigatorShare ? ref("share-2") : ref("copy") const copyLinkIcon = refAutoReset<"share-2" | "copy" | "check">(
hasNavigatorShare ? "share-2" : "copy",
1000
)
const shareLink = ref<string | null>("") const shareLink = ref<string | null>("")
const fetchingShareLink = ref(false) const fetchingShareLink = ref(false)
@@ -448,7 +453,6 @@ const copyShareLink = (shareLink: string) => {
copyLinkIcon.value = "check" copyLinkIcon.value = "check"
copyToClipboard(`https://hopp.sh/r${shareLink}`) copyToClipboard(`https://hopp.sh/r${shareLink}`)
toast.success(`${t("state.copied_to_clipboard")}`) toast.success(`${t("state.copied_to_clipboard")}`)
setTimeout(() => (copyLinkIcon.value = "copy"), 2000)
} }
} }

View File

@@ -26,8 +26,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "@nuxtjs/composition-api"
import { HoppRESTHeader } from "@hoppscotch/data" import { HoppRESTHeader } from "@hoppscotch/data"
import { refAutoReset } from "@vueuse/core"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useI18n, useToast } from "~/helpers/utils/composables" import { useI18n, useToast } from "~/helpers/utils/composables"
@@ -39,12 +39,11 @@ const props = defineProps<{
headers: Array<HoppRESTHeader> headers: Array<HoppRESTHeader>
}>() }>()
const copyIcon = ref("copy") const copyIcon = refAutoReset<"copy" | "check">("copy", 1000)
const copyHeaders = () => { const copyHeaders = () => {
copyToClipboard(JSON.stringify(props.headers)) copyToClipboard(JSON.stringify(props.headers))
copyIcon.value = "check" copyIcon.value = "check"
toast.success(`${t("state.copied_to_clipboard")}`) toast.success(`${t("state.copied_to_clipboard")}`)
setTimeout(() => (copyIcon.value = "copy"), 1000)
} }
</script> </script>

View File

@@ -28,7 +28,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "@nuxtjs/composition-api" import { refAutoReset } from "@vueuse/core"
import { HoppRESTHeader } from "~/../hoppscotch-data/dist" import { HoppRESTHeader } from "~/../hoppscotch-data/dist"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useI18n, useToast } from "~/helpers/utils/composables" import { useI18n, useToast } from "~/helpers/utils/composables"
@@ -41,12 +41,11 @@ defineProps<{
header: HoppRESTHeader header: HoppRESTHeader
}>() }>()
const copyIcon = ref("copy") const copyIcon = refAutoReset<"copy" | "check">("copy", 1000)
const copyHeader = (headerValue: string) => { const copyHeader = (headerValue: string) => {
copyToClipboard(headerValue) copyToClipboard(headerValue)
copyIcon.value = "check" copyIcon.value = "check"
toast.success(`${t("state.copied_to_clipboard")}`) toast.success(`${t("state.copied_to_clipboard")}`)
setTimeout(() => (copyIcon.value = "copy"), 1000)
} }
</script> </script>

View File

@@ -65,6 +65,7 @@ import { pipe } from "fp-ts/function"
import * as RR from "fp-ts/ReadonlyRecord" import * as RR from "fp-ts/ReadonlyRecord"
import * as O from "fp-ts/Option" import * as O from "fp-ts/Option"
import { translateToNewRequest } from "@hoppscotch/data" import { translateToNewRequest } from "@hoppscotch/data"
import { refAutoReset } from "@vueuse/core"
import { useI18n, useToast } from "~/helpers/utils/composables" import { useI18n, useToast } from "~/helpers/utils/composables"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import { Shortcode } from "~/helpers/shortcodes/Shortcode" import { Shortcode } from "~/helpers/shortcodes/Shortcode"
@@ -93,7 +94,8 @@ const requestMethodLabels = {
} as const } as const
const timeStampRef = ref() const timeStampRef = ref()
const copyIconRefs = ref<"copy" | "check">("copy")
const copyIconRefs = refAutoReset<"copy" | "check">("copy", 1000)
const parseShortcodeRequest = computed(() => const parseShortcodeRequest = computed(() =>
pipe(props.shortcode.request, JSON.parse, translateToNewRequest) pipe(props.shortcode.request, JSON.parse, translateToNewRequest)
@@ -118,7 +120,6 @@ const copyShortcode = (codeID: string) => {
copyToClipboard(`https://hopp.sh/r/${codeID}`) copyToClipboard(`https://hopp.sh/r/${codeID}`)
toast.success(`${t("state.copied_to_clipboard")}`) toast.success(`${t("state.copied_to_clipboard")}`)
copyIconRefs.value = "check" copyIconRefs.value = "check"
setTimeout(() => (copyIconRefs.value = "copy"), 1000)
} }
</script> </script>

View File

@@ -113,6 +113,7 @@ import { computed, reactive, ref } from "@nuxtjs/composition-api"
import { pipe } from "fp-ts/function" import { pipe } from "fp-ts/function"
import * as TO from "fp-ts/TaskOption" import * as TO from "fp-ts/TaskOption"
import * as O from "fp-ts/Option" import * as O from "fp-ts/Option"
import { refAutoReset } from "@vueuse/core"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import jsonLinter from "~/helpers/editor/linting/json" import jsonLinter from "~/helpers/editor/linting/json"
import { readFileAsText } from "~/helpers/functional/files" import { readFileAsText } from "~/helpers/functional/files"
@@ -145,7 +146,8 @@ const toast = useToast()
const linewrapEnabled = ref(true) const linewrapEnabled = ref(true)
const wsCommunicationBody = ref<HTMLElement>() const wsCommunicationBody = ref<HTMLElement>()
const prettifyIcon = ref<"wand" | "check" | "info">("wand")
const prettifyIcon = refAutoReset<"wand" | "check" | "info">("wand", 1000)
const knownContentTypes = { const knownContentTypes = {
JSON: "application/ld+json", JSON: "application/ld+json",
@@ -216,6 +218,5 @@ const prettifyRequestBody = () => {
prettifyIcon.value = "info" prettifyIcon.value = "info"
toast.error(`${t("error.json_prettify_invalid_body")}`) toast.error(`${t("error.json_prettify_invalid_body")}`)
} }
setTimeout(() => (prettifyIcon.value = "wand"), 1000)
} }
</script> </script>

View File

@@ -203,7 +203,7 @@ import * as LJSON from "lossless-json"
import * as O from "fp-ts/Option" import * as O from "fp-ts/Option"
import { pipe } from "fp-ts/function" import { pipe } from "fp-ts/function"
import { ref, computed, reactive, watch } from "@nuxtjs/composition-api" import { ref, computed, reactive, watch } from "@nuxtjs/composition-api"
import { useTimeAgo } from "@vueuse/core" import { refAutoReset, useTimeAgo } from "@vueuse/core"
import { LogEntryData } from "./Log.vue" import { LogEntryData } from "./Log.vue"
import { useI18n } from "~/helpers/utils/composables" import { useI18n } from "~/helpers/utils/composables"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
@@ -310,11 +310,11 @@ const { downloadIcon, downloadResponse } = useDownloadResponse(
logPayload logPayload
) )
const copyQueryIcon = ref("copy") const copyQueryIcon = refAutoReset<"copy" | "check">("copy", 1000)
const copyQuery = (entry: string) => { const copyQuery = (entry: string) => {
copyToClipboard(entry) copyToClipboard(entry)
copyQueryIcon.value = "check" copyQueryIcon.value = "check"
setTimeout(() => (copyQueryIcon.value = "copy"), 1000)
} }
// Relative Time // Relative Time

View File

@@ -1,4 +1,5 @@
import { Ref, ref } from "@nuxtjs/composition-api" import { Ref } from "@nuxtjs/composition-api"
import { refAutoReset } from "@vueuse/core"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useI18n, useToast } from "~/helpers/utils/composables" import { useI18n, useToast } from "~/helpers/utils/composables"
@@ -8,13 +9,13 @@ export default function useCopyResponse(responseBodyText: Ref<any>): {
} { } {
const toast = useToast() const toast = useToast()
const t = useI18n() const t = useI18n()
const copyIcon = ref("copy")
const copyIcon = refAutoReset<"copy" | "check">("copy", 1000)
const copyResponse = () => { const copyResponse = () => {
copyToClipboard(responseBodyText.value) copyToClipboard(responseBodyText.value)
copyIcon.value = "check" copyIcon.value = "check"
toast.success(`${t("state.copied_to_clipboard")}`) toast.success(`${t("state.copied_to_clipboard")}`)
setTimeout(() => (copyIcon.value = "copy"), 1000)
} }
return { return {

View File

@@ -1,7 +1,8 @@
import * as S from "fp-ts/string" import * as S from "fp-ts/string"
import * as RNEA from "fp-ts/ReadonlyNonEmptyArray" import * as RNEA from "fp-ts/ReadonlyNonEmptyArray"
import { pipe } from "fp-ts/function" import { pipe } from "fp-ts/function"
import { Ref, ref } from "@nuxtjs/composition-api" import { Ref } from "@nuxtjs/composition-api"
import { refAutoReset } from "@vueuse/core"
import { useI18n, useToast } from "~/helpers/utils/composables" import { useI18n, useToast } from "~/helpers/utils/composables"
export type downloadResponseReturnType = (() => void) | Ref<any> export type downloadResponseReturnType = (() => void) | Ref<any>
@@ -13,7 +14,8 @@ export default function useDownloadResponse(
downloadIcon: Ref<string> downloadIcon: Ref<string>
downloadResponse: () => void downloadResponse: () => void
} { } {
const downloadIcon = ref("download") const downloadIcon = refAutoReset<"download" | "check">("download", 1000)
const toast = useToast() const toast = useToast()
const t = useI18n() const t = useI18n()
@@ -42,7 +44,6 @@ export default function useDownloadResponse(
setTimeout(() => { setTimeout(() => {
document.body.removeChild(a) document.body.removeChild(a)
URL.revokeObjectURL(url) URL.revokeObjectURL(url)
downloadIcon.value = "download"
}, 1000) }, 1000)
} }
return { return {

View File

@@ -236,6 +236,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, watch, defineComponent } from "@nuxtjs/composition-api" import { ref, computed, watch, defineComponent } from "@nuxtjs/composition-api"
import { refAutoReset } from "@vueuse/core"
import { applySetting, toggleSetting, useSetting } from "~/newstore/settings" import { applySetting, toggleSetting, useSetting } from "~/newstore/settings"
import { import {
useToast, useToast,
@@ -276,7 +277,7 @@ const hasFirefoxExtInstalled = computed(
() => browserIsFirefox() && currentExtensionStatus.value === "available" () => browserIsFirefox() && currentExtensionStatus.value === "available"
) )
const clearIcon = ref("rotate-ccw") const clearIcon = refAutoReset<"rotate-ccw" | "check">("rotate-ccw", 1000)
const confirmRemove = ref(false) const confirmRemove = ref(false)
@@ -322,7 +323,6 @@ const resetProxy = () => {
applySetting("PROXY_URL", `https://proxy.hoppscotch.io/`) applySetting("PROXY_URL", `https://proxy.hoppscotch.io/`)
clearIcon.value = "check" clearIcon.value = "check"
toast.success(`${t("state.cleared")}`) toast.success(`${t("state.cleared")}`)
setTimeout(() => (clearIcon.value = "rotate-ccw"), 1000)
} }
const getColorModeName = (colorMode: string) => { const getColorModeName = (colorMode: string) => {