Header.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div>
  3. <header
  4. class="flex space-x-2 flex-1 py-2 px-2 items-center justify-between"
  5. >
  6. <div class="space-x-2 inline-flex items-center">
  7. <ButtonSecondary
  8. class="tracking-wide !font-bold !text-secondaryDark"
  9. label="HOPPSCOTCH"
  10. to="/"
  11. />
  12. <AppGitHubStarButton class="mt-1.5 transition hidden sm:flex" />
  13. </div>
  14. <div class="space-x-2 inline-flex items-center">
  15. <ButtonSecondary
  16. id="installPWA"
  17. v-tippy="{ theme: 'tooltip' }"
  18. :title="$t('header.install_pwa')"
  19. svg="download"
  20. class="rounded"
  21. @click.native="showInstallPrompt()"
  22. />
  23. <ButtonSecondary
  24. v-tippy="{ theme: 'tooltip' }"
  25. :title="`${$t('app.search')} <kbd>/</kbd>`"
  26. svg="search"
  27. class="rounded"
  28. @click.native="showSearch = true"
  29. />
  30. <ButtonSecondary
  31. v-tippy="{ theme: 'tooltip' }"
  32. :title="`${$t('support.title')} <kbd>?</kbd>`"
  33. svg="life-buoy"
  34. class="rounded"
  35. @click.native="showSupport = true"
  36. />
  37. <ButtonSecondary
  38. v-if="currentUser === null"
  39. svg="upload-cloud"
  40. :label="$t('header.save_workspace')"
  41. filled
  42. class="hidden !font-semibold md:flex"
  43. @click.native="showLogin = true"
  44. />
  45. <ButtonPrimary
  46. v-if="currentUser === null"
  47. :label="$t('header.login')"
  48. @click.native="showLogin = true"
  49. />
  50. <span v-else class="px-2">
  51. <tippy ref="user" interactive trigger="click" theme="popover" arrow>
  52. <template #trigger>
  53. <ProfilePicture
  54. v-if="currentUser.photoURL"
  55. v-tippy="{
  56. theme: 'tooltip',
  57. }"
  58. :url="currentUser.photoURL"
  59. :alt="currentUser.displayName"
  60. :title="currentUser.displayName"
  61. indicator
  62. :indicator-styles="isOnLine ? 'bg-green-500' : 'bg-red-500'"
  63. />
  64. <ButtonSecondary
  65. v-else
  66. v-tippy="{ theme: 'tooltip' }"
  67. :title="$t('header.account')"
  68. class="rounded"
  69. svg="user"
  70. />
  71. </template>
  72. <SmartItem
  73. to="/settings"
  74. svg="settings"
  75. :label="$t('navigation.settings')"
  76. @click.native="$refs.user.tippy().hide()"
  77. />
  78. <FirebaseLogout @confirm-logout="$refs.user.tippy().hide()" />
  79. </tippy>
  80. </span>
  81. </div>
  82. </header>
  83. <AppAnnouncement v-if="!isOnLine" />
  84. <FirebaseLogin :show="showLogin" @hide-modal="showLogin = false" />
  85. <AppSupport :show="showSupport" @hide-modal="showSupport = false" />
  86. <AppPowerSearch :show="showSearch" @hide-modal="showSearch = false" />
  87. </div>
  88. </template>
  89. <script>
  90. import { defineComponent, ref } from "@nuxtjs/composition-api"
  91. import intializePwa from "~/helpers/pwa"
  92. import { currentUser$ } from "~/helpers/fb/auth"
  93. import { getLocalConfig, setLocalConfig } from "~/newstore/localpersistence"
  94. import { useReadonlyStream } from "~/helpers/utils/composables"
  95. import { defineActionHandler } from "~/helpers/actions"
  96. export default defineComponent({
  97. setup() {
  98. const showSupport = ref(false)
  99. const showSearch = ref(false)
  100. defineActionHandler("modals.support.toggle", () => {
  101. showSupport.value = !showSupport.value
  102. })
  103. defineActionHandler("modals.search.toggle", () => {
  104. showSearch.value = !showSearch.value
  105. })
  106. return {
  107. currentUser: useReadonlyStream(currentUser$, null),
  108. showSupport,
  109. showSearch,
  110. }
  111. },
  112. data() {
  113. return {
  114. // Once the PWA code is initialized, this holds a method
  115. // that can be called to show the user the installation
  116. // prompt.
  117. showInstallPrompt: null,
  118. showLogin: false,
  119. isOnLine: navigator.onLine,
  120. }
  121. },
  122. async mounted() {
  123. window.addEventListener("online", () => {
  124. this.isOnLine = true
  125. })
  126. window.addEventListener("offline", () => {
  127. this.isOnLine = false
  128. })
  129. // Initializes the PWA code - checks if the app is installed,
  130. // etc.
  131. this.showInstallPrompt = await intializePwa()
  132. const cookiesAllowed = getLocalConfig("cookiesAllowed") === "yes"
  133. if (!cookiesAllowed) {
  134. this.$toast.show(this.$t("app.we_use_cookies").toString(), {
  135. icon: "cookie",
  136. duration: 0,
  137. action: [
  138. {
  139. text: this.$t("action.learn_more").toString(),
  140. onClick: (_, toastObject) => {
  141. setLocalConfig("cookiesAllowed", "yes")
  142. toastObject.goAway(0)
  143. window
  144. .open("https://docs.hoppscotch.io/privacy", "_blank")
  145. .focus()
  146. },
  147. },
  148. {
  149. text: this.$t("action.dismiss").toString(),
  150. onClick: (_, toastObject) => {
  151. setLocalConfig("cookiesAllowed", "yes")
  152. toastObject.goAway(0)
  153. },
  154. },
  155. ],
  156. })
  157. }
  158. },
  159. })
  160. </script>