From 41e8c78ecd05fc58a56b3a59756bbc21bdb237e4 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Mon, 13 Nov 2023 17:52:57 +0000 Subject: [PATCH] Refactoring Document storage (#5) - Major refactoring that makes Doc a class with properties - Data made only shallow reactive, for a good speedup of initial load - Minor bugfixes and UX improvements along the way - Fixed handling of hash and question marks in URLs (was confusing Vue Router) - Search made stricter to find good results (not ignore all punctuation) Reviewed-on: https://git.zi.fi/Vasanko/cista-storage/pulls/5 --- frontend/src/App.vue | 9 +- frontend/src/components/BreadCrumb.vue | 8 +- frontend/src/components/FileExplorer.vue | 87 ++++++------- frontend/src/components/FileModified.vue | 4 +- frontend/src/components/FileRenameInput.vue | 6 +- frontend/src/components/FileSize.vue | 4 +- frontend/src/components/HeaderMain.vue | 33 +++-- frontend/src/components/HeaderSelected.vue | 27 ++-- frontend/src/components/LoginModal.vue | 5 +- frontend/src/components/UploadButton.vue | 11 +- frontend/src/repositories/Document.ts | 37 +++++- frontend/src/repositories/WS.ts | 14 +-- frontend/src/stores/documents.ts | 132 -------------------- frontend/src/utils/index.ts | 2 +- frontend/src/views/ExplorerView.vue | 10 +- 15 files changed, 141 insertions(+), 248 deletions(-) delete mode 100644 frontend/src/stores/documents.ts diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 104dd5a..88b2bf6 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -17,7 +17,7 @@ import type { ComputedRef } from 'vue' import type HeaderMain from '@/components/HeaderMain.vue' import { onMounted, onUnmounted, ref, watchEffect } from 'vue' import { loadSession, watchConnect, watchDisconnect } from '@/repositories/WS' -import { useDocumentStore } from '@/stores/documents' +import { useMainStore } from '@/stores/main' import { computed } from 'vue' import Router from '@/router/index' @@ -27,7 +27,7 @@ interface Path { pathList: string[] query: string } -const documentStore = useDocumentStore() +const store = useMainStore() const path: ComputedRef = computed(() => { const p = decodeURIComponent(Router.currentRoute.value.path).split('//') const pathList = p[0].split('/').filter(value => value !== '') @@ -39,7 +39,7 @@ const path: ComputedRef = computed(() => { } }) watchEffect(() => { - document.title = path.value.path.replace(/\/$/, '').split('/').pop() || documentStore.server.name || 'Cista Storage' + document.title = path.value.path.replace(/\/$/, '').split('/').pop() || store.server.name || 'Cista Storage' }) onMounted(loadSession) onMounted(watchConnect) @@ -48,7 +48,7 @@ const headerMain = ref(null) let vert = 0 let timer: any = null const globalShortcutHandler = (event: KeyboardEvent) => { - const fileExplorer = documentStore.fileExplorer as any + const fileExplorer = store.fileExplorer as any if (!fileExplorer) return const c = fileExplorer.isCursor() const keyup = event.type === 'keyup' @@ -124,3 +124,4 @@ onUnmounted(() => { }) export type { Path } +@/stores/main diff --git a/frontend/src/components/BreadCrumb.vue b/frontend/src/components/BreadCrumb.vue index ce98fda..e0cbdc9 100644 --- a/frontend/src/components/BreadCrumb.vue +++ b/frontend/src/components/BreadCrumb.vue @@ -4,7 +4,7 @@ aria-label="Breadcrumb" @keyup.left.stop="move(-1)" @keyup.right.stop="move(1)" - @focus="move(0)" + @keyup.enter="move(0)" > { if (!link) throw Error(`No link at index ${index} (path: ${props.path})`) const url = `/${longest.value.slice(0, index).join('/')}/` const here = `/${longest.value.join('/')}/` + const current = decodeURIComponent(location.hash.slice(1).split('//')[0]) + const u = url.replaceAll('?', '%3F').replaceAll('#', '%23') + if (here.startsWith(current)) router.replace(u) + else router.push(u) link.focus() - if (here.startsWith(location.hash.slice(1))) router.replace(url) - else router.push(url) } const move = (dir: number) => { diff --git a/frontend/src/components/FileExplorer.vue b/frontend/src/components/FileExplorer.vue index 3a0cdb0..f873093 100644 --- a/frontend/src/components/FileExplorer.vue +++ b/frontend/src/components/FileExplorer.vue @@ -17,7 +17,7 @@ - + @@ -36,11 +36,11 @@ @@ -50,7 +50,7 @@ - + @@ -79,28 +79,24 @@ diff --git a/frontend/src/components/FileRenameInput.vue b/frontend/src/components/FileRenameInput.vue index aaa6977..6f1aff2 100644 --- a/frontend/src/components/FileRenameInput.vue +++ b/frontend/src/components/FileRenameInput.vue @@ -12,7 +12,7 @@ diff --git a/frontend/src/components/HeaderMain.vue b/frontend/src/components/HeaderMain.vue index f8206c1..eefc739 100644 --- a/frontend/src/components/HeaderMain.vue +++ b/frontend/src/components/HeaderMain.vue @@ -1,15 +1,15 @@