Share.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <SmartModal
  3. v-if="show"
  4. :title="$t('app.invite_your_friends')"
  5. @close="hideModal"
  6. >
  7. <template #body>
  8. <p class="text-secondaryLight mb-8 px-2">
  9. {{ $t("app.invite_description") }}
  10. </p>
  11. <div class="flex flex-col space-y-2 px-2">
  12. <div class="grid gap-4 grid-cols-3">
  13. <a
  14. v-for="(platform, index) in platforms"
  15. :key="`platform-${index}`"
  16. :href="platform.link"
  17. target="_blank"
  18. class="share-link"
  19. >
  20. <SmartIcon :name="platform.icon" class="h-6 w-6" />
  21. <span class="mt-3">
  22. {{ platform.name }}
  23. </span>
  24. </a>
  25. <button class="share-link" @click="copyAppLink">
  26. <SmartIcon class="h-6 text-xl w-6" :name="copyIcon" />
  27. <span class="mt-3">
  28. {{ $t("app.copy") }}
  29. </span>
  30. </button>
  31. </div>
  32. </div>
  33. </template>
  34. </SmartModal>
  35. </template>
  36. <script setup lang="ts">
  37. import { ref, useContext } from "@nuxtjs/composition-api"
  38. import { copyToClipboard } from "~/helpers/utils/clipboard"
  39. const {
  40. $toast,
  41. app: { i18n },
  42. } = useContext()
  43. const t = i18n.t.bind(i18n)
  44. defineProps<{
  45. show: Boolean
  46. }>()
  47. const emit = defineEmits<{
  48. (e: "hide-modal"): void
  49. }>()
  50. const url = "https://hoppscotch.io"
  51. const text = "Hoppscotch - Open source API development ecosystem."
  52. const description =
  53. "Helps you create requests faster, saving precious time on development."
  54. const subject = "Checkout Hoppscotch - an open source API development ecosystem"
  55. 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`
  56. const twitter = "hoppscotch_io"
  57. const copyIcon = ref("copy")
  58. const platforms = [
  59. {
  60. name: "Email",
  61. icon: "mail",
  62. link: `mailto:?subject=${subject}&body=${summary}`,
  63. },
  64. {
  65. name: "Twitter",
  66. icon: "brands/twitter",
  67. link: `https://twitter.com/intent/tweet?text=${text} ${description}&url=${url}&via=${twitter}`,
  68. },
  69. {
  70. name: "Facebook",
  71. icon: "brands/facebook",
  72. link: `https://www.facebook.com/sharer/sharer.php?u=${url}`,
  73. },
  74. {
  75. name: "Reddit",
  76. icon: "brands/reddit",
  77. link: `https://www.reddit.com/submit?url=${url}&title=${text}`,
  78. },
  79. {
  80. name: "LinkedIn",
  81. icon: "brands/linkedin",
  82. link: `https://www.linkedin.com/sharing/share-offsite/?url=${url}`,
  83. },
  84. ]
  85. const copyAppLink = () => {
  86. copyToClipboard(url)
  87. copyIcon.value = "check"
  88. $toast.success(t("state.copied_to_clipboard").toString(), {
  89. icon: "content_paste",
  90. })
  91. setTimeout(() => (copyIcon.value = "copy"), 1000)
  92. }
  93. const hideModal = () => {
  94. emit("hide-modal")
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .share-link {
  99. @apply border border-dividerLight;
  100. @apply rounded;
  101. @apply flex-col flex;
  102. @apply p-4;
  103. @apply items-center;
  104. @apply justify-center;
  105. @apply font-semibold;
  106. @apply hover:(bg-primaryLight text-secondaryDark);
  107. @apply focus:outline-none;
  108. @apply focus-visible:border-divider;
  109. svg {
  110. @apply opacity-80;
  111. }
  112. &:hover {
  113. svg {
  114. @apply opacity-100;
  115. }
  116. }
  117. }
  118. </style>