fix loading indicator for traversing warrens

This commit is contained in:
2025-07-18 14:45:21 +02:00
parent 4c3e54daca
commit 48cbd532c2
4 changed files with 33 additions and 16 deletions

View File

@@ -18,7 +18,7 @@ const store = useWarrenStore();
const session = useAuthSession(); const session = useAuthSession();
async function selectWarren(id: string) { async function selectWarren(id: string) {
await store.setCurrentWarren(id, '/'); store.setCurrentWarren(id, '/');
await navigateTo({ await navigateTo({
path: '/warrens/files', path: '/warrens/files',
}); });
@@ -56,6 +56,7 @@ async function selectWarren(id: string) {
<SidebarMenuSubItem <SidebarMenuSubItem
v-for="(warren, id) in store.warrens" v-for="(warren, id) in store.warrens"
:key="id" :key="id"
@click="() => selectWarren(id)"
> >
<SidebarMenuSubButton <SidebarMenuSubButton
:tooltip="warren.name" :tooltip="warren.name"
@@ -63,8 +64,7 @@ async function selectWarren(id: string) {
store.current != null && store.current != null &&
store.current.warrenId === id store.current.warrenId === id
" "
class="transition-all" class="cursor-pointer transition-all select-none"
@click="() => selectWarren(id)"
> >
<Icon name="lucide:folder-root" /> <Icon name="lucide:folder-root" />
<span>{{ warren.name }}</span> <span>{{ warren.name }}</span>

View File

@@ -47,20 +47,28 @@ async function submitDelete(force: boolean = false) {
async function openRenameDialog() { async function openRenameDialog() {
renameDialog.openDialog(entry); renameDialog.openDialog(entry);
} }
async function onClick() {
if (warrenStore.loading) {
return;
}
warrenStore.addToCurrentWarrenPath(entry.name);
}
</script> </script>
<template> <template>
<ContextMenu> <ContextMenu>
<ContextMenuTrigger> <ContextMenuTrigger>
<button <button
:disabled="warrenStore.loading"
:class="[ :class="[
'bg-accent/30 border-border flex w-52 flex-row gap-4 overflow-hidden rounded-md border-1 px-4 py-2 select-none', 'bg-accent/30 border-border flex w-52 flex-row gap-4 overflow-hidden rounded-md border-1 px-4 py-2 select-none',
{ {
'pointer-events-none': 'pointer-events-none': entry.fileType === 'file',
disabled || entry.fileType === 'file',
}, },
]" ]"
@click="() => warrenStore.addToCurrentWarrenPath(entry.name)" @click="onClick"
> >
<div class="flex flex-row items-center"> <div class="flex flex-row items-center">
<Icon class="size-6" :name="getFileIcon(entry.mimeType)" /> <Icon class="size-6" :name="getFileIcon(entry.mimeType)" />

View File

@@ -1,13 +1,16 @@
<script setup lang="ts"> <script setup lang="ts">
import { computedAsync } from '@vueuse/core';
import DirectoryListContextMenu from '~/components/DirectoryListContextMenu.vue'; import DirectoryListContextMenu from '~/components/DirectoryListContextMenu.vue';
import RenameEntryDialog from '~/components/actions/RenameEntryDialog.vue'; import RenameEntryDialog from '~/components/actions/RenameEntryDialog.vue';
import { getWarrenDirectory } from '~/lib/api/warrens'; import { getWarrenDirectory } from '~/lib/api/warrens';
import type { DirectoryEntry } from '~/types';
definePageMeta({ definePageMeta({
middleware: ['authenticated'], middleware: ['authenticated'],
}); });
const warrenStore = useWarrenStore(); const warrenStore = useWarrenStore();
const loadingIndicator = useLoadingIndicator();
if (warrenStore.current == null) { if (warrenStore.current == null) {
await navigateTo({ await navigateTo({
@@ -15,16 +18,24 @@ if (warrenStore.current == null) {
}); });
} }
const entries = useAsyncData('current-directory', async () => { const entries = computedAsync<DirectoryEntry[]>(async () => {
if (warrenStore.current == null) { if (warrenStore.current == null) {
return null; return [];
} }
return await getWarrenDirectory( loadingIndicator.start();
warrenStore.loading = true;
const entries = await getWarrenDirectory(
warrenStore.current.warrenId, warrenStore.current.warrenId,
warrenStore.current.path warrenStore.current.path
); );
}).data;
warrenStore.loading = false;
loadingIndicator.finish();
return entries;
}, []);
</script> </script>
<template> <template>

View File

@@ -6,16 +6,16 @@ export const useWarrenStore = defineStore('warrens', {
state: () => ({ state: () => ({
warrens: {} as Record<string, Warren>, warrens: {} as Record<string, Warren>,
current: null as { warrenId: string; path: string } | null, current: null as { warrenId: string; path: string } | null,
loading: false,
}), }),
actions: { actions: {
async setCurrentWarren(warrenId: string, path: string) { setCurrentWarren(warrenId: string, path: string) {
this.current = { this.current = {
warrenId, warrenId,
path, path,
}; };
await refreshNuxtData('current-directory');
}, },
async addToCurrentWarrenPath(path: string) { addToCurrentWarrenPath(path: string) {
if (this.current == null) { if (this.current == null) {
return; return;
} }
@@ -25,9 +25,8 @@ export const useWarrenStore = defineStore('warrens', {
} }
this.current.path += path; this.current.path += path;
await refreshNuxtData('current-directory');
}, },
async setCurrentWarrenPath(path: string) { setCurrentWarrenPath(path: string) {
if (this.current == null) { if (this.current == null) {
return; return;
} }
@@ -37,7 +36,6 @@ export const useWarrenStore = defineStore('warrens', {
} }
this.current.path = path; this.current.path = path;
await refreshNuxtData('current-directory');
}, },
clearCurrentWarren() { clearCurrentWarren() {
this.current = null; this.current = null;