simplify code

This commit is contained in:
2022-12-20 16:02:57 +01:00
parent 071d1f9788
commit bd15f631f9
3 changed files with 51 additions and 60 deletions

View File

@@ -1,9 +1,9 @@
<template>
<div id="app">
<NavBar :activeType="type" @set-type="setType"></NavBar>
<NavBar :activeType="activeType" @set-type="setType"></NavBar>
<section class="section">
<TimeWindows :activeWindow="window" @set-window="setWindow"></TimeWindows>
<Chart :window="window" :type="type"></Chart>
<TimeWindows :windows="windows" :active-window="activeWindow" @set-window="setWindow"></TimeWindows>
<Chart :active-window="activeWindow" :active-type="activeType"></Chart>
</section>
<router-view></router-view>
</div>
@@ -17,31 +17,37 @@ import Chart from '@/components/Chart.vue'
import { windows } from '@/utils/helpers'
import type { Window } from '@/utils/types'
const type = ref<string>('')
const window = ref<Window | undefined>(undefined)
const defaultWindow = windows[1]
const activeType = ref<string>('')
const activeWindow = ref<Window>(defaultWindow)
const router = useRouter()
const currentRoute = useRoute()
if (currentRoute.params.type) type.value = currentRoute.params.type as string
if (currentRoute.params.window) window.value = windows.find((w) => w.label === currentRoute.params.window)
if (currentRoute.params.type) activeType.value = currentRoute.params.type as string
if (currentRoute.params.window) {
activeWindow.value = windows.find((w) => w.label === currentRoute.params.window) || defaultWindow
}
const updateRoute = () => {
if (type.value) {
if (activeType.value) {
const route = {
name: 'view',
params: {
type: type.value,
window: window.value?.label.replace(' ', '-')
type: activeType.value,
window: activeWindow.value?.label.replace(' ', '-')
}
}
router.push(route)
}
}
const setType = (newType: string) => {
type.value = newType
activeType.value = newType
updateRoute()
}
const setWindow = (newWindow: Window) => {
window.value = newWindow
activeWindow.value = newWindow
updateRoute()
}
</script>