default.vue 5.6 KB

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