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: {
|
actions: {
|
||||||
setActualDocument(location: string){
|
setActualDocument(location: string){
|
||||||
this.loading = true;
|
location = decodeURIComponent(location)
|
||||||
|
this.loading = true
|
||||||
let data = this.root
|
let data = this.root
|
||||||
const dataMapped = [];
|
const actualDirArr = []
|
||||||
const locations = location.split('/').slice(1)
|
try {
|
||||||
// Get data target location
|
// Navigate to target folder
|
||||||
locations.forEach(location => {
|
for (const dirname of location.split('/').slice(1)) {
|
||||||
location = decodeURIComponent(location)
|
if (!dirname) continue
|
||||||
if(data && data.dir){
|
actualDirArr.push(dirname)
|
||||||
for (const key in data.dir) {
|
data = data.dir[dirname]
|
||||||
if(key === location) data = data.dir[key]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
} 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
|
// Transform data
|
||||||
|
const dataMapped = []
|
||||||
for (const [name, attr] of Object.entries(data.dir)) {
|
for (const [name, attr] of Object.entries(data.dir)) {
|
||||||
const {id, size, mtime, dir} = attr
|
const {id, size, mtime, dir} = attr
|
||||||
const element: Document = {
|
const element: Document = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user