refactor: composables for breakpoints

This commit is contained in:
liyasthomas
2022-02-01 13:20:40 +05:30
parent 98b01b016d
commit aaecba043b
11 changed files with 72 additions and 73 deletions

View File

@@ -5,7 +5,7 @@
> >
<div class="inline-flex items-center space-x-2"> <div class="inline-flex items-center space-x-2">
<ButtonSecondary <ButtonSecondary
class="tracking-wide !font-bold !text-secondaryDark hover:bg-primaryDark focus-visible:bg-primaryDark" class="tracking-wide !font-bold !text-secondaryDark hover:bg-primaryDark focus-visible:bg-primaryDark uppercase"
:label="t('app.name')" :label="t('app.name')"
to="/" to="/"
/> />

View File

@@ -14,7 +14,7 @@
<span v-if="EXPAND_NAVIGATION">{{ navigation.title }}</span> <span v-if="EXPAND_NAVIGATION">{{ navigation.title }}</span>
<tippy <tippy
v-if="!EXPAND_NAVIGATION" v-if="!EXPAND_NAVIGATION"
:placement="windowInnerWidth.x.value >= 768 ? 'right' : 'bottom'" :placement="mdAndLarger ? 'right' : 'bottom'"
theme="tooltip" theme="tooltip"
:content="navigation.title" :content="navigation.title"
/> />
@@ -24,13 +24,15 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import useWindowSize from "~/helpers/utils/useWindowSize" import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
import { useSetting } from "~/newstore/settings" import { useSetting } from "~/newstore/settings"
import { useI18n } from "~/helpers/utils/composables" import { useI18n } from "~/helpers/utils/composables"
const t = useI18n() const t = useI18n()
const windowInnerWidth = useWindowSize() const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
const EXPAND_NAVIGATION = useSetting("EXPAND_NAVIGATION") const EXPAND_NAVIGATION = useSetting("EXPAND_NAVIGATION")
const primaryNavigation = [ const primaryNavigation = [

View File

@@ -125,11 +125,7 @@
</span> </span>
<ButtonSecondary <ButtonSecondary
class="ml-2 rounded rounded-r-none" class="ml-2 rounded rounded-r-none"
:label=" :label="mdAndLarger && COLUMN_LAYOUT ? `${t('request.save')}` : ''"
windowInnerWidth.x.value >= 768 && COLUMN_LAYOUT
? `${t('request.save')}`
: ''
"
filled filled
svg="save" svg="save"
@click.native="saveRequest()" @click.native="saveRequest()"
@@ -217,6 +213,7 @@
import { computed, ref, watch } from "@nuxtjs/composition-api" import { computed, ref, watch } from "@nuxtjs/composition-api"
import { isLeft, isRight } from "fp-ts/lib/Either" import { isLeft, isRight } from "fp-ts/lib/Either"
import * as E from "fp-ts/Either" import * as E from "fp-ts/Either"
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
import { import {
updateRESTResponse, updateRESTResponse,
restEndpoint$, restEndpoint$,
@@ -245,7 +242,6 @@ import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useSetting } from "~/newstore/settings" import { useSetting } from "~/newstore/settings"
import { overwriteRequestTeams } from "~/helpers/teams/utils" import { overwriteRequestTeams } from "~/helpers/teams/utils"
import { apolloClient } from "~/helpers/apollo" import { apolloClient } from "~/helpers/apollo"
import useWindowSize from "~/helpers/utils/useWindowSize"
import { createShortcode } from "~/helpers/backend/mutations/Shortcode" import { createShortcode } from "~/helpers/backend/mutations/Shortcode"
const t = useI18n() const t = useI18n()
@@ -555,6 +551,8 @@ const isCustomMethod = computed(() => {
const requestName = useRESTRequestName() const requestName = useRESTRequestName()
const windowInnerWidth = useWindowSize()
const COLUMN_LAYOUT = useSetting("COLUMN_LAYOUT") const COLUMN_LAYOUT = useSetting("COLUMN_LAYOUT")
const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
</script> </script>

View File

@@ -1,11 +1,11 @@
<template> <template>
<Splitpanes <Splitpanes
class="smart-splitter" class="smart-splitter"
:rtl="SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768" :rtl="SIDEBAR_ON_LEFT && mdAndLarger"
:class="{ :class="{
'!flex-row-reverse': SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768, '!flex-row-reverse': SIDEBAR_ON_LEFT && mdAndLarger,
}" }"
:horizontal="!(windowInnerWidth.x.value >= 768)" :horizontal="!mdAndLarger"
> >
<Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto"> <Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto">
<Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT"> <Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT">
@@ -148,9 +148,9 @@ import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css" import "splitpanes/dist/splitpanes.css"
import Paho from "paho-mqtt" import Paho from "paho-mqtt"
import debounce from "lodash/debounce" import debounce from "lodash/debounce"
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics" import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
import { useSetting } from "~/newstore/settings" import { useSetting } from "~/newstore/settings"
import useWindowSize from "~/helpers/utils/useWindowSize"
import { import {
MQTTEndpoint$, MQTTEndpoint$,
setMQTTEndpoint, setMQTTEndpoint,
@@ -171,8 +171,11 @@ import { useStream } from "~/helpers/utils/composables"
export default defineComponent({ export default defineComponent({
components: { Splitpanes, Pane }, components: { Splitpanes, Pane },
setup() { setup() {
const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
return { return {
windowInnerWidth: useWindowSize(), mdAndLarger,
SIDEBAR: useSetting("SIDEBAR"), SIDEBAR: useSetting("SIDEBAR"),
COLUMN_LAYOUT: useSetting("COLUMN_LAYOUT"), COLUMN_LAYOUT: useSetting("COLUMN_LAYOUT"),
SIDEBAR_ON_LEFT: useSetting("SIDEBAR_ON_LEFT"), SIDEBAR_ON_LEFT: useSetting("SIDEBAR_ON_LEFT"),

View File

@@ -1,11 +1,11 @@
<template> <template>
<Splitpanes <Splitpanes
class="smart-splitter" class="smart-splitter"
:rtl="SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768" :rtl="SIDEBAR_ON_LEFT && mdAndLarger"
:class="{ :class="{
'!flex-row-reverse': SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768, '!flex-row-reverse': SIDEBAR_ON_LEFT && mdAndLarger,
}" }"
:horizontal="!(windowInnerWidth.x.value >= 768)" :horizontal="!mdAndLarger"
> >
<Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto"> <Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto">
<Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT"> <Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT">
@@ -306,9 +306,9 @@ import { io as ClientV4 } from "socket.io-client-v4"
import wildcard from "socketio-wildcard" import wildcard from "socketio-wildcard"
import debounce from "lodash/debounce" import debounce from "lodash/debounce"
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics" import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
import { useSetting } from "~/newstore/settings" import { useSetting } from "~/newstore/settings"
import useWindowSize from "~/helpers/utils/useWindowSize"
import { import {
SIOEndpoint$, SIOEndpoint$,
setSIOEndpoint, setSIOEndpoint,
@@ -337,8 +337,11 @@ const socketIoClients = {
export default defineComponent({ export default defineComponent({
components: { Splitpanes, Pane }, components: { Splitpanes, Pane },
setup() { setup() {
const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
return { return {
windowInnerWidth: useWindowSize(), mdAndLarger,
SIDEBAR: useSetting("SIDEBAR"), SIDEBAR: useSetting("SIDEBAR"),
COLUMN_LAYOUT: useSetting("COLUMN_LAYOUT"), COLUMN_LAYOUT: useSetting("COLUMN_LAYOUT"),
SIDEBAR_ON_LEFT: useSetting("SIDEBAR_ON_LEFT"), SIDEBAR_ON_LEFT: useSetting("SIDEBAR_ON_LEFT"),

View File

@@ -1,11 +1,11 @@
<template> <template>
<Splitpanes <Splitpanes
class="smart-splitter" class="smart-splitter"
:rtl="SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768" :rtl="SIDEBAR_ON_LEFT && mdAndLarger"
:class="{ :class="{
'!flex-row-reverse': SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768, '!flex-row-reverse': SIDEBAR_ON_LEFT && mdAndLarger,
}" }"
:horizontal="!(windowInnerWidth.x.value >= 768)" :horizontal="!mdAndLarger"
> >
<Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto"> <Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto">
<Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT"> <Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT">
@@ -186,8 +186,8 @@ import { defineComponent } from "@nuxtjs/composition-api"
import { Splitpanes, Pane } from "splitpanes" import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css" import "splitpanes/dist/splitpanes.css"
import debounce from "lodash/debounce" import debounce from "lodash/debounce"
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics" import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
import useWindowSize from "~/helpers/utils/useWindowSize"
import { useSetting } from "~/newstore/settings" import { useSetting } from "~/newstore/settings"
import { import {
setWSEndpoint, setWSEndpoint,
@@ -213,8 +213,11 @@ import { useStream } from "~/helpers/utils/composables"
export default defineComponent({ export default defineComponent({
components: { Splitpanes, Pane }, components: { Splitpanes, Pane },
setup() { setup() {
const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
return { return {
windowInnerWidth: useWindowSize(), mdAndLarger,
SIDEBAR: useSetting("SIDEBAR"), SIDEBAR: useSetting("SIDEBAR"),
COLUMN_LAYOUT: useSetting("COLUMN_LAYOUT"), COLUMN_LAYOUT: useSetting("COLUMN_LAYOUT"),
SIDEBAR_ON_LEFT: useSetting("SIDEBAR_ON_LEFT"), SIDEBAR_ON_LEFT: useSetting("SIDEBAR_ON_LEFT"),

View File

@@ -1,25 +0,0 @@
import {
Ref,
onMounted,
onUnmounted,
reactive,
toRefs,
} from "@nuxtjs/composition-api"
interface WindowSize {
x: Ref<number>
y: Ref<number>
}
export function useWindowSize(): WindowSize {
const windowSize = reactive({ x: 0, y: 0 })
const resizeListener = () => {
;({ innerWidth: windowSize.x, innerHeight: windowSize.y } = window)
}
onMounted(() => window.addEventListener("resize", resizeListener))
onUnmounted(() => window.removeEventListener("resize", resizeListener))
resizeListener()
return toRefs(windowSize)
}
export default useWindowSize

View File

@@ -8,7 +8,7 @@
<Splitpanes <Splitpanes
class="no-splitter" class="no-splitter"
:dbl-click-splitter="false" :dbl-click-splitter="false"
:horizontal="!(windowInnerWidth.x.value >= 768)" :horizontal="!mdAndLarger"
> >
<Pane <Pane
style="width: auto; height: auto" style="width: auto; height: auto"
@@ -48,6 +48,7 @@ import {
} from "@nuxtjs/composition-api" } from "@nuxtjs/composition-api"
import { Splitpanes, Pane } from "splitpanes" import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css" import "splitpanes/dist/splitpanes.css"
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
import { setupLocalPersistence } from "~/newstore/localpersistence" import { setupLocalPersistence } from "~/newstore/localpersistence"
import { performMigrations } from "~/helpers/migrations" import { performMigrations } from "~/helpers/migrations"
import { initUserInfo } from "~/helpers/teams/BackendUserInfo" import { initUserInfo } from "~/helpers/teams/BackendUserInfo"
@@ -56,26 +57,27 @@ import { applySetting, useSetting } from "~/newstore/settings"
import { logPageView } from "~/helpers/fb/analytics" import { logPageView } from "~/helpers/fb/analytics"
import { hookKeybindingsListener } from "~/helpers/keybindings" import { hookKeybindingsListener } from "~/helpers/keybindings"
import { defineActionHandler } from "~/helpers/actions" import { defineActionHandler } from "~/helpers/actions"
import useWindowSize from "~/helpers/utils/useWindowSize"
import { useSentry } from "~/helpers/sentry" import { useSentry } from "~/helpers/sentry"
import { useColorMode } from "~/helpers/utils/composables" import { useColorMode } from "~/helpers/utils/composables"
function appLayout() { function appLayout() {
const rightSidebar = useSetting("SIDEBAR") const rightSidebar = useSetting("SIDEBAR")
const columnLayout = useSetting("COLUMN_LAYOUT") const columnLayout = useSetting("COLUMN_LAYOUT")
const windowInnerWidth = useWindowSize()
const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
// Initially apply // Initially apply
onBeforeMount(() => { onBeforeMount(() => {
if (windowInnerWidth.x.value < 768) { if (mdAndLarger.value) {
rightSidebar.value = false rightSidebar.value = false
columnLayout.value = true columnLayout.value = true
} }
}) })
// Listen for updates // Listen for updates
watch(windowInnerWidth.x, () => { watch(mdAndLarger, () => {
if (windowInnerWidth.x.value < 768) { if (!mdAndLarger.value) {
rightSidebar.value = false rightSidebar.value = false
columnLayout.value = true columnLayout.value = true
} }
@@ -172,8 +174,12 @@ export default defineComponent({
updateThemes() updateThemes()
setupSentry() setupSentry()
const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
return { return {
windowInnerWidth: useWindowSize(), mdAndLarger,
ZEN_MODE: useSetting("ZEN_MODE"), ZEN_MODE: useSetting("ZEN_MODE"),
} }
}, },

View File

@@ -1,11 +1,11 @@
<template> <template>
<Splitpanes <Splitpanes
class="smart-splitter" class="smart-splitter"
:rtl="SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768" :rtl="SIDEBAR_ON_LEFT && mdAndLarger"
:class="{ :class="{
'!flex-row-reverse': SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768, '!flex-row-reverse': SIDEBAR_ON_LEFT && mdAndLarger,
}" }"
:horizontal="!(windowInnerWidth.x.value >= 768)" :horizontal="!mdAndLarger"
> >
<Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto"> <Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto">
<Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT"> <Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT">
@@ -140,19 +140,22 @@ import { defineComponent } from "@nuxtjs/composition-api"
import { Splitpanes, Pane } from "splitpanes" import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css" import "splitpanes/dist/splitpanes.css"
import Mustache from "mustache" import Mustache from "mustache"
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
import { currentUser$ } from "~/helpers/fb/auth" import { currentUser$ } from "~/helpers/fb/auth"
import DocsTemplate from "~/assets/md/docs.md" import DocsTemplate from "~/assets/md/docs.md"
import folderContents from "~/assets/md/folderContents.md" import folderContents from "~/assets/md/folderContents.md"
import folderBody from "~/assets/md/folderBody.md" import folderBody from "~/assets/md/folderBody.md"
import { useSetting } from "~/newstore/settings" import { useSetting } from "~/newstore/settings"
import { useReadonlyStream } from "~/helpers/utils/composables" import { useReadonlyStream } from "~/helpers/utils/composables"
import useWindowSize from "~/helpers/utils/useWindowSize"
export default defineComponent({ export default defineComponent({
components: { Splitpanes, Pane }, components: { Splitpanes, Pane },
setup() { setup() {
const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
return { return {
windowInnerWidth: useWindowSize(), mdAndLarger,
SIDEBAR: useSetting("SIDEBAR"), SIDEBAR: useSetting("SIDEBAR"),
COLUMN_LAYOUT: useSetting("COLUMN_LAYOUT"), COLUMN_LAYOUT: useSetting("COLUMN_LAYOUT"),
currentUser: useReadonlyStream(currentUser$, null), currentUser: useReadonlyStream(currentUser$, null),

View File

@@ -1,11 +1,11 @@
<template> <template>
<Splitpanes <Splitpanes
class="smart-splitter" class="smart-splitter"
:rtl="SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768" :rtl="SIDEBAR_ON_LEFT && mdAndLarger"
:class="{ :class="{
'!flex-row-reverse': SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768, '!flex-row-reverse': SIDEBAR_ON_LEFT && mdAndLarger,
}" }"
:horizontal="!(windowInnerWidth.x.value >= 768)" :horizontal="!mdAndLarger"
> >
<Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto"> <Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto">
<Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT"> <Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT">
@@ -39,10 +39,10 @@
import { defineComponent, watch } from "@nuxtjs/composition-api" import { defineComponent, watch } from "@nuxtjs/composition-api"
import { Splitpanes, Pane } from "splitpanes" import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css" import "splitpanes/dist/splitpanes.css"
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
import { useSetting } from "~/newstore/settings" import { useSetting } from "~/newstore/settings"
import { GQLConnection } from "~/helpers/GQLConnection" import { GQLConnection } from "~/helpers/GQLConnection"
import { useNuxt, useReadonlyStream } from "~/helpers/utils/composables" import { useNuxt, useReadonlyStream } from "~/helpers/utils/composables"
import useWindowSize from "~/helpers/utils/useWindowSize"
export default defineComponent({ export default defineComponent({
components: { Splitpanes, Pane }, components: { Splitpanes, Pane },
@@ -64,8 +64,11 @@ export default defineComponent({
else nuxt.value.$loading.finish() else nuxt.value.$loading.finish()
}) })
const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
return { return {
windowInnerWidth: useWindowSize(), mdAndLarger,
SIDEBAR: useSetting("SIDEBAR"), SIDEBAR: useSetting("SIDEBAR"),
COLUMN_LAYOUT: useSetting("COLUMN_LAYOUT"), COLUMN_LAYOUT: useSetting("COLUMN_LAYOUT"),
SIDEBAR_ON_LEFT: useSetting("SIDEBAR_ON_LEFT"), SIDEBAR_ON_LEFT: useSetting("SIDEBAR_ON_LEFT"),

View File

@@ -1,11 +1,11 @@
<template> <template>
<Splitpanes <Splitpanes
class="smart-splitter" class="smart-splitter"
:rtl="SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768" :rtl="SIDEBAR_ON_LEFT && mdAndLarger"
:class="{ :class="{
'!flex-row-reverse': SIDEBAR_ON_LEFT && windowInnerWidth.x.value >= 768, '!flex-row-reverse': SIDEBAR_ON_LEFT && mdAndLarger,
}" }"
:horizontal="!(windowInnerWidth.x.value >= 768)" :horizontal="!mdAndLarger"
> >
<Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto"> <Pane size="75" min-size="65" class="hide-scrollbar !overflow-auto">
<Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT"> <Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT">
@@ -127,6 +127,7 @@ import {
HoppRESTAuthOAuth2, HoppRESTAuthOAuth2,
safelyExtractRESTRequest, safelyExtractRESTRequest,
} from "@hoppscotch/data" } from "@hoppscotch/data"
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
import { useSetting } from "~/newstore/settings" import { useSetting } from "~/newstore/settings"
import { import {
restActiveParamsCount$, restActiveParamsCount$,
@@ -150,7 +151,6 @@ import {
import { loadRequestFromSync, startRequestSync } from "~/helpers/fb/request" import { loadRequestFromSync, startRequestSync } from "~/helpers/fb/request"
import { onLoggedIn } from "~/helpers/fb/auth" import { onLoggedIn } from "~/helpers/fb/auth"
import { oauthRedirect } from "~/helpers/oauth" import { oauthRedirect } from "~/helpers/oauth"
import useWindowSize from "~/helpers/utils/useWindowSize"
function bindRequestToURLParams() { function bindRequestToURLParams() {
const { route } = useContext() const { route } = useContext()
@@ -267,8 +267,11 @@ export default defineComponent({
setupRequestSync(confirmSync, requestForSync) setupRequestSync(confirmSync, requestForSync)
bindRequestToURLParams() bindRequestToURLParams()
const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
return { return {
windowInnerWidth: useWindowSize(), mdAndLarger,
newActiveParamsCount$: useReadonlyStream( newActiveParamsCount$: useReadonlyStream(
restActiveParamsCount$.pipe( restActiveParamsCount$.pipe(
map((e) => { map((e) => {