feat: add reporting workflow and optimize dashboard loading
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, shallowRef } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, shallowRef, watch } from 'vue'
|
||||
|
||||
import AppHero from './components/AppHero.vue'
|
||||
import HomeControlScreen from './components/HomeControlScreen.vue'
|
||||
@ -33,12 +33,25 @@ function syncPageFromHash() {
|
||||
currentPage.value = pageFromHash()
|
||||
}
|
||||
|
||||
async function ensurePageData(page: PageKey) {
|
||||
if (dashboard.isBooting.value) return
|
||||
|
||||
if (page === 'trader' && dashboard.selectedTraderId.value !== null) {
|
||||
await dashboard.selectTrader(dashboard.selectedTraderId.value)
|
||||
}
|
||||
|
||||
if (page === 'stock' && dashboard.selectedStockCode.value) {
|
||||
await dashboard.selectStock(dashboard.selectedStockCode.value)
|
||||
}
|
||||
}
|
||||
|
||||
function navigate(page: PageKey) {
|
||||
const nextHash = `#/${page}`
|
||||
if (window.location.hash !== nextHash) {
|
||||
window.location.hash = nextHash
|
||||
}
|
||||
currentPage.value = page
|
||||
void ensurePageData(page)
|
||||
}
|
||||
|
||||
async function handleSelectTrader(traderId: number) {
|
||||
@ -84,12 +97,19 @@ async function handleUnfollowStock(stockCode: string) {
|
||||
onMounted(() => {
|
||||
syncPageFromHash()
|
||||
window.addEventListener('hashchange', syncPageFromHash)
|
||||
void dashboard.initialize()
|
||||
void (async () => {
|
||||
await dashboard.initialize()
|
||||
await ensurePageData(currentPage.value)
|
||||
})()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('hashchange', syncPageFromHash)
|
||||
})
|
||||
|
||||
watch(currentPage, (page) => {
|
||||
void ensurePageData(page)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user