|
1 | 1 | <script setup lang="ts">
|
2 |
| -// only one icon can be lit up at the same time |
3 |
| -import { STORAGE_KEY_LAST_ACCESSED_EXPLORE_ROUTE, STORAGE_KEY_LAST_ACCESSED_NOTIFICATION_ROUTE } from '~/constants' |
| 2 | +import type { Component } from 'vue' |
| 3 | +import type { NavButtonName } from '../../composables/settings' |
4 | 4 |
|
5 |
| -const moreMenuVisible = ref(false) |
| 5 | +import { STORAGE_KEY_BOTTOM_NAV_BUTTONS } from '~/constants' |
| 6 | +
|
| 7 | +import { NavButtonExplore, NavButtonFederated, NavButtonHome, NavButtonLocal, NavButtonMention, NavButtonMoreMenu, NavButtonNotification, NavButtonSearch } from '#components' |
| 8 | +
|
| 9 | +interface NavButton { |
| 10 | + name: string |
| 11 | + component: Component |
| 12 | +} |
| 13 | +
|
| 14 | +const navButtons: NavButton[] = [ |
| 15 | + { name: 'home', component: NavButtonHome }, |
| 16 | + { name: 'search', component: NavButtonSearch }, |
| 17 | + { name: 'notification', component: NavButtonNotification }, |
| 18 | + { name: 'mention', component: NavButtonMention }, |
| 19 | + { name: 'explore', component: NavButtonExplore }, |
| 20 | + { name: 'local', component: NavButtonLocal }, |
| 21 | + { name: 'federated', component: NavButtonFederated }, |
| 22 | + { name: 'moreMenu', component: NavButtonMoreMenu }, |
| 23 | +] |
6 | 24 |
|
7 |
| -const { notifications } = useNotifications() |
8 |
| -const lastAccessedNotificationRoute = useLocalStorage(STORAGE_KEY_LAST_ACCESSED_NOTIFICATION_ROUTE, '') |
9 |
| -const lastAccessedExploreRoute = useLocalStorage(STORAGE_KEY_LAST_ACCESSED_EXPLORE_ROUTE, '') |
| 25 | +const defaultSelectedNavButtonNames: NavButtonName[] = currentUser.value |
| 26 | + ? ['home', 'search', 'notification', 'mention', 'moreMenu'] |
| 27 | + : ['explore', 'local', 'federated', 'moreMenu'] |
| 28 | +const selectedNavButtonNames = useLocalStorage<NavButtonName[]>(STORAGE_KEY_BOTTOM_NAV_BUTTONS, defaultSelectedNavButtonNames) |
| 29 | +
|
| 30 | +const selectedNavButtons = computed(() => selectedNavButtonNames.value.map(name => navButtons.find(navButton => navButton.name === name))) |
| 31 | +
|
| 32 | +// only one icon can be lit up at the same time |
| 33 | +const moreMenuVisible = ref(false) |
10 | 34 | </script>
|
11 | 35 |
|
12 | 36 | <template>
|
| 37 | + <!-- This weird styles above are used for scroll locking, don't change it unless you know exactly what you're doing. --> |
13 | 38 | <nav
|
14 | 39 | h-14 border="t base" flex flex-row text-xl
|
15 | 40 | of-y-scroll scrollbar-hide overscroll-none
|
16 | 41 | class="after-content-empty after:(h-[calc(100%+0.5px)] w-0.1px pointer-events-none)"
|
17 | 42 | >
|
18 |
| - <!-- These weird styles above are used for scroll locking, don't change it unless you know exactly what you're doing. --> |
19 |
| - <template v-if="currentUser"> |
20 |
| - <NuxtLink to="/home" :aria-label="$t('nav.home')" :active-class="moreMenuVisible ? '' : 'text-primary'" flex flex-row items-center place-content-center h-full flex-1 class="coarse-pointer:select-none" @click="$scrollToTop"> |
21 |
| - <div i-ri:home-5-line /> |
22 |
| - </NuxtLink> |
23 |
| - <NuxtLink to="/search" :aria-label="$t('nav.search')" :active-class="moreMenuVisible ? '' : 'text-primary'" flex flex-row items-center place-content-center h-full flex-1 class="coarse-pointer:select-none" @click="$scrollToTop"> |
24 |
| - <div i-ri:search-line /> |
25 |
| - </NuxtLink> |
26 |
| - <NuxtLink :to="`/notifications/${lastAccessedNotificationRoute}`" :aria-label="$t('nav.notifications')" :active-class="moreMenuVisible ? '' : 'text-primary'" flex flex-row items-center place-content-center h-full flex-1 class="coarse-pointer:select-none" @click="$scrollToTop"> |
27 |
| - <div flex relative> |
28 |
| - <div class="i-ri:notification-4-line" text-xl /> |
29 |
| - <div v-if="notifications" class="top-[-0.3rem] right-[-0.3rem]" absolute font-bold rounded-full h-4 w-4 text-xs bg-primary text-inverted flex items-center justify-center> |
30 |
| - {{ notifications < 10 ? notifications : '•' }} |
31 |
| - </div> |
32 |
| - </div> |
33 |
| - </NuxtLink> |
34 |
| - <NuxtLink to="/conversations" :aria-label="$t('nav.conversations')" :active-class="moreMenuVisible ? '' : 'text-primary'" flex flex-row items-center place-content-center h-full flex-1 class="coarse-pointer:select-none" @click="$scrollToTop"> |
35 |
| - <div i-ri:at-line /> |
36 |
| - </NuxtLink> |
37 |
| - </template> |
38 |
| - <template v-else> |
39 |
| - <NuxtLink :to="`/${currentServer}/explore/${lastAccessedExploreRoute}`" :aria-label="$t('nav.explore')" :active-class="moreMenuVisible ? '' : 'text-primary'" flex flex-row items-center place-content-center h-full flex-1 class="coarse-pointer:select-none" @click="$scrollToTop"> |
40 |
| - <div i-ri:compass-3-line /> |
41 |
| - </NuxtLink> |
42 |
| - <NuxtLink group :to="`/${currentServer}/public/local`" :aria-label="$t('nav.local')" :active-class="moreMenuVisible ? '' : 'text-primary'" flex flex-row items-center place-content-center h-full flex-1 class="coarse-pointer:select-none" @click="$scrollToTop"> |
43 |
| - <div i-ri:group-2-line /> |
44 |
| - </NuxtLink> |
45 |
| - <NuxtLink :to="`/${currentServer}/public`" :aria-label="$t('nav.federated')" :active-class="moreMenuVisible ? '' : 'text-primary'" flex flex-row items-center place-content-center h-full flex-1 class="coarse-pointer:select-none" @click="$scrollToTop"> |
46 |
| - <div i-ri:earth-line /> |
47 |
| - </NuxtLink> |
48 |
| - </template> |
49 |
| - <NavBottomMoreMenu v-slot="{ toggleVisible, show }" v-model="moreMenuVisible" flex flex-row items-center place-content-center h-full flex-1 cursor-pointer> |
50 |
| - <button |
51 |
| - flex items-center place-content-center h-full flex-1 class="select-none" |
52 |
| - :class="show ? '!text-primary' : ''" |
53 |
| - aria-label="More menu" |
54 |
| - @click="toggleVisible" |
55 |
| - > |
56 |
| - <span :class="show ? 'i-ri:close-fill' : 'i-ri:more-fill'" /> |
57 |
| - </button> |
58 |
| - </NavBottomMoreMenu> |
| 43 | + <Component :is="navButton!.component" v-for="navButton in selectedNavButtons" :key="navButton!.name" :active-class="moreMenuVisible ? '' : 'text-primary'" /> |
59 | 44 | </nav>
|
60 | 45 | </template>
|
0 commit comments