diff --git a/cista-front/src/stores/documents.ts b/cista-front/src/stores/documents.ts index bbc43f7..d04d008 100644 --- a/cista-front/src/stores/documents.ts +++ b/cista-front/src/stores/documents.ts @@ -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 = {