-
Notifications
You must be signed in to change notification settings - Fork 0
/
navbar.tsx
189 lines (180 loc) · 4.14 KB
/
navbar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import config from '@config'
import { getTeamForUser, userHasTag } from '@db'
import type { Team, User } from '@prisma/client'
import type { SessionRequest } from '@session'
import { Icon } from '@iconify-icon/react'
export async function navbar(req: SessionRequest) {
const user = req.session?.user
let team: Team | null = null
if (user) {
team = await getTeamForUser(user.id)
}
return (
<aside className="shrink-0 md:w-64 bg-gray-800 flex flex-col">
<header className="bg-blue-500 flex items-center h-14">
<a href="/" className="pl-4 flex gap-1 justify-center items-center">
<Icon icon="mdi:person-outline" width="1.2em" height="1.2em" />
{user?.name} | {team?.money}
<Icon icon="mdi:dollar" width="1.2em" height="1.2em" />
<span
className="icon-[mdi--attach-money]"
style={{ width: '1.2em', height: '1.2em;' }}
></span>
</a>
<div
className="flex justify-center items-center ml-auto mr-2 text-white text-sm md:hidden px-4 py-2 hover:bg-blue-700 rounded-md cursor-pointer"
id="toggle"
>
<Icon icon="mdi:menu" width="1.5em" height="1.5em" />
</div>
</header>
<div className="md:block overflow-y-auto hidden" id="nav">
{await Promise.all(
modules.map(async (nav_group) => (
<nav className="p-4 flex flex-col gap-1 border-b border-gray-700">
<header className="font-bold uppercase text-gray-400 text-sm mb-1">
{nav_group.name}
</header>
{await Promise.all(
nav_group.items.map(async (module) =>
(await isVisible(module.key, user))
? renderModule(module)
: null
)
)}
</nav>
))
)}
</div>
</aside>
)
}
async function isVisible(module: string, user: User | undefined) {
if (user === undefined) {
return false
}
const visible = config().visibleModules[module]
if (visible === undefined) {
return false
}
if (visible === 'admin') {
return user.admin === true
} else if (visible === true) {
return true
} else if (visible === false) {
return false
} else {
return await userHasTag(user.id, visible)
}
}
function renderModule(module: Module) {
return (
<a
className="font-medium text-gray-200 px-2 py-1 hover:bg-gray-900 rounded gap-2"
href={module.url}
>
{module.name}
</a>
)
}
interface Module {
name: string
url: string
key: string
}
interface NavGroup {
name: string
items: Module[]
}
const modules: NavGroup[] = [
{
name: 'Nákup',
items: [
{
name: 'Profil',
url: '/user',
key: 'profile'
},
{
name: 'Obchod',
url: '/shop',
key: 'shop'
},
{
name: 'Rezervácie',
url: '/reservations',
key: 'reservations'
}
]
},
{
name: 'fun',
items: [
{
name: 'Hry',
url: '/games',
key: 'games'
},
{
name: 'Moje Reklamy',
url: '/ad/myads',
key: 'ads'
},
{
name: 'Videá',
url: '/videos',
key: 'videos'
},
{
name: 'Stávky',
url: '/bets',
key: 'bets'
},
{
name: 'Questy',
url: '/quests',
key: 'quests'
}
]
},
{
name: 'peniaze',
items: [
{
name: 'Transakcie',
url: '/transactions',
key: 'transactions'
},
{
name: 'Platby',
url: '/payments/quickPay',
key: 'payments'
},
{
name: 'Pridaj Peniaze družinkám',
url: '/management',
key: 'management'
}
]
},
{
name: 'Admin management',
items: [
{
name: 'Mergovanie družiniek',
url: '/teams',
key: 'teams'
},
{
name: 'Aktuálne guesty',
url: '/quests/board',
key: 'quests-admin'
},
{
name: 'Fix upload',
url: '/upload',
key: 'upload'
}
]
}
]