-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppNav.vue
More file actions
374 lines (330 loc) 路 11.7 KB
/
Copy pathAppNav.vue
File metadata and controls
374 lines (330 loc) 路 11.7 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<!--
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
-->
<template>
<!-- Enhanced Floating Navbar with Navigation -->
<nav class="absolute top-6 left-1/2 transform -translate-x-1/2 z-50 bg-card/90 backdrop-blur-xl border border-muted-foreground/20 rounded-full shadow-2xl max-w-4xl">
<div class="flex items-center justify-between px-8 py-4 gap-4">
<!-- Logo/Brand and AI Status -->
<div class="flex items-center gap-4">
<a
href="https://contextmax.dev" target="_blank" rel="noopener noreferrer"
class="flex items-center gap-1 text-xl font-bold text-foreground tracking-wide hover:text-primary transition-colors duration-200"
>
<img src="/logo-transparent.png" alt="ContextMax Logo" class="w-8 h-8" />
contextMax<span class="text-xs text-muted-foreground font-normal self-end -ml-0"><a href="https://51newyork.com" target="_blank" rel="noopener noreferrer" class="hover:text-primary transition-colors duration-200">by 51NewYork</a></span>
</a>
<!-- AI Models Status -->
<div class="flex items-center gap-2">
<div
v-for="modelKey in availableModels"
:key="modelKey"
class="flex items-center gap-1.5"
:title="getModelTooltip(modelKey)"
>
<div
:class="[
'w-2 h-2 rounded-full transition-all duration-300',
getStatusColor(modelKey),
shouldPulsate(modelKey) ? 'animate-pulse' : ''
]"
></div>
<span class="text-xs text-muted-foreground">{{ getModelDisplayName(modelKey) }}</span>
</div>
</div>
</div>
<!-- Navigation Items -->
<div class="flex items-center gap-4">
<!-- Divider -->
<div v-if="hasSavedProjects()" class="w-px h-6 bg-border"></div>
<!-- Project Section (only show if there are saved projects) -->
<div v-if="hasSavedProjects()" class="flex items-center gap-1">
<!-- "Project:" Label -->
<span class="text-sm text-muted-foreground mr-2">Project</span>
<!-- Current Project Name Button -->
<Button
@click="goToWorkspace"
variant="ghost"
size="sm"
:class="currentView === 'workspace' ? 'bg-primary/10 text-primary' : ''"
class="px-3 py-2 font-medium"
>
<Icon name="lucide:code" class="w-4 h-4 mr-2" />
{{ selectedFolder?.name || getCurrentProjectName() }}
</Button>
<!-- Switch Project Button (only if multiple projects) -->
<Button
v-if="availableProjects.length > 1"
@click="showProjectSwitcher"
variant="ghost"
size="sm"
class="px-3 py-2"
title="Switch Project"
>
<span class="text-sm mr-1">Switch</span>
<Icon name="lucide:chevron-down" class="w-4 h-4" />
</Button>
</div>
<!-- Add Project Button -->
<Button
@click="$emit('select-project')"
:disabled="!isFileSystemSupported"
variant="outline"
size="sm"
class="px-3 py-2 bg-primary/5 hover:bg-primary/10 border-primary/20"
>
<Icon name="lucide:plus" class="w-4 h-4 mr-2" />
Add
</Button>
<!-- Remove Project Button -->
<Button
v-if="selectedFolder"
@click="handleClearProjectWithConfirmation"
variant="outline"
size="sm"
class="px-3 py-2 bg-destructive/5 hover:bg-destructive/10 border-destructive/20 text-destructive hover:text-destructive"
>
<Icon name="lucide:trash-2" class="w-4 h-4 mr-2" />
Remove
</Button>
</div>
</div>
</nav>
<!-- Project Switcher Modal -->
<Dialog v-model:open="showProjectSwitcherModal">
<DialogContent class="sm:max-w-md">
<DialogHeader>
<DialogTitle class="flex items-center gap-3">
<Icon name="lucide:folder-open" class="w-5 h-5" />
Switch Project
</DialogTitle>
<DialogDescription>
Switch to a different saved project. Your current work is auto-saved.
</DialogDescription>
</DialogHeader>
<div class="space-y-3 mt-6">
<div v-if="availableProjects.length === 0" class="text-center py-8 text-muted-foreground">
<Icon name="lucide:folder-x" class="w-12 h-12 mx-auto mb-4 opacity-50" aria-hidden="true" />
<p class="font-medium mb-2">No Saved Projects</p>
<p class="text-sm">Use "Add" to add a project folder.</p>
</div>
<div v-else class="space-y-2">
<Button
v-for="project in availableProjects"
:key="project.name"
@click="handleProjectSwitch(project.name)"
variant="outline"
size="default"
class="w-full justify-start p-4 h-auto"
:disabled="isSwitchingProject || project.name === selectedFolder?.name"
>
<div class="flex items-center">
<Icon
:name="project.name === selectedFolder?.name ? 'lucide:check-circle' : 'lucide:folder'"
class="w-5 h-5 mr-3 text-primary"
aria-hidden="true"
/>
<div class="text-left flex-1">
<div class="font-medium">{{ project.name }}</div>
<div class="text-sm text-muted-foreground">
{{ project.name === selectedFolder?.name ? 'Current project' : formatLastAccessed(project.lastAccessed) }}
</div>
</div>
</div>
</Button>
</div>
</div>
<DialogFooter class="mt-6">
<Button variant="ghost" @click="showProjectSwitcherModal = false">
Cancel
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</template>
<script setup lang="ts">
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { LLMService } from '~/plugins/llm.client'
interface Props {
isFileSystemSupported: boolean
}
const _props = withDefaults(defineProps<Props>(), {
isFileSystemSupported: false
})
const _emit = defineEmits<{
(e: 'select-project'): void
(e: 'clear-project'): void
}>()
// Use the project store
const {
currentView,
selectedFolder,
goToLanding,
goToWorkspace,
} = useProjectStore()
// Project Manager (for saved projects functionality)
const {
hasSavedProjects,
savedProjects,
switchToProject
} = useProjectManager()
// LLM Status
const {
getModelState,
getAvailableModels
} = useLLMLoader()
const availableModels = getAvailableModels()
// Advanced UX Systems
const { success, errorWithRetry } = useNotifications()
// Accessibility support
const { announceStatus, announceError } = useAccessibility()
// Project switcher state
const showProjectSwitcherModal = ref(false)
const isSwitchingProject = ref(false)
// Available projects for switching
const availableProjects = computed(() => {
return savedProjects.value
})
// Get current project name for navbar
const getCurrentProjectName = (): string => {
// If we have a selected folder, use its name
if (selectedFolder.value?.name) {
return selectedFolder.value.name
}
// Otherwise, get the most recently accessed project
if (savedProjects.value.length > 0) {
return savedProjects.value[0].name // First item is most recently accessed
}
return 'Workspace'
}
// Project switcher functions
const showProjectSwitcher = () => {
showProjectSwitcherModal.value = true
}
// Handle project switching
const handleProjectSwitch = async (projectName: string) => {
if (projectName === selectedFolder.value?.name) {
showProjectSwitcherModal.value = false
return
}
isSwitchingProject.value = true
try {
const switchSuccess = await switchToProject(projectName)
if (switchSuccess) {
showProjectSwitcherModal.value = false
success(
'Project Switched',
`Successfully switched to project "${projectName}"`
)
announceStatus(`Switched to project ${projectName}`)
// Navigate to workspace after successful switch
goToWorkspace()
} else {
errorWithRetry(
'Switch Failed',
`Failed to switch to project "${projectName}". The project may not be available in local storage.`,
() => handleProjectSwitch(projectName)
)
announceError(`Failed to switch to project ${projectName}`)
}
} catch (error) {
const message = error instanceof Error ? error.message : 'Unknown error'
errorWithRetry(
'Switch Failed',
`Error switching to project "${projectName}": ${message}`,
() => handleProjectSwitch(projectName)
)
announceError(`Error switching to project: ${message}`)
} finally {
isSwitchingProject.value = false
}
}
// Format last accessed time
const formatLastAccessed = (timestamp: number): string => {
const now = Date.now()
const diff = now - timestamp
const minutes = Math.floor(diff / 60000)
const hours = Math.floor(diff / 3600000)
const days = Math.floor(diff / 86400000)
if (minutes < 1) return 'Just now'
if (minutes < 60) return `${minutes} minute${minutes === 1 ? '' : 's'} ago`
if (hours < 24) return `${hours} hour${hours === 1 ? '' : 's'} ago`
if (days < 7) return `${days} day${days === 1 ? '' : 's'} ago`
return new Date(timestamp).toLocaleDateString()
}
// LLM Status Functions
const getModelDisplayName = (modelKey: string) => {
const displayNames: Record<string, string> = {
embeddings: 'Embeddings',
textGeneration: 'Text Gen'
}
return displayNames[modelKey] || modelKey
}
const getStatusColor = (modelKey: string) => {
const serviceStatus = LLMService.getStatus(modelKey)
const modelState = getModelState(modelKey).value
// Determine if we're downloading vs initializing
const isDownloading = modelState.progress > 0 && modelState.progress < 100 &&
(modelState.message.includes('Downloading') || modelState.message.includes('Loading model'))
switch (serviceStatus) {
case 'ready':
return 'bg-green-500'
case 'error':
return 'bg-red-500'
case 'loading':
return isDownloading ? 'bg-yellow-500' : 'bg-blue-500'
default:
return 'bg-gray-400'
}
}
const shouldPulsate = (modelKey: string) => {
const serviceStatus = LLMService.getStatus(modelKey)
return serviceStatus === 'loading'
}
const getModelTooltip = (modelKey: string) => {
const serviceStatus = LLMService.getStatus(modelKey)
const modelState = getModelState(modelKey).value
const displayName = getModelDisplayName(modelKey)
switch (serviceStatus) {
case 'ready':
return `${displayName}: Ready`
case 'error':
return `${displayName}: Error - ${modelState.error || 'Unknown error'}`
case 'loading':
if (modelState.progress > 0) {
return `${displayName}: ${modelState.progress}% - ${modelState.message}`
}
return `${displayName}: ${modelState.message}`
default:
return `${displayName}: Unknown status`
}
}
// Handle clear project
const handleClearProjectWithConfirmation = () => {
_emit('clear-project')
success('Project Cleared', 'Project has been cleared successfully')
announceStatus('Project cleared')
}
</script>
<style scoped>
.animate-pulse {
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes pulse {
0%, 100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
</style>