More efficient flat file list format and various UX improvements #3

Merged
leo merged 19 commits from major-upgrade into main 2023-11-12 23:20:40 +00:00
7 changed files with 13 additions and 94 deletions
Showing only changes of commit c2b9ef6c2f - Show all commits

View File

@ -1,52 +0,0 @@
<template>
<object
v-if="props.type === 'pdf'"
:data="dataURL"
type="application/pdf"
width="100%"
height="100%"
></object>
<a-image
v-else-if="props.type === 'image'"
width="50%"
:src="dataURL"
@click="() => setVisible(true)"
:previewMask="false"
:preview="{
visibleImg,
onVisibleChange: setVisible
}"
/>
<!-- Unknown case -->
<h1 v-else>Unsupported file type</h1>
</template>
<script setup lang="ts">
import { watchEffect, ref } from 'vue'
import Router from '@/router/index'
import { url_document_get } from '@/repositories/Document'
const dataURL = ref('')
watchEffect(() => {
dataURL.value = new URL(
url_document_get + Router.currentRoute.value.path,
location.origin
).toString()
})
const emit = defineEmits({
visibleImg(value: boolean) {
return value
}
})
function setVisible(value: boolean) {
emit('visibleImg', value)
}
const props = defineProps<{
type?: string
visibleImg: boolean
}>()
</script>
<style></style>

View File

@ -9,7 +9,7 @@
<SvgButton
name="create-folder"
data-tooltip="New folder"
@click="() => documentStore.fileExplorer.newFolder()"
@click="() => documentStore.fileExplorer!.newFolder()"
/>
<slot></slot>
<div class="spacer smallgap"></div>
@ -42,15 +42,15 @@ const showSearchInput = ref<boolean>(false)
const search = ref<HTMLInputElement | null>()
const searchButton = ref<HTMLButtonElement | null>()
const closeSearch = ev => {
const closeSearch = (ev: Event) => {
if (!showSearchInput.value) return // Already closing
showSearchInput.value = false
const breadcrumb = document.querySelector('.breadcrumb') as HTMLElement
breadcrumb.focus()
updateSearch(ev)
}
const updateSearch = ev => {
const q = ev.target.value
const updateSearch = (ev: Event) => {
const q = (ev.target as HTMLInputElement).value
let p = props.path.join('/')
p = p ? `/${p}` : ''
const url = q ? `${p}//${q}` : (p || '/')
@ -58,9 +58,9 @@ const updateSearch = ev => {
if (!props.query && q) router.push(url)
else router.replace(url)
}
const toggleSearchInput = () => {
const toggleSearchInput = (ev: Event) => {
showSearchInput.value = !showSearchInput.value
if (!showSearchInput.value) return closeSearch()
if (!showSearchInput.value) return closeSearch(ev)
nextTick(() => {
const input = search.value
if (input) input.focus()

View File

@ -34,7 +34,7 @@ const op = (op: string, dst?: string) => {
// @ts-ignore
if (dst !== undefined) msg.dst = dst
const control = connect(controlUrl, {
message(ev: WebSocmetMessageEvent) {
message(ev: MessageEvent) {
const res = JSON.parse(ev.data)
if ('error' in res) {
console.error('Control socket error', msg, res.error)

View File

@ -1,27 +0,0 @@
<template>
<template v-for="upload in documentStore.uploadingDocuments" :key="upload.key">
<span>{{ upload.name }}</span>
<div class="progress-container">
<a-progress :percent="upload.progress" />
<CloseCircleOutlined class="close-button" @click="dismissUpload(upload.key)" />
</div>
</template>
</template>
<script setup lang="ts">
import { useDocumentStore } from '@/stores/documents'
const documentStore = useDocumentStore()
function dismissUpload(key: number) {
documentStore.deleteUploadingDocument(key)
}
</script>
<style scoped>
.progress-container {
display: flex;
align-items: center;
}
.close-button:hover {
color: #b81414;
}
</style>

View File

@ -32,7 +32,7 @@ function uploadHandler(event: Event) {
if (!infiles.length) return
infiles.sort((a, b) => collator.compare(a.cloudName, b.cloudName))
// @ts-ignore
upqueue = upqueue.concat(infiles)
upqueue = [...upqueue, ...infiles]
statsAdd(infiles)
startWorker()
}
@ -49,13 +49,14 @@ const uprogress_init = {
tlast: 0,
statbytes: 0,
statdur: 0,
files: [],
files: [] as File[],
filestart: 0,
fileidx: 0,
filecount: 0,
filename: '',
filesize: 0,
filepos: 0,
status: 'idle',
}
const uprogress = reactive({...uprogress_init})
const percent = computed(() => uprogress.uploaded / uprogress.total * 100)
@ -109,7 +110,7 @@ const statsAdd = (f: Array<File>) => {
if (uprogress.files.length === 0) statReset()
uprogress.total += f.reduce((a, b) => a + b.size, 0)
uprogress.filecount += f.length
uprogress.files = uprogress.files.concat(f)
uprogress.files = [...uprogress.files, ...f]
statNextFile()
}
let upqueue = [] as File[]

View File

@ -109,7 +109,7 @@ const handleWatchMessage = (event: MessageEvent) => {
}
}
function handleRootMessage({ root }: { root: DirEntry }) {
function handleRootMessage({ root }: { root: FileEntry[] }) {
const store = useDocumentStore()
console.log('Watch root', root)
store.updateRoot(root)

View File

@ -21,9 +21,7 @@ export const useDocumentStore = defineStore({
state: () => ({
document: [] as Document[],
selected: new Set<FUID>(),
uploadingDocuments: [],
uploadCount: 0 as number,
fileExplorer: null,
fileExplorer: null as any,
error: '' as string,
connected: false,
server: {} as Record<string, any>,
@ -53,7 +51,6 @@ export const useDocumentStore = defineStore({
})
loc.push(name)
}
console.log("Documents", docs)
this.document = docs as Document[]
},
updateModified() {