default.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 overflow-y-auto 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 columnLayout = useSetting("COLUMN_LAYOUT")
  63. const windowInnerWidth = useWindowSize()
  64. // Initially apply
  65. onBeforeMount(() => {
  66. if (windowInnerWidth.x.value < 768) {
  67. rightSidebar.value = false
  68. columnLayout.value = true
  69. }
  70. })
  71. // Listen for updates
  72. watch(windowInnerWidth.x, () => {
  73. if (windowInnerWidth.x.value < 768) {
  74. rightSidebar.value = false
  75. columnLayout.value = true
  76. }
  77. })
  78. }
  79. function updateThemes() {
  80. const { $colorMode } = useContext() as any
  81. // Apply theme updates
  82. const themeColor = useSetting("THEME_COLOR")
  83. const bgColor = useSetting("BG_COLOR")
  84. const fontSize = useSetting("FONT_SIZE")
  85. // Initially apply
  86. onBeforeMount(() => {
  87. document.documentElement.setAttribute("data-accent", themeColor.value)
  88. $colorMode.preference = bgColor.value
  89. document.documentElement.setAttribute("data-font-size", fontSize.value)
  90. })
  91. // Listen for updates
  92. watch(themeColor, () =>
  93. document.documentElement.setAttribute("data-accent", themeColor.value)
  94. )
  95. watch(bgColor, () => ($colorMode.preference = bgColor.value))
  96. watch(fontSize, () =>
  97. document.documentElement.setAttribute("data-font-size", fontSize.value)
  98. )
  99. }
  100. function defineJumpActions() {
  101. const router = useRouter()
  102. defineActionHandler("navigation.jump.rest", () => {
  103. router.push({ path: "/" })
  104. })
  105. defineActionHandler("navigation.jump.graphql", () => {
  106. router.push({ path: "/graphql" })
  107. })
  108. defineActionHandler("navigation.jump.realtime", () => {
  109. router.push({ path: "/realtime" })
  110. })
  111. defineActionHandler("navigation.jump.documentation", () => {
  112. router.push({ path: "/documentation" })
  113. })
  114. defineActionHandler("navigation.jump.settings", () => {
  115. router.push({ path: "/settings" })
  116. })
  117. defineActionHandler("navigation.jump.back", () => {
  118. router.go(-1)
  119. })
  120. defineActionHandler("navigation.jump.forward", () => {
  121. router.go(1)
  122. })
  123. }
  124. export default defineComponent({
  125. components: { Splitpanes, Pane },
  126. setup() {
  127. appLayout()
  128. hookKeybindingsListener()
  129. defineJumpActions()
  130. updateThemes()
  131. return {
  132. windowInnerWidth: useWindowSize(),
  133. ZEN_MODE: useSetting("ZEN_MODE"),
  134. }
  135. },
  136. head() {
  137. return this.$nuxtI18nHead({ addSeoAttributes: true })
  138. },
  139. watch: {
  140. $route(to) {
  141. logPageView(to.fullPath)
  142. },
  143. },
  144. beforeMount() {
  145. setupLocalPersistence()
  146. registerApolloAuthUpdate()
  147. },
  148. async mounted() {
  149. performMigrations()
  150. console.log(
  151. "%cWe ❤︎ open source!",
  152. "background-color:white;padding:8px 16px;border-radius:8px;font-size:32px;color:red;"
  153. )
  154. console.log(
  155. "%cContribute: https://github.com/hoppscotch/hoppscotch",
  156. "background-color:black;padding:4px 8px;border-radius:8px;font-size:16px;color:white;"
  157. )
  158. const workbox = await (window as any).$workbox
  159. if (workbox) {
  160. workbox.addEventListener("installed", (event: any) => {
  161. if (event.isUpdate) {
  162. this.$toast.show(`${this.$t("app.new_version_found")}`, {
  163. icon: "download_for_offline",
  164. duration: 0,
  165. action: [
  166. {
  167. text: `${this.$t("app.reload")}`,
  168. class: "!ml-auto",
  169. onClick: (_, toastObject) => {
  170. toastObject.goAway(0)
  171. window.location.reload()
  172. },
  173. },
  174. ],
  175. })
  176. }
  177. })
  178. }
  179. initializeFirebase()
  180. initUserInfo()
  181. logPageView(this.$router.currentRoute.fullPath)
  182. },
  183. })
  184. </script>