Rewrite folder selection. Needs better error handling still.

This commit is contained in:
Leo Vasanko 2023-11-01 21:29:13 +00:00
parent a8ea43194d
commit d27cb2133a

View File

@ -45,21 +45,28 @@ export const useDocumentStore = defineStore({
actions: {
setActualDocument(location: string){
this.loading = true;
location = decodeURIComponent(location)
this.loading = true
let data = this.root
const dataMapped = [];
const locations = location.split('/').slice(1)
// Get data target location
locations.forEach(location => {
location = decodeURIComponent(location)
if(data && data.dir){
for (const key in data.dir) {
if(key === location) data = data.dir[key]
}
const actualDirArr = []
try {
// Navigate to target folder
for (const dirname of location.split('/').slice(1)) {
if (!dirname) continue
actualDirArr.push(dirname)
data = data.dir[dirname]
}
})
} catch (error) {
console.error("Cannot show requested folder", location, actualDirArr.join('/'), error)
}
if (data.dir === undefined) {
// Target folder not available
this.document = []
this.loading = false // ???
return
}
// Transform data
const dataMapped = []
for (const [name, attr] of Object.entries(data.dir)) {
const {id, size, mtime, dir} = attr
const element: Document = {