Header.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <header class="header">
  3. <div class="row-wrapper">
  4. <span class="slide-in">
  5. <nuxt-link :to="localePath('index')">
  6. <h1 class="heading logo">Hoppscotch</h1>
  7. </nuxt-link>
  8. <iframe
  9. src="https://ghbtns.com/github-btn.html?user=hoppscotch&repo=hoppscotch&type=star&count=true"
  10. frameborder="0"
  11. scrolling="0"
  12. width="150"
  13. height="20"
  14. title="GitHub"
  15. class="ml-8 hide-on-small-screen"
  16. loading="lazy"
  17. ></iframe>
  18. </span>
  19. <span>
  20. <a
  21. href="https://appwrite.io/?utm_source=hoppscotch&utm_medium=banner&utm_campaign=hello"
  22. target="_blank"
  23. rel="noopener"
  24. class="
  25. items-center
  26. px-4
  27. py-2
  28. mx-4
  29. font-mono
  30. text-sm
  31. rounded-md
  32. bg-primaryDark
  33. hide-on-small-screen
  34. "
  35. >
  36. Appwrite - Open-Source Backend as a Service
  37. <img
  38. class="w-8 ml-2"
  39. src="~assets/images/appwrite-icon.svg"
  40. alt="Appwrite"
  41. />
  42. </a>
  43. <button
  44. id="installPWA"
  45. v-tooltip="$t('install_pwa')"
  46. class="icon button"
  47. @click.prevent="showInstallPrompt()"
  48. >
  49. <i class="material-icons">offline_bolt</i>
  50. </button>
  51. <a
  52. href="https://github.com/hoppscotch/hoppscotch"
  53. target="_blank"
  54. aria-label="GitHub"
  55. rel="noopener"
  56. >
  57. <button v-tooltip="'GitHub'" class="icon button" aria-label="GitHub">
  58. <svg
  59. xmlns="http://www.w3.org/2000/svg"
  60. width="24"
  61. height="24"
  62. class="material-icons"
  63. >
  64. <path
  65. d="M12 0C5.374 0 0 5.373 0 12c0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23A11.509 11.509 0 0112 5.803c1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576C20.566 21.797 24 17.3 24 12c0-6.627-5.373-12-12-12z"
  66. />
  67. </svg>
  68. </button>
  69. </a>
  70. <v-popover v-if="currentUser === null">
  71. <button v-tooltip="$t('login_with')" class="icon button">
  72. <i class="material-icons">login</i>
  73. </button>
  74. <template #popover>
  75. <FirebaseLogin @show-email="showEmail = true" />
  76. </template>
  77. </v-popover>
  78. <v-popover v-else>
  79. <button
  80. v-tooltip="
  81. (currentUser.displayName ||
  82. '<label><i>Name not found</i></label>') +
  83. '<br>' +
  84. (currentUser.email || '<label><i>Email not found</i></label>')
  85. "
  86. class="icon button"
  87. aria-label="Account"
  88. >
  89. <img
  90. v-if="currentUser.photoURL"
  91. :src="currentUser.photoURL"
  92. class="w-6 h-6 rounded-full material-icons"
  93. alt="Profile image"
  94. />
  95. <i v-else class="material-icons">account_circle</i>
  96. </button>
  97. <template #popover>
  98. <div>
  99. <nuxt-link v-close-popover :to="localePath('settings')">
  100. <button class="icon button">
  101. <i class="material-icons">settings</i>
  102. <span>
  103. {{ $t("settings") }}
  104. </span>
  105. </button>
  106. </nuxt-link>
  107. </div>
  108. <div>
  109. <FirebaseLogout />
  110. </div>
  111. </template>
  112. </v-popover>
  113. <v-popover>
  114. <button v-tooltip="$t('more')" class="icon button">
  115. <i class="material-icons">drag_indicator</i>
  116. </button>
  117. <template #popover>
  118. <button
  119. v-close-popover
  120. class="icon button"
  121. @click="showExtensions = true"
  122. >
  123. <i class="material-icons">extension</i>
  124. <span>{{ $t("extensions") }}</span>
  125. </button>
  126. <button
  127. v-close-popover
  128. class="icon button"
  129. @click="showShortcuts = true"
  130. >
  131. <i class="material-icons">keyboard</i>
  132. <span>{{ $t("shortcuts") }}</span>
  133. </button>
  134. <button
  135. v-close-popover
  136. class="icon button"
  137. @click="showSupport = true"
  138. >
  139. <i class="material-icons">favorite</i>
  140. <span>{{ $t("support_us") }}</span>
  141. </button>
  142. <button
  143. v-close-popover
  144. class="icon button"
  145. onClick="window.open('https://twitter.com/share?text=👽 Hoppscotch • Open source API development ecosystem - Helps you create requests faster, saving precious time on development.&url=https://hoppscotch.io&hashtags=hoppscotch&via=hoppscotch_io');"
  146. >
  147. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24">
  148. <path
  149. d="M24 4.557a9.83 9.83 0 01-2.828.775 4.932 4.932 0 002.165-2.724 9.864 9.864 0 01-3.127 1.195 4.916 4.916 0 00-3.594-1.555c-3.179 0-5.515 2.966-4.797 6.045A13.978 13.978 0 011.671 3.149a4.93 4.93 0 001.523 6.574 4.903 4.903 0 01-2.229-.616c-.054 2.281 1.581 4.415 3.949 4.89a4.935 4.935 0 01-2.224.084 4.928 4.928 0 004.6 3.419A9.9 9.9 0 010 19.54a13.94 13.94 0 007.548 2.212c9.142 0 14.307-7.721 13.995-14.646A10.025 10.025 0 0024 4.557z"
  150. />
  151. </svg>
  152. <span>Tweet</span>
  153. </button>
  154. <button
  155. v-if="navigatorShare"
  156. v-close-popover
  157. v-tooltip="$t('more')"
  158. class="icon button"
  159. @click="nativeShare"
  160. >
  161. <i class="material-icons">share</i>
  162. <span>Share</span>
  163. </button>
  164. </template>
  165. </v-popover>
  166. </span>
  167. </div>
  168. <AppExtensions
  169. :show="showExtensions"
  170. @hide-modal="showExtensions = false"
  171. />
  172. <AppShortcuts :show="showShortcuts" @hide-modal="showShortcuts = false" />
  173. <AppSupport :show="showSupport" @hide-modal="showSupport = false" />
  174. <FirebaseEmail :show="showEmail" @hide-modal="showEmail = false" />
  175. </header>
  176. </template>
  177. <script>
  178. import intializePwa from "~/helpers/pwa"
  179. import { currentUser$ } from "~/helpers/fb/auth"
  180. import { getLocalConfig, setLocalConfig } from "~/newstore/localpersistence"
  181. // import { hasExtensionInstalled } from "~/helpers/strategies/ExtensionStrategy"
  182. export default {
  183. data() {
  184. return {
  185. // Once the PWA code is initialized, this holds a method
  186. // that can be called to show the user the installation
  187. // prompt.
  188. showInstallPrompt: null,
  189. showExtensions: false,
  190. showShortcuts: false,
  191. showSupport: false,
  192. showEmail: false,
  193. navigatorShare: navigator.share,
  194. }
  195. },
  196. subscriptions() {
  197. return {
  198. currentUser: currentUser$,
  199. }
  200. },
  201. async mounted() {
  202. // Initializes the PWA code - checks if the app is installed,
  203. // etc.
  204. this.showInstallPrompt = await intializePwa()
  205. const cookiesAllowed = getLocalConfig("cookiesAllowed") === "yes"
  206. if (!cookiesAllowed) {
  207. this.$toast.show(this.$t("we_use_cookies"), {
  208. icon: "info",
  209. duration: 5000,
  210. theme: "toasted-primary",
  211. action: [
  212. {
  213. text: this.$t("dismiss"),
  214. onClick: (_, toastObject) => {
  215. setLocalConfig("cookiesAllowed", "yes")
  216. toastObject.goAway(0)
  217. },
  218. },
  219. ],
  220. })
  221. }
  222. // const showAd = localStorage.getItem("showAd") === "no"
  223. // if (!showAd) {
  224. // setTimeout(() => {
  225. // this.$toast.clear()
  226. // this.$toast.show(
  227. // "<span><a href='https://fundoss.org/collective/hoppscotch' target='_blank' rel='noopener'>Sponsor us to support Hoppscotch open source project 💖</a><br><sub>Whoosh this away to dismiss.</sub></span>",
  228. // {
  229. // icon: "",
  230. // duration: 0,
  231. // theme: "toasted-ad",
  232. // action: [
  233. // {
  234. // text: "Donate",
  235. // icon: "chevron_right",
  236. // onClick: (_, toastObject) => {
  237. // localStorage.setItem("showAd", "no")
  238. // toastObject.goAway(0)
  239. // window.open("https://fundoss.org/collective/hoppscotch")
  240. // },
  241. // },
  242. // ],
  243. // onComplete() {
  244. // localStorage.setItem("showAd", "no")
  245. // },
  246. // }
  247. // )
  248. // }, 6000)
  249. // }
  250. // let showExtensionsToast = localStorage.getItem("showExtensionsToast") === "yes"
  251. // if (!showExtensionsToast) {
  252. // setTimeout(() => {
  253. // if (!hasExtensionInstalled()) {
  254. // this.$toast.show(this.$t("extensions_info2"), {
  255. // icon: "extension",
  256. // duration: 5000,
  257. // theme: "toasted-primary",
  258. // action: [
  259. // {
  260. // text: this.$t("yes"),
  261. // onClick: (_, toastObject) => {
  262. // this.showExtensions = true
  263. // localStorage.setItem("showExtensionsToast", "yes")
  264. // toastObject.goAway(0)
  265. // },
  266. // },
  267. // {
  268. // text: this.$t("no"),
  269. // onClick: (_, toastObject) => {
  270. // this.$store.commit("setMiscState", {
  271. // value: false,
  272. // attribute: "showExtensionsToast",
  273. // })
  274. // localStorage.setItem("showExtensionsToast", "no")
  275. // toastObject.goAway(0)
  276. // },
  277. // },
  278. // ],
  279. // })
  280. // }
  281. // }, 5000)
  282. // }
  283. },
  284. methods: {
  285. nativeShare() {
  286. if (navigator.share) {
  287. navigator
  288. .share({
  289. title: "Hoppscotch",
  290. text: "Hoppscotch • Open source API development ecosystem - Helps you create requests faster, saving precious time on development.",
  291. url: "https://hoppscotch.io",
  292. })
  293. .then(() => {})
  294. .catch(console.error)
  295. } else {
  296. // fallback
  297. }
  298. },
  299. },
  300. }
  301. </script>
  302. <style scoped lang="scss">
  303. .logo {
  304. @apply text-xl;
  305. @apply transition-colors;
  306. @apply ease-in-out;
  307. @apply duration-150;
  308. @apply hover:text-accent;
  309. }
  310. @keyframes slideIn {
  311. 0% {
  312. @apply opacity-0;
  313. @apply -left-4;
  314. }
  315. 100% {
  316. @apply opacity-100;
  317. @apply left-0;
  318. }
  319. }
  320. .slide-in {
  321. @apply relative;
  322. animation: slideIn 0.2s forwards ease-in-out;
  323. }
  324. </style>