From be1c4c1504e2d7f29ba595ad0318c8fb21b1291a Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Sun, 12 Nov 2023 19:38:23 +0000 Subject: [PATCH] Fixes to URL path handling, search query on URL --- frontend/src/components/BreadCrumb.vue | 5 +++- frontend/src/components/FileExplorer.vue | 13 ++++------- frontend/src/components/HeaderMain.vue | 29 ++++++++++++++++++------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/BreadCrumb.vue b/frontend/src/components/BreadCrumb.vue index addac26..ce98fda 100644 --- a/frontend/src/components/BreadCrumb.vue +++ b/frontend/src/components/BreadCrumb.vue @@ -46,8 +46,11 @@ const isCurrent = (index: number) => index == props.path.length ? 'location' : u const navigate = (index: number) => { const link = links[index] 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('/')}/` link.focus() - router.replace(`/${longest.value.slice(0, index).join('/')}`) + 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 e7636ef..c63040d 100644 --- a/frontend/src/components/FileExplorer.vue +++ b/frontend/src/components/FileExplorer.vue @@ -87,13 +87,10 @@ import { connect, controlUrl } from '@/repositories/WS' import { collator, formatSize, formatUnixDate } from '@/utils' import { useRouter } from 'vue-router' -const props = withDefaults( - defineProps<{ - path: Array - documents: Document[] - }>(), - {} -) +const props = defineProps<{ + path: Array + documents: Document[] +}>() const documentStore = useDocumentStore() const router = useRouter() const url_for = (doc: Document) => { @@ -249,7 +246,7 @@ const mkdir = (doc: Document, name: string) => { editing.value = null } else { console.log('mkdir', msg) - router.push(`/${doc.loc}/${name}/`) + router.push(doc.loc ? `/${doc.loc}/${name}/` : `/${name}/`) } } }) diff --git a/frontend/src/components/HeaderMain.vue b/frontend/src/components/HeaderMain.vue index a9826b1..58c6e53 100644 --- a/frontend/src/components/HeaderMain.vue +++ b/frontend/src/components/HeaderMain.vue @@ -17,7 +17,9 @@ import { useDocumentStore } from '@/stores/documents' -import { ref, nextTick } from 'vue' +import { ref, nextTick, watchEffect } from 'vue' import ContextMenu from '@imengyu/vue3-context-menu' +import router from '@/router'; const documentStore = useDocumentStore() const showSearchInput = ref(false) const search = ref() const searchButton = ref() -const closeSearch = () => { +const closeSearch = ev => { if (!showSearchInput.value) return // Already closing showSearchInput.value = false - documentStore.search = '' const breadcrumb = document.querySelector('.breadcrumb') as HTMLElement breadcrumb.focus() + updateSearch(ev) +} +const updateSearch = ev => { + const q = ev.target.value + let p = props.path.join('/') + p = p ? `/${p}` : '' + const url = q ? `${p}//${q}` : (p || '/') + console.log("Update search", url) + if (!props.query && q) router.push(url) + else router.replace(url) } const toggleSearchInput = () => { showSearchInput.value = !showSearchInput.value @@ -54,7 +66,9 @@ const toggleSearchInput = () => { if (input) input.focus() }) } - +watchEffect(() => { + if (props.query) showSearchInput.value = true +}) const settingsMenu = (e: Event) => { // show the context menu const items = [] @@ -69,9 +83,10 @@ const settingsMenu = (e: Event) => { items, }) } -const props = defineProps({ +const props = defineProps<{ path: Array -}) + query: string +}>() defineExpose({ toggleSearchInput,