useCopyResponse.ts 669 B

12345678910111213141516171819202122232425
  1. import { Ref } from "@nuxtjs/composition-api"
  2. import { refAutoReset } from "@vueuse/core"
  3. import { copyToClipboard } from "~/helpers/utils/clipboard"
  4. import { useI18n, useToast } from "~/helpers/utils/composables"
  5. export default function useCopyResponse(responseBodyText: Ref<any>): {
  6. copyIcon: Ref<string>
  7. copyResponse: () => void
  8. } {
  9. const toast = useToast()
  10. const t = useI18n()
  11. const copyIcon = refAutoReset<"copy" | "check">("copy", 1000)
  12. const copyResponse = () => {
  13. copyToClipboard(responseBodyText.value)
  14. copyIcon.value = "check"
  15. toast.success(`${t("state.copied_to_clipboard")}`)
  16. }
  17. return {
  18. copyIcon,
  19. copyResponse,
  20. }
  21. }