Rewrite folder selection. Needs better error handling still.
This commit is contained in:
parent
a8ea43194d
commit
d27cb2133a
|
@ -45,21 +45,28 @@ export const useDocumentStore = defineStore({
|
|||
|
||||
actions: {
|
||||
setActualDocument(location: string){
|
||||
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]
|
||||
this.loading = true
|
||||
let data = this.root
|
||||
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 = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user