From d4e91ea9a68c8bfebe6a1000b47023fc3ed2dd5b Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Mon, 13 Nov 2023 13:56:54 +0000 Subject: [PATCH 1/7] Stricter search that doesn't ignore all punctuation. --- frontend/src/utils/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index e8cf947..870ffca 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -86,7 +86,7 @@ export function haystackFormat(str: string) { // Preformat search string for faster search export function needleFormat(query: string) { const based = query.normalize('NFKD').replace(/[\u0300-\u036f]/g, '').toLowerCase() - return {based, words: based.split(/\W+/)} + return {based, words: based.split(/\s+/)} } // Test if haystack includes needle -- 2.45.2 From 3d3b078e60b729ba23c9d5381058f8bb6f920e5c Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Mon, 13 Nov 2023 14:48:43 +0000 Subject: [PATCH 2/7] Refactor replacing Document type with Doc class with computed properties. Switched Doc storage to shallowRefs for extra performance and to keep the Doc class included. --- frontend/src/components/FileExplorer.vue | 55 +++++++++------------ frontend/src/components/FileModified.vue | 4 +- frontend/src/components/FileRenameInput.vue | 6 +-- frontend/src/components/FileSize.vue | 4 +- frontend/src/repositories/Document.ts | 29 ++++++++--- frontend/src/stores/documents.ts | 26 ++++------ 6 files changed, 63 insertions(+), 61 deletions(-) diff --git a/frontend/src/components/FileExplorer.vue b/frontend/src/components/FileExplorer.vue index 3a0cdb0..593e305 100644 --- a/frontend/src/components/FileExplorer.vue +++ b/frontend/src/components/FileExplorer.vue @@ -79,28 +79,28 @@ 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/repositories/Document.ts b/frontend/src/repositories/Document.ts index 022b260..cae8774 100644 --- a/frontend/src/repositories/Document.ts +++ b/frontend/src/repositories/Document.ts @@ -1,17 +1,34 @@ +import { formatSize, formatUnixDate, haystackFormat } from "@/utils" + export type FUID = string -export type Document = { +export type DocProps = { loc: string name: string key: FUID size: number - sizedisp: string mtime: number - modified: string - haystack: string dir: boolean } +export class Doc { + private _name: string = "" + public loc: string = "" + public key: FUID = "" + public size: number = 0 + public mtime: number = 0 + public haystack: string = "" + public dir: boolean = false + + constructor(props: Partial = {}) { Object.assign(this, props) } + get name() { return this._name } + set name(name: string) { + this._name = name + this.haystack = haystackFormat(name) + } + get sizedisp(): string { return formatSize(this.size) } + get modified(): string { return formatUnixDate(this.mtime) } +} export type errorEvent = { error: { code: number @@ -36,7 +53,7 @@ export type UpdateEntry = ['k', number] | ['d', number] | ['i', Array // Helper structure for selections export interface SelectedItems { keys: FUID[] - docs: Record - recursive: Array<[string, string, Document]> + docs: Record + recursive: Array<[string, string, Doc]> missing: Set } diff --git a/frontend/src/stores/documents.ts b/frontend/src/stores/documents.ts index 7ea40da..71f2af3 100644 --- a/frontend/src/stores/documents.ts +++ b/frontend/src/stores/documents.ts @@ -1,14 +1,11 @@ -import type { Document, FileEntry, FUID, SelectedItems } from '@/repositories/Document' -import { formatSize, formatUnixDate, haystackFormat } from '@/utils' +import type { FileEntry, FUID, SelectedItems } from '@/repositories/Document' +import { Doc } from '@/repositories/Document' import { defineStore } from 'pinia' import { collator } from '@/utils' import { logoutUser } from '@/repositories/User' import { watchConnect } from '@/repositories/WS' +import { shallowRef } from 'vue' -type FileData = { id: string; mtime: number; size: number; dir: DirectoryData } -type DirectoryData = { - [filename: string]: FileData -} type User = { username: string privileged: boolean @@ -19,7 +16,7 @@ type User = { export const useDocumentStore = defineStore({ id: 'documents', state: () => ({ - document: [] as Document[], + document: shallowRef([]), selected: new Set(), fileExplorer: null as any, error: '' as string, @@ -38,20 +35,17 @@ export const useDocumentStore = defineStore({ let loc = [] as string[] for (const [level, name, key, mtime, size, isfile] of root) { loc = loc.slice(0, level - 1) - docs.push({ + docs.push(new Doc({ name, loc: level ? loc.join('/') : '/', key, size, - sizedisp: formatSize(size), mtime, - modified: formatUnixDate(mtime), - haystack: haystackFormat(name), dir: !isfile, - }) + })) loc.push(name) } - this.document = docs as Document[] + this.document = docs }, login(username: string, privileged: boolean) { this.user.username = username @@ -75,12 +69,12 @@ export const useDocumentStore = defineStore({ isUserLogged(): boolean { return this.user.isLoggedIn }, - recentDocuments(): Document[] { + recentDocuments(): Doc[] { const ret = [...this.document] ret.sort((a, b) => b.mtime - a.mtime) return ret }, - largeDocuments(): Document[] { + largeDocuments(): Doc[] { const ret = [...this.document] ret.sort((a, b) => b.size - a.size) return ret @@ -105,7 +99,7 @@ export const useDocumentStore = defineStore({ for (const key of selected) if (!found.has(key)) ret.missing.add(key) // Build a flat list including contents recursively const relnames = new Set() - function add(rel: string, full: string, doc: Document) { + function add(rel: string, full: string, doc: Doc) { if (!doc.dir && relnames.has(rel)) throw Error(`Multiple selections conflict for: ${rel}`) relnames.add(rel) ret.recursive.push([rel, full, doc]) -- 2.45.2 From 19a5c4ad8a14d2fca191ff6927e877a0eb881910 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Mon, 13 Nov 2023 15:17:45 +0000 Subject: [PATCH 3/7] Another approach to auto-update modified with current time --- frontend/src/components/FileExplorer.vue | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/FileExplorer.vue b/frontend/src/components/FileExplorer.vue index 593e305..b01d385 100644 --- a/frontend/src/components/FileExplorer.vue +++ b/frontend/src/components/FileExplorer.vue @@ -17,7 +17,7 @@ - + @@ -61,7 +61,7 @@ - + @@ -79,7 +79,7 @@ +@/stores/main diff --git a/frontend/src/components/FileExplorer.vue b/frontend/src/components/FileExplorer.vue index b01d385..155da5f 100644 --- a/frontend/src/components/FileExplorer.vue +++ b/frontend/src/components/FileExplorer.vue @@ -36,11 +36,11 @@ @@ -80,7 +80,7 @@ @@ -152,3 +152,4 @@ const download = async () => { text-overflow: ellipsis; } +@/stores/main diff --git a/frontend/src/components/LoginModal.vue b/frontend/src/components/LoginModal.vue index 3d811e8..3735383 100644 --- a/frontend/src/components/LoginModal.vue +++ b/frontend/src/components/LoginModal.vue @@ -39,10 +39,10 @@ import { reactive, ref } from 'vue' import { loginUser } from '@/repositories/User' import type { ISimpleError } from '@/repositories/Client' -import { useDocumentStore } from '@/stores/documents' +import { useMainStore } from '@/stores/main' const confirmLoading = ref(false) -const store = useDocumentStore() +const store = useMainStore() const loginForm = reactive({ username: '', @@ -99,3 +99,4 @@ const login = async () => { height: 1em; } +@/stores/main diff --git a/frontend/src/components/UploadButton.vue b/frontend/src/components/UploadButton.vue index d203b19..2bc9efa 100644 --- a/frontend/src/components/UploadButton.vue +++ b/frontend/src/components/UploadButton.vue @@ -1,12 +1,12 @@ +@/stores/main -- 2.45.2 From ffafbc87d02c6c261087e9f86b673f0ecf4be5a5 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Mon, 13 Nov 2023 09:39:20 -0800 Subject: [PATCH 6/7] Fix hash and question mark handling in URLs - broke Vue router --- frontend/src/components/BreadCrumb.vue | 6 ++++-- frontend/src/components/FileExplorer.vue | 8 ++------ frontend/src/components/HeaderMain.vue | 6 +++--- frontend/src/repositories/Document.ts | 8 ++++++++ frontend/src/views/ExplorerView.vue | 1 - 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/BreadCrumb.vue b/frontend/src/components/BreadCrumb.vue index ce98fda..7016559 100644 --- a/frontend/src/components/BreadCrumb.vue +++ b/frontend/src/components/BreadCrumb.vue @@ -48,9 +48,11 @@ const navigate = (index: number) => { 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 155da5f..f873093 100644 --- a/frontend/src/components/FileExplorer.vue +++ b/frontend/src/components/FileExplorer.vue @@ -50,7 +50,7 @@