default.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div class="flex h-screen w-screen">
  3. <Splitpanes class="no-splitter" :dbl-click-splitter="false" horizontal>
  4. <Pane v-if="!ZEN_MODE" style="height: auto">
  5. <AppHeader />
  6. </Pane>
  7. <Pane class="flex flex-1 hide-scrollbar !overflow-auto">
  8. <Splitpanes
  9. class="no-splitter"
  10. :dbl-click-splitter="false"
  11. :horizontal="!(windowInnerWidth.x.value >= 768)"
  12. >
  13. <Pane
  14. style="width: auto; height: auto"
  15. class="hide-scrollbar !overflow-auto"
  16. >
  17. <AppSidenav />
  18. </Pane>
  19. <Pane class="flex flex-1 hide-scrollbar !overflow-auto">
  20. <Splitpanes
  21. class="no-splitter"
  22. :dbl-click-splitter="false"
  23. horizontal
  24. >
  25. <Pane class="flex flex-1 hide-scrollbar !overflow-auto">
  26. <main class="flex flex-1 w-full">
  27. <nuxt class="flex flex-1" />
  28. </main>
  29. </Pane>
  30. </Splitpanes>
  31. </Pane>
  32. </Splitpanes>
  33. </Pane>
  34. <Pane style="height: auto">
  35. <AppFooter />
  36. </Pane>
  37. </Splitpanes>
  38. </div>
  39. </template>
  40. <script lang="ts">
  41. import {
  42. defineComponent,
  43. onBeforeMount,
  44. useContext,
  45. useRouter,
  46. watch,
  47. } from "@nuxtjs/composition-api"
  48. import { Splitpanes, Pane } from "splitpanes"
  49. import "splitpanes/dist/splitpanes.css"
  50. import { setupLocalPersistence } from "~/newstore/localpersistence"
  51. import { performMigrations } from "~/helpers/migrations"
  52. import { initUserInfo } from "~/helpers/teams/BackendUserInfo"
  53. import { registerApolloAuthUpdate } from "~/helpers/apollo"
  54. import { initializeFirebase } from "~/helpers/fb"
  55. import { useSetting } from "~/newstore/settings"
  56. import { logPageView } from "~/helpers/fb/analytics"
  57. import { hookKeybindingsListener } from "~/helpers/keybindings"
  58. import { defineActionHandler } from "~/helpers/actions"
  59. import useWindowSize from "~/helpers/utils/useWindowSize"
  60. function appLayout() {
  61. const rightSidebar = useSetting("RIGHT_SIDEBAR")
  62. const windowInnerWidth = useWindowSize()
  63. // Initially apply
  64. onBeforeMount(() => {
  65. if (windowInnerWidth.x.value < 768) rightSidebar.value = false
  66. })
  67. // Listen for updates
  68. watch(windowInnerWidth.x, () =>
  69. windowInnerWidth.x.value >= 768
  70. ? (rightSidebar.value = true)
  71. : (rightSidebar.value = false)
  72. )
  73. }
  74. function updateThemes() {
  75. const { $colorMode } = useContext() as any
  76. // Apply theme updates
  77. const themeColor = useSetting("THEME_COLOR")
  78. const bgColor = useSetting("BG_COLOR")
  79. const fontSize = useSetting("FONT_SIZE")
  80. // Initially apply
  81. onBeforeMount(() => {
  82. document.documentElement.setAttribute("data-accent", themeColor.value)
  83. $colorMode.preference = bgColor.value
  84. document.documentElement.setAttribute("data-font-size", fontSize.value)
  85. })
  86. // Listen for updates
  87. watch(themeColor, () =>
  88. document.documentElement.setAttribute("data-accent", themeColor.value)
  89. )
  90. watch(bgColor, () => ($colorMode.preference = bgColor.value))
  91. watch(fontSize, () =>
  92. document.documentElement.setAttribute("data-font-size", fontSize.value)
  93. )
  94. }
  95. function defineJumpActions() {
  96. const router = useRouter()
  97. defineActionHandler("navigation.jump.rest", () => {
  98. router.push({ path: "/" })
  99. })
  100. defineActionHandler("navigation.jump.graphql", () => {
  101. router.push({ path: "/graphql" })
  102. })
  103. defineActionHandler("navigation.jump.realtime", () => {
  104. router.push({ path: "/realtime" })
  105. })
  106. defineActionHandler("navigation.jump.documentation", () => {
  107. router.push({ path: "/documentation" })
  108. })
  109. defineActionHandler("navigation.jump.settings", () => {
  110. router.push({ path: "/settings" })
  111. })
  112. defineActionHandler("navigation.jump.back", () => {
  113. router.go(-1)
  114. })
  115. defineActionHandler("navigation.jump.forward", () => {
  116. router.go(1)
  117. })
  118. }
  119. export default defineComponent({
  120. components: { Splitpanes, Pane },
  121. setup() {
  122. appLayout()
  123. hookKeybindingsListener()
  124. defineJumpActions()
  125. updateThemes()
  126. return {
  127. windowInnerWidth: useWindowSize(),
  128. ZEN_MODE: useSetting("ZEN_MODE"),
  129. }
  130. },
  131. head() {
  132. return this.$nuxtI18nHead({ addSeoAttributes: true })
  133. },
  134. watch: {
  135. $route(to) {
  136. logPageView(to.fullPath)
  137. },
  138. },
  139. beforeMount() {
  140. setupLocalPersistence()
  141. registerApolloAuthUpdate()
  142. },
  143. async mounted() {
  144. performMigrations()
  145. console.log(
  146. "%cWe ❤︎ open source!",
  147. "background-color:white;padding:8px 16px;border-radius:8px;font-size:32px;color:red;"
  148. )
  149. console.log(
  150. "%cContribute: https://github.com/hoppscotch/hoppscotch",
  151. "background-color:black;padding:4px 8px;border-radius:8px;font-size:16px;color:white;"
  152. )
  153. const workbox = await (window as any).$workbox
  154. if (workbox) {
  155. workbox.addEventListener("installed", (event: any) => {
  156. if (event.isUpdate) {
  157. this.$toast.show(this.$t("app.new_version_found").toString(), {
  158. icon: "download_for_offline",
  159. duration: 0,
  160. action: [
  161. {
  162. text: this.$t("app.reload").toString(),
  163. onClick: (_, toastObject) => {
  164. toastObject.goAway(0)
  165. window.location.reload()
  166. },
  167. },
  168. ],
  169. })
  170. }
  171. })
  172. }
  173. initializeFirebase()
  174. initUserInfo()
  175. logPageView(this.$router.currentRoute.fullPath)
  176. },
  177. })
  178. </script>