95 lines
2.3 KiB
Vue
95 lines
2.3 KiB
Vue
<script setup lang="ts">
|
|
import { useDropZone } from '@vueuse/core';
|
|
import { toast } from 'vue-sonner';
|
|
import DirectoryListContextMenu from '~/components/DirectoryListContextMenu.vue';
|
|
import RenameEntryDialog from '~/components/actions/RenameEntryDialog.vue';
|
|
import { getWarrenDirectory } from '~/lib/api/warrens';
|
|
|
|
definePageMeta({
|
|
middleware: ['authenticated'],
|
|
});
|
|
|
|
const warrenStore = useWarrenStore();
|
|
const loadingIndicator = useLoadingIndicator();
|
|
const uploadStore = useUploadStore();
|
|
const warrenPath = computed(() => useWarrenPath());
|
|
|
|
const dropZoneRef = ref<HTMLElement>();
|
|
|
|
const dropZone = useDropZone(dropZoneRef, {
|
|
onDrop,
|
|
multiple: true,
|
|
});
|
|
|
|
if (warrenStore.current == null) {
|
|
await navigateTo({
|
|
path: '/warrens',
|
|
});
|
|
}
|
|
|
|
const dirData = useAsyncData(
|
|
'current-directory',
|
|
async () => {
|
|
if (warrenStore.current == null) {
|
|
return [];
|
|
}
|
|
|
|
loadingIndicator.start();
|
|
warrenStore.loading = true;
|
|
|
|
const { files, parent } = await getWarrenDirectory(
|
|
warrenStore.current.warrenId,
|
|
warrenStore.current.path
|
|
);
|
|
|
|
warrenStore.loading = false;
|
|
loadingIndicator.finish();
|
|
|
|
return { files, parent };
|
|
},
|
|
{ watch: [warrenPath] }
|
|
).data;
|
|
|
|
function onDrop(files: File[] | null, e: DragEvent) {
|
|
if (files == null) {
|
|
return;
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
if (warrenStore.current == null) {
|
|
toast.warning('Upload', {
|
|
description: 'Enter a warren before attempting to upload files',
|
|
});
|
|
return;
|
|
}
|
|
|
|
const added = uploadStore.addFiles(
|
|
warrenStore.current.warrenId,
|
|
warrenStore.current.path,
|
|
files
|
|
);
|
|
|
|
if (added) {
|
|
uploadStore.dialogOpen = true;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div ref="dropZoneRef" class="grow">
|
|
<DirectoryListContextMenu class="w-full grow">
|
|
<DirectoryList
|
|
v-if="dirData != null"
|
|
:is-over-drop-zone="
|
|
dropZone.isOverDropZone.value &&
|
|
dropZone.files.value != null
|
|
"
|
|
:entries="dirData.files"
|
|
:parent="dirData.parent"
|
|
/>
|
|
</DirectoryListContextMenu>
|
|
<RenameEntryDialog />
|
|
</div>
|
|
</template>
|