Refactoring Document storage #5
|
@ -48,9 +48,11 @@ const navigate = (index: number) => {
|
||||||
if (!link) throw Error(`No link at index ${index} (path: ${props.path})`)
|
if (!link) throw Error(`No link at index ${index} (path: ${props.path})`)
|
||||||
const url = `/${longest.value.slice(0, index).join('/')}/`
|
const url = `/${longest.value.slice(0, index).join('/')}/`
|
||||||
const here = `/${longest.value.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()
|
link.focus()
|
||||||
if (here.startsWith(location.hash.slice(1))) router.replace(url)
|
|
||||||
else router.push(url)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const move = (dir: number) => {
|
const move = (dir: number) => {
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<a
|
<a
|
||||||
:href="url_for(doc)"
|
:href="doc.url"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
@contextmenu.prevent
|
@contextmenu.prevent
|
||||||
@focus.stop="cursor = doc"
|
@focus.stop="cursor = doc"
|
||||||
|
@ -93,10 +93,6 @@ const props = defineProps<{
|
||||||
}>()
|
}>()
|
||||||
const store = useMainStore()
|
const store = useMainStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const url_for = (doc: Doc) => {
|
|
||||||
const p = doc.loc ? `${doc.loc}/${doc.name}` : doc.name
|
|
||||||
return doc.dir ? `#/${p}/` : `/files/${p}`
|
|
||||||
}
|
|
||||||
const cursor = shallowRef<Doc | null>(null)
|
const cursor = shallowRef<Doc | null>(null)
|
||||||
// File rename
|
// File rename
|
||||||
const editing = shallowRef<Doc | null>(null)
|
const editing = shallowRef<Doc | null>(null)
|
||||||
|
@ -249,7 +245,7 @@ const mkdir = (doc: Doc, name: string) => {
|
||||||
editing.value = null
|
editing.value = null
|
||||||
} else {
|
} else {
|
||||||
console.log('mkdir', msg)
|
console.log('mkdir', msg)
|
||||||
router.push(doc.loc ? `/${doc.loc}/${name}/` : `/${name}/`)
|
router.push(doc.urlrouter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -58,9 +58,9 @@ const updateSearch = (ev: Event) => {
|
||||||
let p = props.path.join('/')
|
let p = props.path.join('/')
|
||||||
p = p ? `/${p}` : ''
|
p = p ? `/${p}` : ''
|
||||||
const url = q ? `${p}//${q}` : (p || '/')
|
const url = q ? `${p}//${q}` : (p || '/')
|
||||||
console.log("Update search", url)
|
const u = url.replaceAll('?', '%3F').replaceAll('#', '%23')
|
||||||
if (!props.query && q) router.push(url)
|
if (!props.query && q) router.push(u)
|
||||||
else router.replace(url)
|
else router.replace(u)
|
||||||
}
|
}
|
||||||
const toggleSearchInput = (ev: Event) => {
|
const toggleSearchInput = (ev: Event) => {
|
||||||
showSearchInput.value = !showSearchInput.value
|
showSearchInput.value = !showSearchInput.value
|
||||||
|
|
|
@ -23,11 +23,19 @@ export class Doc {
|
||||||
constructor(props: Partial<DocProps> = {}) { Object.assign(this, props) }
|
constructor(props: Partial<DocProps> = {}) { Object.assign(this, props) }
|
||||||
get name() { return this._name }
|
get name() { return this._name }
|
||||||
set name(name: string) {
|
set name(name: string) {
|
||||||
|
if (name.includes('/') || name.startsWith('.')) throw Error(`Invalid name: ${name}`)
|
||||||
this._name = name
|
this._name = name
|
||||||
this.haystack = haystackFormat(name)
|
this.haystack = haystackFormat(name)
|
||||||
}
|
}
|
||||||
get sizedisp(): string { return formatSize(this.size) }
|
get sizedisp(): string { return formatSize(this.size) }
|
||||||
get modified(): string { return formatUnixDate(this.mtime) }
|
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 = {
|
export type errorEvent = {
|
||||||
error: {
|
error: {
|
||||||
|
|
|
@ -56,4 +56,3 @@ watchEffect(() => {
|
||||||
store.fileExplorer = fileExplorer.value
|
store.fileExplorer = fileExplorer.value
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@/stores/main
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user