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: #5
This commit is contained in:
		| @@ -1,17 +1,42 @@ | ||||
| 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<DocProps> = {}) { Object.assign(this, props) } | ||||
|   get name() { return this._name } | ||||
|   set name(name: string) { | ||||
|     if (name.includes('/') || name.startsWith('.')) throw Error(`Invalid name: ${name}`) | ||||
|     this._name = name | ||||
|     this.haystack = haystackFormat(name) | ||||
|   } | ||||
|   get sizedisp(): string { return formatSize(this.size) } | ||||
|   get modified(): string { return formatUnixDate(this.mtime) } | ||||
|   get url(): string { | ||||
|     const p = this.loc ? `${this.loc}/${this.name}` : this.name | ||||
|     return this.dir ? '/#/' + `${p}/`.replaceAll('#', '%23') : `/files/${p}`.replaceAll('?', '%3F').replaceAll('#', '%23') | ||||
|   } | ||||
|   get urlrouter(): string { | ||||
|     return this.url.replace(/^\/#/, '') | ||||
|   } | ||||
| } | ||||
| export type errorEvent = { | ||||
|   error: { | ||||
|     code: number | ||||
| @@ -36,7 +61,7 @@ export type UpdateEntry = ['k', number] | ['d', number] | ['i', Array<FileEntry> | ||||
| // Helper structure for selections | ||||
| export interface SelectedItems { | ||||
|   keys: FUID[] | ||||
|   docs: Record<FUID, Document> | ||||
|   recursive: Array<[string, string, Document]> | ||||
|   docs: Record<FUID, Doc> | ||||
|   recursive: Array<[string, string, Doc]> | ||||
|   missing: Set<FUID> | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Leo Vasanko
					Leo Vasanko