Files
hoppscotch/packages/hoppscotch-app/helpers/lenses/composables/useCopyResponse.ts
2022-01-17 21:00:48 +05:30

25 lines
650 B
TypeScript

import { Ref, ref } from "@nuxtjs/composition-api"
import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useI18n, useToast } from "~/helpers/utils/composables"
export default function useCopyResponse(responseBodyText: Ref<any>): {
copyIcon: Ref<string>
copyResponse: () => void
} {
const toast = useToast()
const t = useI18n()
const copyIcon = ref("copy")
const copyResponse = () => {
copyToClipboard(responseBodyText.value)
copyIcon.value = "check"
toast.success(`${t("state.copied_to_clipboard")}`)
setTimeout(() => (copyIcon.value = "copy"), 1000)
}
return {
copyIcon,
copyResponse,
}
}