api-client/layouts/default.vue

186 lines
5.1 KiB
Vue
Raw Normal View History

2019-08-24 03:06:57 +00:00
<template>
2021-07-01 16:39:11 +00:00
<div class="flex h-screen w-screen">
<Splitpanes :dbl-click-splitter="false" horizontal>
2021-08-05 17:22:02 +00:00
<Pane class="flex flex-1 hide-scrollbar !overflow-auto">
2021-08-05 15:59:05 +00:00
<Splitpanes
:dbl-click-splitter="false"
:horizontal="!(windowInnerWidth >= 768)"
>
2021-07-01 16:39:11 +00:00
<Pane
v-if="LEFT_SIDEBAR"
2021-08-05 15:59:05 +00:00
style="width: auto; height: auto"
class="hide-scrollbar !overflow-auto"
2021-07-01 16:39:11 +00:00
>
<AppSidenav />
</Pane>
2021-08-05 17:22:02 +00:00
<Pane class="flex flex-1 hide-scrollbar !overflow-auto">
<Splitpanes :dbl-click-splitter="false" horizontal>
<Pane v-if="!ZEN_MODE" style="height: auto">
2021-07-01 16:39:11 +00:00
<AppHeader />
</Pane>
2021-08-05 17:22:02 +00:00
<Pane class="flex flex-1 hide-scrollbar !overflow-auto">
2021-08-14 18:16:03 +00:00
<main class="flex flex-1 w-full">
2021-08-05 17:22:02 +00:00
<nuxt class="flex flex-1" />
</main>
2021-07-01 16:39:11 +00:00
</Pane>
</Splitpanes>
</Pane>
</Splitpanes>
</Pane>
2021-07-07 23:28:42 +00:00
<Pane style="height: auto">
<AppFooter />
2021-07-01 16:39:11 +00:00
</Pane>
</Splitpanes>
2019-09-02 04:48:01 +00:00
</div>
2019-08-24 03:06:57 +00:00
</template>
2019-10-25 08:14:34 +00:00
<script lang="ts">
2021-08-12 08:14:10 +00:00
import {
defineComponent,
onBeforeMount,
2021-08-12 08:14:10 +00:00
useContext,
useRouter,
watch,
} from "@nuxtjs/composition-api"
2021-07-01 16:39:11 +00:00
import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css"
2021-07-06 12:20:37 +00:00
import { setupLocalPersistence } from "~/newstore/localpersistence"
import { performMigrations } from "~/helpers/migrations"
2021-05-14 00:16:10 +00:00
import { initUserInfo } from "~/helpers/teams/BackendUserInfo"
import { registerApolloAuthUpdate } from "~/helpers/apollo"
2021-06-14 04:07:30 +00:00
import { initializeFirebase } from "~/helpers/fb"
2021-08-12 08:14:10 +00:00
import { useSetting } from "~/newstore/settings"
2021-07-09 03:39:07 +00:00
import { logPageView } from "~/helpers/fb/analytics"
import { hookKeybindingsListener } from "~/helpers/keybindings"
2021-08-10 08:16:42 +00:00
import { defineActionHandler } from "~/helpers/actions"
function updateThemes() {
const { $colorMode } = useContext() as any
// Apply theme updates
const themeColor = useSetting("THEME_COLOR")
const bgColor = useSetting("BG_COLOR")
const fontSize = useSetting("FONT_SIZE")
// Initially apply
onBeforeMount(() => {
document.documentElement.setAttribute("data-accent", themeColor.value)
$colorMode.preference = bgColor.value
document.documentElement.setAttribute("data-font-size", fontSize.value)
})
// Listen for updates
watch(themeColor, () =>
document.documentElement.setAttribute("data-accent", themeColor.value)
)
watch(bgColor, () => ($colorMode.preference = bgColor.value))
watch(fontSize, () =>
document.documentElement.setAttribute("data-font-size", fontSize.value)
)
}
function defineJumpActions() {
const router = useRouter()
defineActionHandler("navigation.jump.rest", () => {
router.push({ path: "/" })
})
defineActionHandler("navigation.jump.graphql", () => {
router.push({ path: "/graphql" })
})
defineActionHandler("navigation.jump.realtime", () => {
router.push({ path: "/realtime" })
})
defineActionHandler("navigation.jump.documentation", () => {
router.push({ path: "/documentation" })
})
defineActionHandler("navigation.jump.settings", () => {
router.push({ path: "/settings" })
})
defineActionHandler("navigation.jump.back", () => {
router.go(-1)
})
defineActionHandler("navigation.jump.forward", () => {
router.go(1)
})
}
export default defineComponent({
2021-07-01 16:39:11 +00:00
components: { Splitpanes, Pane },
setup() {
hookKeybindingsListener()
2021-08-12 08:14:10 +00:00
defineJumpActions()
2021-08-12 08:14:10 +00:00
updateThemes()
2021-08-12 08:14:10 +00:00
2021-07-01 16:39:11 +00:00
return {
2021-08-12 08:14:10 +00:00
LEFT_SIDEBAR: useSetting("LEFT_SIDEBAR"),
ZEN_MODE: useSetting("ZEN_MODE"),
}
},
2021-08-12 08:14:10 +00:00
data() {
return {
2021-08-12 08:14:10 +00:00
windowInnerWidth: 0,
2021-07-01 16:39:11 +00:00
}
},
2021-07-05 12:56:00 +00:00
watch: {
2021-07-09 03:39:07 +00:00
$route(to) {
logPageView(to.fullPath)
},
2021-07-05 12:56:00 +00:00
},
2019-11-12 04:18:57 +00:00
beforeMount() {
2021-07-15 02:29:11 +00:00
setupLocalPersistence()
registerApolloAuthUpdate()
2019-11-12 04:18:57 +00:00
},
async mounted() {
2021-08-05 15:59:05 +00:00
window.addEventListener("resize", this.handleResize)
this.handleResize()
performMigrations()
console.log(
"%cWe ❤︎ open source!",
"background-color:white;padding:8px 16px;border-radius:8px;font-size:32px;color:red;"
2020-02-24 18:44:50 +00:00
)
console.log(
2020-08-13 11:20:02 +00:00
"%cContribute: https://github.com/hoppscotch/hoppscotch",
"background-color:black;padding:4px 8px;border-radius:8px;font-size:16px;color:white;"
2020-02-24 18:44:50 +00:00
)
2021-07-24 21:45:48 +00:00
const workbox = await (window as any).$workbox
if (workbox) {
2021-07-24 10:58:32 +00:00
workbox.addEventListener("installed", (event: any) => {
if (event.isUpdate) {
2021-08-02 15:27:18 +00:00
this.$toast.show(this.$t("app.new_version_found").toString(), {
icon: "info",
duration: 0,
action: [
{
2021-07-06 12:20:37 +00:00
text: this.$t("reload").toString(),
2021-05-18 06:26:59 +00:00
onClick: (_, toastObject) => {
toastObject.goAway(0)
2021-05-18 16:09:55 +00:00
window.location.reload()
},
},
],
})
}
})
}
2021-06-14 04:07:30 +00:00
initializeFirebase()
2021-05-14 00:16:10 +00:00
initUserInfo()
2021-07-09 03:39:07 +00:00
logPageView(this.$router.currentRoute.fullPath)
2019-11-12 04:18:57 +00:00
},
2021-08-05 15:59:05 +00:00
destroyed() {
window.removeEventListener("resize", this.handleResize)
},
methods: {
handleResize() {
this.windowInnerWidth = window.innerWidth
},
},
})
2019-08-24 03:06:57 +00:00
</script>