Skip to content

Commit 34c479e

Browse files
committed
fix: update ui
1 parent 2709e51 commit 34c479e

File tree

3 files changed

+113
-126
lines changed

3 files changed

+113
-126
lines changed

client/app/components/LoadingScreen.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const connection = computed(() => connections[code]!)
190190
</div>
191191

192192
<div
193-
v-if="info"
193+
v-if="info?.authenticated"
194194
class="absolute top-10 left-10 hidden lg:block pointer-events-none text-[10px] text-white/20"
195195
>
196196
<p>DB: {{ info.name }}</p>

client/app/layouts/default.vue

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<script setup lang="ts">
2-
import type { NavigationMenuItem, DropdownMenuItem } from '@nuxt/ui'
2+
import type { NavigationMenuItem } from '@nuxt/ui'
33
import { computedAsync } from '@vueuse/core'
44
import { rpc } from '../composables/rpc'
5-
import { useRoute, ref, computed, onMounted, watch, useRouter } from '#imports'
5+
import { useRoute, ref, computed, watch, useRouter } from '#imports'
66
77
const collections = computedAsync(async () => await rpc.value?.listCollections() || [])
88
99
const route = useRoute()
1010
const router = useRouter()
11-
// const toast = useToast()
1211
1312
const open = ref(false)
1413
@@ -29,11 +28,6 @@ const groups = computed(() => [
2928
label: 'Collections',
3029
items: links.value[0],
3130
},
32-
{
33-
id: 'actions',
34-
label: 'Actions',
35-
items: links.value[0],
36-
},
3731
{
3832
id: 'code',
3933
label: 'Code',
@@ -57,41 +51,6 @@ watch(links, () => {
5751
}
5852
}
5953
}, { immediate: true })
60-
61-
onMounted(async () => {
62-
// const cookie = useCookie('cookie-consent')
63-
// if (cookie.value === 'accepted') {
64-
// return
65-
// }
66-
67-
// toast.add({
68-
// title: 'We use first-party cookies to enhance your experience on our website.',
69-
// duration: 0,
70-
// close: false,
71-
// actions: [{
72-
// label: 'Accept',
73-
// color: 'neutral',
74-
// variant: 'outline',
75-
// onClick: () => {
76-
// cookie.value = 'accepted'
77-
// },
78-
// }, {
79-
// label: 'Opt out',
80-
// color: 'neutral',
81-
// variant: 'ghost',
82-
// }],
83-
// })
84-
})
85-
86-
const items = [[{
87-
label: 'New mail',
88-
icon: 'i-lucide-send',
89-
to: '/inbox',
90-
}, {
91-
label: 'New customer',
92-
icon: 'i-lucide-user-plus',
93-
to: '/customers',
94-
}]] satisfies DropdownMenuItem[][]
9554
</script>
9655

