@@ -10,17 +10,15 @@ import { computed, defineProps, h, ref } from 'vue';
10
10
import { useRouter } from ' vue-router' ;
11
11
12
12
import type { ArrayElement } from ' @dvcol/common-utils/common' ;
13
- import type { DropdownProps } from ' naive-ui' ;
14
- import type { Component } from ' vue' ;
13
+ import type { DropdownOption , DropdownProps } from ' naive-ui' ;
14
+ import type { Component , PropType } from ' vue' ;
15
15
16
16
import IconAccount from ' ~/components/icons/IconAccount.vue' ;
17
17
import IconAccountAdd from ' ~/components/icons/IconAccountAdd.vue' ;
18
- import IconCog from ' ~/components/icons/IconCog.vue' ;
19
18
import IconExternalLink from ' ~/components/icons/IconExternalLink.vue' ;
20
- import IconLightBulb from ' ~/components/icons/IconLightBulb.vue' ;
21
19
import IconLogOut from ' ~/components/icons/IconLogOut.vue' ;
22
20
23
- import { Route } from ' ~/models/router.model' ;
21
+ import { getRouteIcon , Route } from ' ~/models/router.model' ;
24
22
import { Logger } from ' ~/services/logger.service' ;
25
23
import { NavbarService } from ' ~/services/navbar.service' ;
26
24
import { TraktService } from ' ~/services/trakt.service' ;
@@ -49,11 +47,16 @@ const onAvatarError = (event: Event) => {
49
47
fallback .value = true ;
50
48
};
51
49
52
- defineProps ({
50
+ const { routes } = defineProps ({
53
51
parentElement: {
54
52
type: HTMLElement ,
55
53
required: true ,
56
54
},
55
+ routes: {
56
+ type: Array as PropType <Route []>,
57
+ required: false ,
58
+ default : () => [],
59
+ },
57
60
});
58
61
59
62
const users = computed (() => {
@@ -82,19 +85,31 @@ const toOption = (
82
85
};
83
86
};
84
87
85
- const options = computed <DropdownProps [' options' ]>(() => {
86
- const baseOptions: DropdownProps [' options' ] = [
87
- toOption (' settings' , IconCog ),
88
- toOption (' about' , IconLightBulb ),
88
+ const { floating, reverse } = useAppStateStoreRefs ();
89
+ const options = computed <DropdownOption []>(() => {
90
+ const baseOptions: DropdownOption [] = [
91
+ toOption (Route .Settings , getRouteIcon (Route .Settings )),
92
+ toOption (Route .About , getRouteIcon (Route .About )),
89
93
{ type: ' divider' , key: ' external-links' },
90
94
toOption (' trakt' , IconExternalLink ),
91
95
{ type: ' divider' , key: ' session-divider' },
92
96
toOption (' login' , IconAccountAdd ),
93
97
toOption (' logout' , IconLogOut ),
94
98
];
95
99
96
- if (! users .value .length ) return baseOptions ;
100
+ const _routes = [];
101
+ if (routes ?.length ) {
102
+ _routes .push (
103
+ ... routes .map (route =>
104
+ toOption (route , getRouteIcon (route ), i18n (route .toLowerCase (), ' route' )),
105
+ ),
106
+ );
107
+ _routes .push ({ type: ' divider' , key: ' routes-divider' });
108
+ }
109
+
110
+ if (! users .value .length ) return [... _routes , ... baseOptions ];
97
111
return [
112
+ ... _routes ,
98
113
... users .value .map (([key , value ]) =>
99
114
toOption (
100
115
` user-${key } ` ,
@@ -108,14 +123,14 @@ const options = computed<DropdownProps['options']>(() => {
108
123
];
109
124
});
110
125
126
+ const optionsReversed = computed (() =>
127
+ reverse .value ? [... options .value ].reverse () : options .value ,
128
+ );
129
+
111
130
const { loadUser, logout } = useLogout ();
112
131
113
132
const onSelect: DropdownProps [' onSelect' ] = async (key : string , { label }) => {
114
133
switch (key ) {
115
- case ' settings' :
116
- return router .push (Route .Settings );
117
- case ' about' :
118
- return router .push (Route .About );
119
134
case ' trakt' :
120
135
return createTab ({
121
136
url: ExternaLinks .trakt [TraktService .isStaging ? ' staging' : ' production' ],
@@ -125,14 +140,15 @@ const onSelect: DropdownProps['onSelect'] = async (key: string, { label }) => {
125
140
case ' logout' :
126
141
return logout ();
127
142
default :
143
+ if (Object .values (Route ).includes (key as Route )) return router .push (key );
128
144
if (typeof label === ' string' && key .startsWith (' user-' )) {
129
145
return loadUser (label );
130
146
}
131
147
Logger .error (' Unknown key:' , key );
132
148
}
133
149
};
150
+
134
151
const { dropdown } = NavbarService ;
135
- const { floating, reverse } = useAppStateStoreRefs ();
136
152
const placement = computed (() => {
137
153
if (reverse .value ) return ' top' ;
138
154
if (floating .value ) return ' bottom' ;
@@ -143,7 +159,7 @@ const placement = computed(() => {
143
159
<template >
144
160
<NDropdown
145
161
trigger =" hover"
146
- :options =" options "
162
+ :options =" optionsReversed "
147
163
:to =" parentElement"
148
164
:placement =" placement"
149
165
size =" small"
0 commit comments