From 2e1ca0cbb0ee77d459d22e2abd0b6a3fce669ece Mon Sep 17 00:00:00 2001 From: Sagar Date: Wed, 10 Aug 2022 05:41:03 +0600 Subject: [PATCH] feat: remember pane sizes (#2556) Co-authored-by: Sagar --- .../components/app/PaneLayout.vue | 74 +++++++++++++++++-- .../hoppscotch-app/pages/documentation.vue | 2 +- packages/hoppscotch-app/pages/graphql.vue | 2 +- packages/hoppscotch-app/pages/index.vue | 2 +- .../hoppscotch-app/pages/realtime/mqtt.vue | 2 +- .../pages/realtime/socketio.vue | 2 +- .../hoppscotch-app/pages/realtime/sse.vue | 2 +- .../pages/realtime/websocket.vue | 2 +- 8 files changed, 75 insertions(+), 13 deletions(-) diff --git a/packages/hoppscotch-app/components/app/PaneLayout.vue b/packages/hoppscotch-app/components/app/PaneLayout.vue index e5b0f7079..7064db7f3 100644 --- a/packages/hoppscotch-app/components/app/PaneLayout.vue +++ b/packages/hoppscotch-app/components/app/PaneLayout.vue @@ -6,21 +6,26 @@ '!flex-row-reverse': SIDEBAR_ON_LEFT && mdAndLarger, }" :horizontal="!mdAndLarger" + @resize="setPaneEvent($event, 'vertical')" > - + @@ -29,7 +34,7 @@ @@ -42,8 +47,9 @@ import { Splitpanes, Pane } from "splitpanes" import "splitpanes/dist/splitpanes.css" import { breakpointsTailwind, useBreakpoints } from "@vueuse/core" -import { computed, useSlots } from "@nuxtjs/composition-api" +import { computed, useSlots, ref } from "@nuxtjs/composition-api" import { useSetting } from "~/newstore/settings" +import { setLocalConfig, getLocalConfig } from "~/newstore/localpersistence" const SIDEBAR_ON_LEFT = useSetting("SIDEBAR_ON_LEFT") @@ -57,4 +63,60 @@ const SIDEBAR = useSetting("SIDEBAR") const slots = useSlots() const hasSidebar = computed(() => !!slots.sidebar) + +const props = defineProps({ + layoutId: { + type: String, + default: null, + }, +}) + +type PaneEvent = { + max: number + min: number + size: number +} + +const PANE_SIDEBAR_SIZE = ref(25) +const PANE_MAIN_SIZE = ref(75) +const PANE_MAIN_TOP_SIZE = ref(45) +const PANE_MAIN_BOTTOM_SIZE = ref(65) + +if (!COLUMN_LAYOUT.value) { + PANE_MAIN_TOP_SIZE.value = 50 + PANE_MAIN_BOTTOM_SIZE.value = 50 +} + +function setPaneEvent(event: PaneEvent[], type: "vertical" | "horizontal") { + if (!props.layoutId) return + const storageKey = `${props.layoutId}-pane-config-${type}` + setLocalConfig(storageKey, JSON.stringify(event)) +} + +function populatePaneEvent() { + if (!props.layoutId) return + + const verticalPaneData = getPaneData("vertical") + if (verticalPaneData) { + const [mainPane, sidebarPane] = verticalPaneData + PANE_MAIN_SIZE.value = mainPane?.size + PANE_SIDEBAR_SIZE.value = sidebarPane?.size + } + + const horizontalPaneData = getPaneData("horizontal") + if (horizontalPaneData) { + const [mainTopPane, mainBottomPane] = horizontalPaneData + PANE_MAIN_TOP_SIZE.value = mainTopPane?.size + PANE_MAIN_BOTTOM_SIZE.value = mainBottomPane?.size + } +} + +function getPaneData(type: "vertical" | "horizontal"): PaneEvent[] | null { + const storageKey = `${props.layoutId}-pane-config-${type}` + const paneEvent = getLocalConfig(storageKey) + if (!paneEvent) return null + return JSON.parse(paneEvent) +} + +populatePaneEvent() diff --git a/packages/hoppscotch-app/pages/documentation.vue b/packages/hoppscotch-app/pages/documentation.vue index 8143c3bb5..a5b807a13 100644 --- a/packages/hoppscotch-app/pages/documentation.vue +++ b/packages/hoppscotch-app/pages/documentation.vue @@ -1,5 +1,5 @@