🎉 Init
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<template>
|
||||
<div class="flex-1 overflow-auto">
|
||||
<table v-if="loading || objects.length" class="w-full border-collapse text-sm">
|
||||
<thead class="sticky top-0 bg-bg">
|
||||
<tr class="border-b border-border text-left text-xs tracking-[0.08em] text-muted">
|
||||
<th class="px-4 py-2.5 font-medium">
|
||||
<SortHeader :active="sortKey === 'key' ? sortDir : null" @click="toggleSort('key')">KEY</SortHeader>
|
||||
</th>
|
||||
<th class="px-4 py-2.5 font-medium">
|
||||
<SortHeader :active="sortKey === 'size' ? sortDir : null" @click="toggleSort('size')">SIZE</SortHeader>
|
||||
</th>
|
||||
<th class="px-4 py-2.5 font-medium">
|
||||
<SortHeader :active="sortKey === 'lastModified' ? sortDir : null" @click="toggleSort('lastModified')">MODIFIED</SortHeader>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="loading">
|
||||
<tr v-for="n in 5" :key="n" class="border-b border-border/60">
|
||||
<td class="px-4 py-3" colspan="3">
|
||||
<div class="h-4 w-2/3 animate-pulse rounded bg-surface-raised" />
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr
|
||||
v-for="object in sortedObjects"
|
||||
v-else
|
||||
:key="object.key"
|
||||
class="cursor-pointer border-b border-border/60 transition-colors hover:bg-surface-raised/35"
|
||||
@click="$emit('select', object)"
|
||||
>
|
||||
<td class="px-4 py-[5px]">
|
||||
<div class="flex items-center gap-2.5">
|
||||
<FileTypeBadge :filename="object.key" />
|
||||
<PathBreadcrumb :path="object.key" />
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-[5px] font-mono tabular-nums text-muted">{{ formatBytes(object.size) }}</td>
|
||||
<td class="px-4 py-[5px] font-mono tabular-nums text-muted">
|
||||
<div class="flex items-center gap-2">
|
||||
<span>{{ formatDate(object.lastModified) }} {{ formatTime(object.lastModified) }}</span>
|
||||
<span
|
||||
v-if="isToday(object.lastModified)"
|
||||
class="rounded bg-surface-raised px-1 py-0.5 font-sans text-[11.5px] font-medium normal-case tracking-normal text-muted"
|
||||
>Heute</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div v-else class="flex h-full flex-col items-center justify-center gap-3 px-6 text-center">
|
||||
<template v-if="error">
|
||||
<span class="material-symbols-outlined !text-[40px] text-accent">error</span>
|
||||
<p class="text-text">Objekte konnten nicht geladen werden</p>
|
||||
<p class="max-w-xs text-sm text-muted">{{ error }}</p>
|
||||
<button
|
||||
type="button"
|
||||
class="mt-1 flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-sm font-medium text-text transition-colors hover:bg-surface-raised"
|
||||
@click="$emit('retry')"
|
||||
>
|
||||
<span class="material-symbols-outlined !text-[18px]">refresh</span>
|
||||
Erneut versuchen
|
||||
</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="material-symbols-outlined !text-[40px] text-muted">{{ hasSearch ? 'search_off' : 'inventory_2' }}</span>
|
||||
<p class="text-text">{{ hasSearch ? 'Keine Treffer' : 'Dieser Bucket ist leer' }}</p>
|
||||
<p class="max-w-xs text-sm text-muted">
|
||||
{{ hasSearch
|
||||
? `Keine Objekte passen zu "${searchTerm}".`
|
||||
: 'Objekte, die du hier hochlädst, tauchen in dieser Liste auf.' }}
|
||||
</p>
|
||||
<button
|
||||
v-if="!hasSearch"
|
||||
type="button"
|
||||
class="mt-1 flex items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-sm font-medium text-white transition-opacity hover:opacity-90"
|
||||
@click="$emit('upload')"
|
||||
>
|
||||
<span class="material-symbols-outlined !text-[18px]">upload</span>
|
||||
Hochladen
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { formatBytes, formatTime, formatDate, isToday } from '~/utils/format'
|
||||
import type { S3Object } from '~/utils/s3xml'
|
||||
|
||||
const props = defineProps<{
|
||||
objects: S3Object[]
|
||||
loading: boolean
|
||||
hasSearch: boolean
|
||||
searchTerm: string
|
||||
error?: string | null
|
||||
}>()
|
||||
defineEmits<{ select: [object: S3Object]; upload: []; retry: [] }>()
|
||||
|
||||
type SortKey = 'key' | 'size' | 'lastModified'
|
||||
|
||||
const sortKey = ref<SortKey>('lastModified')
|
||||
const sortDir = ref<'asc' | 'desc'>('desc')
|
||||
|
||||
function toggleSort(key: SortKey) {
|
||||
if (sortKey.value === key) {
|
||||
sortDir.value = sortDir.value === 'asc' ? 'desc' : 'asc'
|
||||
return
|
||||
}
|
||||
sortKey.value = key
|
||||
sortDir.value = 'asc'
|
||||
}
|
||||
|
||||
const sortedObjects = computed(() => {
|
||||
const factor = sortDir.value === 'asc' ? 1 : -1
|
||||
return [...props.objects].sort((a, b) => {
|
||||
if (sortKey.value === 'key') {
|
||||
return a.key.localeCompare(b.key) * factor
|
||||
}
|
||||
if (sortKey.value === 'size') {
|
||||
return (a.size - b.size) * factor
|
||||
}
|
||||
return (new Date(a.lastModified).getTime() - new Date(b.lastModified).getTime()) * factor
|
||||
})
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user