11<script setup lang="ts">
2- import type { BcHeaderMegaMenu } from ' #build/components'
3- import { useLatestStateStore } from ' ~/stores/useLatestStateStore'
2+ import type { BcNavigationMenu } from ' #build/components'
43import {
54 mobileHeaderThreshold , smallHeaderThreshold ,
65} from ' ~/types/header'
76
8- defineProps <{
9- isHomePage: boolean ,
10- minimalist: boolean ,
11- }>()
12- const latestStateStore = useLatestStateStore ()
13- const { latestState } = storeToRefs (latestStateStore )
147const {
158 getEpochFromSlot,
169 networkInfo,
10+ secondsPerSlot,
1711} = useNetwork ()
12+
13+ const { counter } = useInterval (secondsPerSlot )
14+
15+ // Todo: decide if this is an antipattern or we should rather use watcher with callOnce
16+ useApi (' /api/latest-state' , {
17+ immediate: true ,
18+ watch: [ counter ],
19+ })
1820const {
19- doLogout,
20- isLoggedIn,
21- } = useUserStore ()
21+ data : userData,
22+ } = await useApi (' /api/users/me' , {
23+ key: ' user' ,
24+ })
25+
26+ const {
27+ logout,
28+ } = useUser ()
29+
2230const {
2331 displayCurrencyDefault,
2432 exchangeRates,
@@ -32,12 +40,13 @@ const { promoCode } = usePromoCode()
3240const isSmallScreen = computed (() => width .value < smallHeaderThreshold )
3341const isMobileScreen = computed (() => width .value < mobileHeaderThreshold )
3442
35- const showInDevelopment = Boolean (useRuntimeConfig ().public .showInDevelopment )
43+ const config = useRuntimeConfig ()
44+ const showInDevelopment = Boolean (config .public .showInDevelopment )
3645const hideInDevelopmentClass = showInDevelopment
3746 ? ' '
3847 : ' hide-because-it-is-unfinished' // TODO: once the searchbar is enabled in production, delete this line
3948
40- const megaMenu = ref <null | typeof BcHeaderMegaMenu >(null )
49+ const megaMenu = ref <null | typeof BcNavigationMenu >(null )
4150
4251const hasExchangeRates = computed (() => exchangeRates .value .length > 1 )
4352
@@ -55,11 +64,8 @@ const currentRate = computed(() => {
5564 })
5665})
5766
58- const currentEpoch = computed (() =>
59- latestState .value ?.current_slot !== undefined
60- ? getEpochFromSlot (latestState .value .current_slot )
61- : undefined ,
62- )
67+ const currentSlot = useCurrentSlot ()
68+ const currentEpoch = computed (() => getEpochFromSlot (currentSlot .value ))
6369
6470const toggleMegaMenu = (evt : Event ) => {
6571 megaMenu .value ?.toggleMegaMenu (evt )
@@ -70,55 +76,45 @@ const isMobileMegaMenuOpen = computed(() => megaMenu.value?.isMobileMenuOpen)
7076type UserMenuItem = { command: () => Promise <void >, label: string }
7177const userMenu: UserMenuItem [] = [
7278 {
73- command : async () => { await navigateTo (' /user/settings' ) },
79+ command : async () => { await navigateTo (` ${ v1Domain } /user/settings` , { external: true } ) },
7480 label: $t (' header.settings' ),
7581 },
7682 {
77- command : () => doLogout (),
83+ command : () => logout (),
7884 label: $t (' header.logout' ),
7985 },
8086]
8187const handleUserMenuSelect = async (value : UserMenuItem ) => {
8288 await value .command ?.()
8389}
90+ const v1Domain = useV1Domain ()
8491 </script >
8592
8693<template >
8794 <div
88- v-if =" minimalist"
89- class =" minimalist"
90- >
91- <div class =" top-background" />
92- <div class =" rows" >
93- <BcHeaderLogo layout-adaptability =" low" />
94- </div >
95- </div >
96-
97- <div
98- v-else
9995 class =" complete"
10096 :class =" hideInDevelopmentClass"
10197 >
10298 <div class =" top-background" />
10399 <div class =" rows" >
104100 <div class =" grid-cell blockchain-info" >
105- <span v-if =" latestState?.current_slot " ><span >{{ $t("header.slot") }}</span >:
101+ <span v-if =" currentSlot " ><span >{{ $t("header.slot") }}</span >:
106102 <BcLink
107- :to =" `/slot/${latestState.current_slot }`"
103+ :to =" `${v1Domain} /slot/${currentSlot }`"
108104 :disabled =" !showInDevelopment || null"
109105 >
110- <BcFormatNumber
106+ <BaseFormatNumber
111107 class =" bold"
112- :value =" latestState.current_slot "
108+ :value =" currentSlot "
113109 />
114110 </BcLink >
115111 </span >
116- <span v-if =" currentEpoch !== undefined " ><span >{{ $t("header.epoch") }}</span >:
112+ <span v-if =" currentEpoch" ><span >{{ $t("header.epoch") }}</span >:
117113 <BcLink
118- :to =" `/epoch/${currentEpoch}`"
114+ :to =" `${v1Domain} /epoch/${currentEpoch}`"
119115 :disabled =" !showInDevelopment || null"
120116 >
121- <BcFormatNumber
117+ <BaseFormatNumber
122118 class =" bold"
123119 :value =" currentEpoch"
124120 />
@@ -148,7 +144,7 @@ const handleUserMenuSelect = async (value: UserMenuItem) => {
148144 :show-currency-icon =" !isMobileScreen"
149145 />
150146 <div
151- v-if =" !isLoggedIn "
147+ v-if =" !userData "
152148 class =" logged-out"
153149 >
154150 <BcLink
@@ -191,15 +187,15 @@ const handleUserMenuSelect = async (value: UserMenuItem) => {
191187 </div >
192188
193189 <div class =" grid-cell explorer-info" >
194- <BcHeaderLogo layout-adaptability =" high" />
190+ <BcNavigationLogo layout-adaptability =" high" />
195191 <span class =" variant" >
196192 <span class =" mobile" >{{ networkInfo.shortName }}</span >
197193 <span class =" large-screen" >{{ networkInfo.name }}</span >
198194 </span >
199195 </div >
200196
201197 <div class =" grid-cell mega-menu" >
202- <BcHeaderMegaMenu ref =" megaMenu" />
198+ <BcNavigationMenu ref =" megaMenu" />
203199 <div
204200 v-if =" isMobileMegaMenuOpen"
205201 class =" decoration"
@@ -216,7 +212,11 @@ const handleUserMenuSelect = async (value: UserMenuItem) => {
216212$mobileHeaderThreshold : 600px ;
217213$smallHeaderThreshold : 1024px ;
218214
219- @mixin common {
215+ .complete {
216+ top : -1px ; // needed for some reason to perfectly match Figma
217+ border-bottom : 1px solid var (--container-border-color );
218+ background-color : var (--container-background );
219+
220220 position : relative ;
221221 display : flex ;
222222 width : 100% ;
@@ -230,23 +230,7 @@ $smallHeaderThreshold: 1024px;
230230 .rows {
231231 width : var (--content-width );
232232 }
233- }
234-
235- .minimalist {
236- color : var (--header-top-font-color );
237- @include common ();
238- @media (max-width : $mobileHeaderThreshold ) {
239- .top-background {
240- height : 36px ;
241- }
242- }
243- }
244233
245- .complete {
246- top : -1px ; // needed for some reason to perfectly match Figma
247- border-bottom : 1px solid var (--container-border-color );
248- background-color : var (--container-background );
249- @include common ();
250234 & .hide-because-it-is-unfinished {
251235 // TODO: once the searchbar is enabled in production, delete this block (because border-bottom is always needed, due to the fact that the lower header is always visible (it contains the search bar when the screeen is narrow, otherwise the logo and mega menu))
252236 @media (max-width : $smallHeaderThreshold ) {
0 commit comments