Prune deleted folders off of breadcrumbs' longest visited (keeps current folder even if missing).

This commit is contained in:
Leo Vasanko 2023-11-20 12:18:37 -08:00
parent fa98cb9177
commit 7cc7e32c33
3 changed files with 17 additions and 1 deletions

View File

@ -34,6 +34,7 @@
import home from '@/assets/svg/home.svg' import home from '@/assets/svg/home.svg'
import { nextTick, onBeforeUpdate, ref, watchEffect } from 'vue' import { nextTick, onBeforeUpdate, ref, watchEffect } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { exists } from '@/utils/fileutil'
const router = useRouter() const router = useRouter()
@ -86,6 +87,15 @@ watchEffect(() => {
else if (props.path.length > longcut.length) { else if (props.path.length > longcut.length) {
longest.value = longcut.concat(props.path.slice(longcut.length)) longest.value = longcut.concat(props.path.slice(longcut.length))
} }
else {
// Prune deleted folders from longest
for (let i = props.path.length; i < longest.value.length; ++i) {
if (!exists(longest.value.slice(0, i + 1))) {
longest.value = longest.value.slice(0, i)
break
}
}
}
// If needed, focus primary navigation to new location // If needed, focus primary navigation to new location
if (props.primary) nextTick(() => { if (props.primary) nextTick(() => {
const act = document.activeElement as HTMLElement const act = document.activeElement as HTMLElement

View File

@ -4,7 +4,7 @@
<p v-if="!store.connected">No Connection</p> <p v-if="!store.connected">No Connection</p>
<p v-else-if="store.document.length === 0">Waiting for File List</p> <p v-else-if="store.document.length === 0">Waiting for File List</p>
<p v-else-if="store.query">No matches!</p> <p v-else-if="store.query">No matches!</p>
<p v-else-if="!store.document.some(doc => (doc.loc ? `${doc.loc}/${doc.name}` : doc.name) === props.path.join('/'))">Folder not found</p> <p v-else-if="!exists(props.path)">Folder not found</p>
<p v-else>Empty folder</p> <p v-else>Empty folder</p>
</div> </div>
</template> </template>
@ -13,6 +13,7 @@
import { defineProps } from 'vue' import { defineProps } from 'vue'
import { useMainStore } from '@/stores/main' import { useMainStore } from '@/stores/main'
import cog from '@/assets/svg/cog.svg' import cog from '@/assets/svg/cog.svg'
import { exists } from '@/utils/fileutil'
const store = useMainStore() const store = useMainStore()
const props = defineProps<{ const props = defineProps<{

View File

@ -0,0 +1,5 @@
import { useMainStore } from '@/stores/main'
const store = useMainStore()
export const exists = (path: string[]) => store.document.some(doc => (doc.loc ? `${doc.loc}/${doc.name}` : doc.name) === path.join('/'))