-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavbar.vue
More file actions
211 lines (189 loc) · 6.18 KB
/
Navbar.vue
File metadata and controls
211 lines (189 loc) · 6.18 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<script setup lang="ts">
import { computed, ref, watch, type FunctionalComponent } from "vue";
import { Menu, X, LogOut, Settings, Trophy } from "lucide-vue-next";
import { Button } from "@/components/ui/button";
import type { RouteLocationRaw } from "vue-router";
import { useQuery } from "@pinia/colada";
import { getAllEvents } from "@/api/events";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "./ui/select";
import { useEventStore } from "@/stores/event";
import { useAuthStore } from "@/stores/auth";
import { useRouter } from "vue-router";
import CompanyOrSpeakerAutocompleteWithDialog from "./CompanyOrSpeakerAutocompleteWithDialog.vue";
import type { Company } from "@/dto/companies";
import type { Speaker } from "@/dto/speakers";
import { useMagicKeys } from "@vueuse/core";
import Notification from "./navbar/Notification.vue";
const isOpen = ref(false);
const authStore = useAuthStore();
const router = useRouter();
const logout = () => {
authStore.clearToken();
router.push({ name: "landing" });
};
interface NavigationItem {
name: string;
to: RouteLocationRaw;
icon?: FunctionalComponent;
}
const navigation: NavigationItem[] = [
{ name: "Me", to: { name: "dashboard" } },
{ name: "Companies", to: { name: "companies" } },
{ name: "Speakers", to: { name: "speakers" } },
{ name: "Leaderboard", to: { name: "leaderboard" }, icon: Trophy },
{ name: "Settings", to: { name: "settings" }, icon: Settings },
];
const { data: events, isLoading: eventsLoading } = useQuery({
key: ["events"],
query: getAllEvents,
});
const sortedEvents = computed(() =>
[...(events.value?.data ?? [])].sort(
(a, b) => b.begin?.localeCompare(a.begin || "") || 0,
),
);
const eventStore = useEventStore();
watch(
() => sortedEvents.value,
() => {
if (sortedEvents.value?.length && !eventStore.selectedEvent) {
eventStore.selectedEvent = sortedEvents.value[0]!;
}
},
{ immediate: true },
);
const companySelected = (company: Company) =>
router.push({ name: "company", params: { companyId: company.id } });
const speakerSelected = (speaker: Speaker) =>
router.push({ name: "speaker", params: { speakerId: speaker.id } });
const keys = useMagicKeys();
const shortcutMac = keys["meta+k"];
const shortcutLinux = keys["ctrl+k"];
const showSuggestions = ref(false);
watch(shortcutMac, () => {
if (shortcutMac.value) {
showSuggestions.value = true;
// Reset after a short delay to allow the component to react
setTimeout(() => {
showSuggestions.value = false;
}, 100);
}
});
watch(shortcutLinux, () => {
if (shortcutLinux.value) {
showSuggestions.value = true;
// Reset after a short delay to allow the component to react
setTimeout(() => {
showSuggestions.value = false;
}, 100);
}
});
</script>
<template>
<section
class="fixed top-0 left-0 right-0 z-50 w-full flex items-center bg-white py-4 border-b border-gray-200"
>
<div class="container mx-auto px-4 md:px-6 lg:px-8">
<nav class="flex items-center justify-between">
<div class="flex items-center gap-3">
<RouterLink :to="{ name: 'dashboard' }" class="text-2xl font-bold"
>Deck</RouterLink
>
<Select v-model="eventStore.selectedEvent">
<SelectTrigger :loading="eventsLoading">
<SelectValue placeholder="Edition" />
</SelectTrigger>
<SelectContent>
<SelectItem
v-for="event in sortedEvents"
:key="event.id"
:value="event"
>
{{ event.name }}
</SelectItem>
</SelectContent>
</Select>
</div>
<CompanyOrSpeakerAutocompleteWithDialog
:autofocus="showSuggestions"
:force-show-suggestions="showSuggestions"
class="hidden md:inline w-full px-3"
placeholder="Search"
show-create
@company-selected="companySelected"
@speaker-selected="speakerSelected"
/>
<!-- Desktop Navigation -->
<div class="hidden md:flex items-center space-x-4">
<Notification />
<RouterLink
v-for="item in navigation"
:key="item.name"
:to="item.to"
class="text-gray-600 hover:text-gray-900"
:title="item.name"
>
<component :is="item.icon" v-if="item.icon" class="h-5 w-5" />
<span v-else>{{ item.name }}</span>
</RouterLink>
<Button
variant="ghost"
size="sm"
class="text-gray-600 hover:text-gray-900"
@click="logout"
>
<LogOut class="h-4 w-4" />
</Button>
</div>
<!-- Mobile Navigation Button -->
<div class="md:hidden">
<Notification />
<Button variant="ghost" @click="isOpen = !isOpen">
<Menu v-if="!isOpen" class="h-6 w-6" />
<X v-else class="h-6 w-6" />
</Button>
</div>
</nav>
<!-- Mobile Navigation Menu -->
<div
v-if="isOpen"
class="md:hidden absolute top-full left-0 w-full bg-white border-b border-gray-200 py-4"
>
<CompanyOrSpeakerAutocompleteWithDialog
class="w-full px-3 pb-3"
placeholder="Search"
@company-selected="companySelected"
@speaker-selected="speakerSelected"
/>
<div class="container mx-auto px-4">
<div class="flex flex-col space-y-4">
<RouterLink
v-for="item in navigation"
:key="item.name"
:to="item.to"
class="text-gray-600 hover:text-gray-900 flex items-center gap-2"
>
<component :is="item.icon" v-if="item.icon" class="h-4 w-4" />
<span>{{ item.name }}</span>
</RouterLink>
<Button
variant="ghost"
size="sm"
class="text-gray-600 hover:text-gray-900 justify-start p-0"
@click="logout"
>
<LogOut class="h-4 w-4 mr-2" />
Logout
</Button>
</div>
</div>
</div>
</div>
</section>
</template>