9756
<template>
@@ -155,13 +114,7 @@ const items = [[{
155114
</template>
156115

157116
<template #right>
158-
<UDropdownMenu :items="items">
159-
<UButton
160-
icon="i-lucide-plus"
161-
size="md"
162-
class="rounded-full"
163-
/>
164-
</UDropdownMenu>
117+
<slot name="actions" />
165118
</template>
166119
</UDashboardNavbar>
167120
</template>

client/app/pages/[...collection]/index.vue

Lines changed: 109 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,33 @@ function addDocument() {
229229
selectedDocument.value[field] = ''
230230
}
231231
// }
232+
233+
// Scroll to new document and focus on first field
234+
setTimeout(() => {
235+
const tableEl = tableRef.value?.$el as HTMLElement
236+
if (tableEl) {
237+
// Scroll to the bottom where the new row is
238+
tableEl.scrollTop = tableEl.scrollHeight
239+
}
240+
241+
// Focus on the first editable field
242+
const firstField = fields.value.find(f => f !== '_id')
243+
if (firstField && selectedDocument.value) {
244+
const inputId = `${selectedDocument.value._id || 'new'}-${firstField}`
245+
const input = document.getElementById(inputId) as HTMLInputElement
246+
if (input) {
247+
input.focus()
248+
}
249+
else {
250+
// If no _id yet, try to find the first input in the editing row
251+
setTimeout(() => {
252+
const firstInput = document.querySelector('.custom-input input') as HTMLInputElement
253+
if (firstInput)
254+
firstInput.focus()
255+
}, 100)
256+
}
257+
}
258+
}, 100)
232259
}
233260
234261
function editDocument(document: any) {
@@ -316,85 +343,92 @@ useEventListener(tableRef, 'scroll', updateShadow)
316343
</script>
317344

318345
<template>
319-
<div class="px-4 py-2 backdrop-blur z-10 flex items-center gap-4 border-b border-default">
320-
<UInput
321-
v-model="search"
322-
placeholder="Search..."
323-
class="flex-1"
324-
/>
325-
<UButton
326-
icon="carbon:add"
327-
color="success"
328-
@click="addDocument"
329-
>
330-
Add Document
331-
</UButton>
332-
</div>
333-
334-
<div
335-
v-if="totalDocuments"
336-
class="flex items-center px-4 py-2 border-b border-default"
337-
>
338-
<div class="opacity-50">
339-
<span v-if="search">{{ filtered.length }} matched · </span>
340-
<span>{{ documents?.length }} of {{ totalDocuments }} documents in total</span>
341-
</div>
342-
<div class="flex-auto" />
343-
<div class="flex gap-2">
344-
<select
345-
v-if="pagination.limit !== 0"
346-
v-model="pagination.page"
347-
class="px-3 py-1.5 rounded border border-default bg-default"
346+
<NuxtLayout>
347+
<template #actions>
348+
<UInput
349+
v-model="search"
350+
placeholder="Search..."
351+
class="w-64"
352+
/>
353+
<UButton
354+
icon="carbon:add"
355+
color="success"
356+
@click="addDocument"
348357
>
349-
<option
350-
v-for="i in Math.ceil(totalDocuments / pagination.limit)"
351-
:key="i"
352-
:value="i"
358+
Add Document
359+
</UButton>
360+
</template>
361+
362+
<div
363+
v-if="totalDocuments"
364+
class="flex items-center px-4 py-2 border-b border-default"
365+
>
366+
<div class="opacity-50">
367+
<span v-if="search">{{ filtered.length }} matched · </span>
368+
<span>{{ documents?.length }} of {{ totalDocuments }} documents in total</span>
369+
</div>
370+
<div class="flex-auto" />
371+
<div class="flex gap-2">
372+
<select
373+
v-if="pagination.limit !== 0"
374+
v-model="pagination.page"
375+
class="px-3 py-1.5 rounded border border-default bg-default"
353376
>
354-
page: {{ i }}
355-
</option>
356-
</select>
357-
<select
358-
v-model="pagination.limit"
359-
class="px-3 py-1.5 rounded border border-default bg-default"
360-
>
361-
<option
362-
v-for="i in [1, 2, 3, 4, 5]"
363-
:key="i"
364-
:value="i * 10"
377+
<option
378+
v-for="i in Math.ceil(totalDocuments / pagination.limit)"
379+
:key="i"
380+
:value="i"
381+
>
382+
page: {{ i }}
383+
</option>
384+
</select>
385+
<select
386+
v-model="pagination.limit"
387+
class="px-3 py-1.5 rounded border border-default bg-default"
365388
>
366-
show: {{ i * 10 }}
367-
</option>
368-
<option :value="0">
369-
show all
370-
</option>
371-
</select>
389+
<option
390+
v-for="i in [1, 2, 3, 4, 5]"
391+
:key="i"
392+
:value="i * 10"
393+
>
394+
show: {{ i * 10 }}
395+
</option>
396+
<option :value="0">
397+
show all
398+
</option>
399+
</select>
400+
</div>
372401
</div>
373-
</div>
374-
375-
<UTable
376-
v-if="documents?.length || selectedDocument"
377-
ref="tableRef"
378-
v-model:column-pinning="columnPinning"
379-
:data="tableData"
380-
:columns="columns"
381-
sticky
382-
:ui="{
383-
tr: editing ? 'data-[editing=true]:bg-elevated' : '',
384-
}"
385-
>
386-
<template #_id-cell="{ row }">
387-
ObjectId('{{ row.original._id }}')
388-
</template>
389-
</UTable>
390-
391-
<div
392-
v-else
393-
class="flex justify-center items-center h-full text-2xl"
394-
>
395-
<span class="mr-1">📄</span>
396-
No documents found
397-
</div>
402+
403+
<UTable
404+
v-if="documents?.length || selectedDocument"
405+
ref="tableRef"
406+
v-model:column-pinning="columnPinning"
407+
:data="tableData"
408+
:columns="columns"
409+
sticky
410+
:ui="{
411+
tr: editing ? 'data-[editing=true]:bg-elevated' : '',
412+
}"
413+
>
414+
<template #_id-cell="{ row }">
415+
<span v-if="row.original._id">
416+
ObjectId('{{ row.original._id }}')
417+
</span>
418+
<span v-else>
419+
---
420+
</span>
421+
</template>
422+
</UTable>
423+
424+
<div
425+
v-else
426+
class="flex justify-center items-center h-full text-2xl"
427+
>
428+
<span class="mr-1">📄</span>
429+
No documents found
430+
</div>
431+
</NuxtLayout>
398432
</template>
399433

400434
<style lang="scss">

0 commit comments

Comments
 (0)