feat: realtime tabs as subpages (#2450)

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
Anwarul Islam
2022-06-28 15:42:47 +06:00
committed by GitHub
parent ca553b9d3c
commit 07a8a37739
8 changed files with 299 additions and 237 deletions

View File

@@ -7,6 +7,7 @@
:to="localePath(navigation.target)" :to="localePath(navigation.target)"
class="nav-link" class="nav-link"
tabindex="0" tabindex="0"
:exact="navigation.exact"
> >
<div v-if="navigation.svg"> <div v-if="navigation.svg">
<SmartIcon :name="navigation.svg" class="svg-icons" /> <SmartIcon :name="navigation.svg" class="svg-icons" />
@@ -40,26 +41,31 @@ const primaryNavigation = [
target: "index", target: "index",
svg: "link-2", svg: "link-2",
title: t("navigation.rest"), title: t("navigation.rest"),
exact: true,
}, },
{ {
target: "graphql", target: "graphql",
svg: "graphql", svg: "graphql",
title: t("navigation.graphql"), title: t("navigation.graphql"),
exact: false,
}, },
{ {
target: "realtime", target: "realtime",
svg: "globe", svg: "globe",
title: t("navigation.realtime"), title: t("navigation.realtime"),
exact: false,
}, },
{ {
target: "documentation", target: "documentation",
svg: "book-open", svg: "book-open",
title: t("navigation.doc"), title: t("navigation.doc"),
exact: false,
}, },
{ {
target: "settings", target: "settings",
svg: "settings", svg: "settings",
title: t("navigation.settings"), title: t("navigation.settings"),
exact: false,
}, },
] ]
</script> </script>
@@ -105,6 +111,20 @@ const primaryNavigation = [
@apply text-tiny; @apply text-tiny;
} }
&.active-link {
@apply text-secondaryDark;
@apply bg-primaryLight;
@apply hover:text-secondaryDark;
.material-icons,
.svg-icons {
@apply opacity-100;
}
&::after {
@apply bg-accent;
}
}
&.exact-active-link { &.exact-active-link {
@apply text-secondaryDark; @apply text-secondaryDark;
@apply bg-primaryLight; @apply bg-primaryLight;

View File

@@ -15,7 +15,10 @@
<span class="text-secondaryDark pl-2 break-all"> <span class="text-secondaryDark pl-2 break-all">
{{ ` \xA0 — \xA0 ${env.value}` }} {{ ` \xA0 — \xA0 ${env.value}` }}
</span> </span>
<span v-if="status === 'updations'" class="text-secondaryLight px-2 break-all"> <span
v-if="status === 'updations'"
class="text-secondaryLight px-2 break-all"
>
{{ ` \xA0 ← \xA0 ${env.previousValue}` }} {{ ` \xA0 ← \xA0 ${env.previousValue}` }}
</span> </span>
</div> </div>

View File

@@ -1,53 +1,67 @@
<template> <template>
<SmartTabs <SmartTabs v-model="currentTab">
v-model="selectedNavigationTab"
class="h-full !overflow-hidden"
styles="sticky bg-primary top-0 z-10 border-b border-dividerLight !overflow-visible"
>
<SmartTab <SmartTab
id="websocket" v-for="{ target, title } in REALTIME_NAVIGATION"
:label="$t('tab.websocket')" :id="target"
style="height: calc(100% - var(--sidebar-primary-sticky-fold))" :key="target"
:label="title"
> >
<RealtimeWebsocket /> <NuxtChild />
</SmartTab>
<SmartTab
id="sse"
:label="$t('tab.sse')"
style="height: calc(100% - var(--sidebar-primary-sticky-fold))"
>
<RealtimeSse />
</SmartTab>
<SmartTab
id="socketio"
:label="$t('tab.socketio')"
style="height: calc(100% - var(--sidebar-primary-sticky-fold))"
>
<RealtimeSocketio />
</SmartTab>
<SmartTab
id="mqtt"
:label="$t('tab.mqtt')"
style="height: calc(100% - var(--sidebar-primary-sticky-fold))"
>
<RealtimeMqtt />
</SmartTab> </SmartTab>
</SmartTabs> </SmartTabs>
</template> </template>
<script> <script setup lang="ts">
import { defineComponent } from "@nuxtjs/composition-api" import { watch, ref, useRouter, useRoute } from "@nuxtjs/composition-api"
import { useI18n } from "~/helpers/utils/composables"
export default defineComponent({ const t = useI18n()
data() { const router = useRouter()
return { const route = useRoute()
selectedNavigationTab: "websocket",
} const REALTIME_NAVIGATION = [
{
target: "websocket",
title: t("tab.websocket"),
}, },
head() { {
return { target: "sse",
title: `${this.$t("navigation.realtime")} • Hoppscotch`, title: t("tab.sse"),
}
}, },
{
target: "socketio",
title: t("tab.socketio"),
},
{
target: "mqtt",
title: t("tab.mqtt"),
},
] as const
type RealtimeNavTab = typeof REALTIME_NAVIGATION[number]["target"]
const currentTab = ref<RealtimeNavTab>("websocket")
// Update the router when the tab is updated
watch(currentTab, (newTab) => {
router.push(`/realtime/${newTab}`)
}) })
// Update the tab when router is upgrad
watch(
route,
(updateRoute) => {
if (updateRoute.path === "/realtime") router.replace("/realtime/websocket")
const destination: string | undefined =
updateRoute.path.split("/realtime/")[1]
const target = REALTIME_NAVIGATION.find(
({ target }) => target === destination
)?.target
if (target) currentTab.value = target
},
{ immediate: true }
)
</script> </script>

415
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff