Header.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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="hide-on-small-screen logo">Hoppscotch</h1>
  7. <h1 class="show-on-small-screen logo">Hs</h1>
  8. </nuxt-link>
  9. <iframe
  10. src="https://ghbtns.com/github-btn.html?user=hoppscotch&repo=hoppscotch&type=star&count=true"
  11. frameborder="0"
  12. scrolling="0"
  13. width="150"
  14. height="20"
  15. title="GitHub"
  16. class="ml-8 hide-on-small-screen"
  17. loading="lazy"
  18. ></iframe>
  19. </span>
  20. <span>
  21. <a
  22. href="https://appwrite.io/?ref=hoppscotch"
  23. target="_blank"
  24. rel="noopener"
  25. class="inline-flex items-center px-4 py-2 mx-4 font-mono text-sm rounded-md bg-bgDarkColor hide-on-small-screen"
  26. >
  27. Appwrite - Open-Source Backend as a Service
  28. <img class="w-8 ml-2" src="~assets/images/appwrite-icon.svg" alt="Appwrite" />
  29. </a>
  30. <button
  31. class="icon"
  32. id="installPWA"
  33. @click.prevent="showInstallPrompt()"
  34. v-tooltip="$t('install_pwa')"
  35. >
  36. <i class="material-icons">offline_bolt</i>
  37. </button>
  38. <a
  39. href="https://github.com/hoppscotch/hoppscotch"
  40. target="_blank"
  41. aria-label="GitHub"
  42. rel="noopener"
  43. >
  44. <button class="icon" aria-label="GitHub" v-tooltip="'GitHub'">
  45. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" class="material-icons">
  46. <path
  47. 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"
  48. />
  49. </svg>
  50. </button>
  51. </a>
  52. <v-popover v-if="fb.currentUser === null">
  53. <button class="icon" v-tooltip="$t('login_with')">
  54. <i class="material-icons">login</i>
  55. </button>
  56. <template slot="popover">
  57. <FirebaseLogin />
  58. </template>
  59. </v-popover>
  60. <v-popover v-else>
  61. <button
  62. class="icon"
  63. v-tooltip="
  64. (fb.currentUser.displayName || '<label><i>Name not found</i></label>') +
  65. '<br>' +
  66. (fb.currentUser.email || '<label><i>Email not found</i></label>')
  67. "
  68. aria-label="Account"
  69. >
  70. <img
  71. v-if="fb.currentUser.photoURL"
  72. :src="fb.currentUser.photoURL"
  73. class="rounded-full material-icons"
  74. alt="Profile image"
  75. />
  76. <i v-else class="material-icons">account_circle</i>
  77. </button>
  78. <template slot="popover">
  79. <div>
  80. <nuxt-link :to="localePath('settings')" v-close-popover>
  81. <button class="icon">
  82. <i class="material-icons">settings</i>
  83. <span>
  84. {{ $t("settings") }}
  85. </span>
  86. </button>
  87. </nuxt-link>
  88. </div>
  89. <div>
  90. <FirebaseLogout />
  91. </div>
  92. </template>
  93. </v-popover>
  94. <v-popover>
  95. <button class="icon" v-tooltip="$t('more')">
  96. <i class="material-icons">drag_indicator</i>
  97. </button>
  98. <template slot="popover">
  99. <button class="icon" @click="showExtensions = true" v-close-popover>
  100. <i class="material-icons">extension</i>
  101. <span>{{ $t("extensions") }}</span>
  102. </button>
  103. <button class="icon" @click="showShortcuts = true" v-close-popover>
  104. <i class="material-icons">keyboard</i>
  105. <span>{{ $t("shortcuts") }}</span>
  106. </button>
  107. <button class="icon" @click="showSupport = true" v-close-popover>
  108. <i class="material-icons">favorite</i>
  109. <span>{{ $t("support_us") }}</span>
  110. </button>
  111. <button
  112. class="icon"
  113. onClick="window.open('https://twitter.com/share?text=👽 Hoppscotch • A free, fast and beautiful API request builder - Helps you create requests faster, saving precious time on development.&url=https://hoppscotch.io&hashtags=hoppscotch&via=liyasthomas');"
  114. v-close-popover
  115. >
  116. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24">
  117. <path
  118. 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"
  119. />
  120. </svg>
  121. <span>Tweet</span>
  122. </button>
  123. <button
  124. v-if="navigatorShare"
  125. class="icon"
  126. @click="nativeShare"
  127. v-close-popover
  128. v-tooltip="$t('more')"
  129. >
  130. <i class="material-icons">share</i>
  131. <span>Share</span>
  132. </button>
  133. </template>
  134. </v-popover>
  135. </span>
  136. </div>
  137. <AppExtensions :show="showExtensions" @hide-modal="showExtensions = false" />
  138. <AppShortcuts :show="showShortcuts" @hide-modal="showShortcuts = false" />
  139. <AppSupport :show="showSupport" @hide-modal="showSupport = false" />
  140. </header>
  141. </template>
  142. <style scoped lang="scss">
  143. $responsiveWidth: 768px;
  144. .logo {
  145. @apply text-xl;
  146. @apply transition-colors;
  147. @apply ease-in-out;
  148. @apply duration-150;
  149. &:hover {
  150. @apply text-acColor;
  151. }
  152. }
  153. @keyframes slideIn {
  154. 0% {
  155. @apply opacity-0;
  156. @apply -left-4;
  157. }
  158. 100% {
  159. @apply opacity-100;
  160. @apply left-0;
  161. }
  162. }
  163. .slide-in {
  164. @apply relative;
  165. animation: slideIn 0.2s forwards ease-in-out;
  166. }
  167. .show-on-small-screen {
  168. @apply hidden;
  169. }
  170. @media (max-width: $responsiveWidth) {
  171. .show-on-small-screen {
  172. @apply inline-flex;
  173. }
  174. }
  175. </style>
  176. <script>
  177. import intializePwa from "~/helpers/pwa"
  178. import { fb } from "~/helpers/fb"
  179. // import { hasExtensionInstalled } from "~/helpers/strategies/ExtensionStrategy"
  180. export default {
  181. data() {
  182. return {
  183. // Once the PWA code is initialized, this holds a method
  184. // that can be called to show the user the installation
  185. // prompt.
  186. showInstallPrompt: null,
  187. showExtensions: false,
  188. showShortcuts: false,
  189. showSupport: false,
  190. navigatorShare: navigator.share,
  191. fb,
  192. }
  193. },
  194. async mounted() {
  195. this._keyListener = function (e) {
  196. if (e.key === "Escape") {
  197. e.preventDefault()
  198. this.showExtensions = this.showShortcuts = this.showSupport = false
  199. }
  200. }
  201. document.addEventListener("keydown", this._keyListener.bind(this))
  202. // Initializes the PWA code - checks if the app is installed,
  203. // etc.
  204. this.showInstallPrompt = await intializePwa()
  205. let cookiesAllowed = localStorage.getItem("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: (e, toastObject) => {
  215. localStorage.setItem("cookiesAllowed", "yes")
  216. toastObject.goAway(0)
  217. },
  218. },
  219. ],
  220. })
  221. }
  222. // let showAd = localStorage.getItem("showAd") === "no"
  223. // if (!showAd) {
  224. // setTimeout(() => {
  225. // this.$toast.clear()
  226. // this.$toast.show(
  227. // "<span><a href='https://github.com/sponsors/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: "Sponsor",
  235. // icon: "chevron_right",
  236. // onClick: (e, toastObject) => {
  237. // localStorage.setItem("showAd", "no")
  238. // toastObject.goAway(0)
  239. // window.open("https://github.com/sponsors/hoppscotch")
  240. // },
  241. // },
  242. // ],
  243. // onComplete() {
  244. // localStorage.setItem("showAd", "no")
  245. // },
  246. // }
  247. // )
  248. // }, 8000)
  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: (e, toastObject) => {
  262. // this.showExtensions = true
  263. // localStorage.setItem("showExtensionsToast", "yes")
  264. // toastObject.goAway(0)
  265. // },
  266. // },
  267. // {
  268. // text: this.$t("no"),
  269. // onClick: (e, 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:
  291. "Hoppscotch • A free, fast and beautiful API request builder - Helps you create requests faster, saving precious time on development.",
  292. url: "https://hoppscotch.io",
  293. })
  294. .then(() => {})
  295. .catch(console.error)
  296. } else {
  297. // fallback
  298. }
  299. },
  300. },
  301. beforeDestroy() {
  302. document.removeEventListener("keydown", this._keyListener)
  303. },
  304. }
  305. </script>