Header.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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="/profile"
  74. svg="user"
  75. :label="$t('navigation.profile')"
  76. @click.native="$refs.user.tippy().hide()"
  77. />
  78. <SmartItem
  79. to="/settings"
  80. svg="settings"
  81. :label="$t('navigation.settings')"
  82. @click.native="$refs.user.tippy().hide()"
  83. />
  84. <FirebaseLogout @confirm-logout="$refs.user.tippy().hide()" />
  85. </tippy>
  86. </span>
  87. </div>
  88. </header>
  89. <AppAnnouncement v-if="!isOnLine" />
  90. <FirebaseLogin :show="showLogin" @hide-modal="showLogin = false" />
  91. <AppSupport :show="showSupport" @hide-modal="showSupport = false" />
  92. <AppPowerSearch :show="showSearch" @hide-modal="showSearch = false" />
  93. </div>
  94. </template>
  95. <script>
  96. import { defineComponent, ref } from "@nuxtjs/composition-api"
  97. import intializePwa from "~/helpers/pwa"
  98. import { currentUser$ } from "~/helpers/fb/auth"
  99. import { getLocalConfig, setLocalConfig } from "~/newstore/localpersistence"
  100. import { useReadonlyStream } from "~/helpers/utils/composables"
  101. import { defineActionHandler } from "~/helpers/actions"
  102. export default defineComponent({
  103. setup() {
  104. const showSupport = ref(false)
  105. const showSearch = ref(false)
  106. defineActionHandler("modals.support.toggle", () => {
  107. showSupport.value = !showSupport.value
  108. })
  109. defineActionHandler("modals.search.toggle", () => {
  110. showSearch.value = !showSearch.value
  111. })
  112. return {
  113. currentUser: useReadonlyStream(currentUser$, null),
  114. showSupport,
  115. showSearch,
  116. }
  117. },
  118. data() {
  119. return {
  120. // Once the PWA code is initialized, this holds a method
  121. // that can be called to show the user the installation
  122. // prompt.
  123. showInstallPrompt: null,
  124. showLogin: false,
  125. isOnLine: navigator.onLine,
  126. }
  127. },
  128. async mounted() {
  129. window.addEventListener("online", () => {
  130. this.isOnLine = true
  131. })
  132. window.addEventListener("offline", () => {
  133. this.isOnLine = false
  134. })
  135. // Initializes the PWA code - checks if the app is installed,
  136. // etc.
  137. this.showInstallPrompt = await intializePwa()
  138. const cookiesAllowed = getLocalConfig("cookiesAllowed") === "yes"
  139. if (!cookiesAllowed) {
  140. this.$toast.show(this.$t("app.we_use_cookies"), {
  141. icon: "cookie",
  142. duration: 0,
  143. action: [
  144. {
  145. text: this.$t("action.learn_more"),
  146. onClick: (_, toastObject) => {
  147. setLocalConfig("cookiesAllowed", "yes")
  148. toastObject.goAway(0)
  149. window
  150. .open("https://docs.hoppscotch.io/privacy", "_blank")
  151. .focus()
  152. },
  153. },
  154. {
  155. text: this.$t("action.dismiss"),
  156. onClick: (_, toastObject) => {
  157. setLocalConfig("cookiesAllowed", "yes")
  158. toastObject.goAway(0)
  159. },
  160. },
  161. ],
  162. })
  163. }
  164. },
  165. })
  166. </script>