From 055a7cd6dea93b8859efc008dda9f6b3edd47ee1 Mon Sep 17 00:00:00 2001
From: Christina Toegl <toegl@tugraz.at>
Date: Thu, 11 Nov 2021 10:08:00 +0100
Subject: [PATCH] Fix problem with missing session storage username for recent
 files

---
 .../file-handling/src/nextcloud-file-picker.js   | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/packages/file-handling/src/nextcloud-file-picker.js b/packages/file-handling/src/nextcloud-file-picker.js
index 7ddee119..87b48fdc 100644
--- a/packages/file-handling/src/nextcloud-file-picker.js
+++ b/packages/file-handling/src/nextcloud-file-picker.js
@@ -453,6 +453,8 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                         }
                     );
 
+                    this.userName = userName;
+
                     this.isPickerActive = true;
                     this.loadDirectory(this.directoryPath);
                 } catch (e) {
@@ -693,8 +695,10 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                     this.statusText = "";
                     this.tabulatorTable.setData(dataObject);
 
-                    //this.tabulatorTable.querySelector("div.tabulator-tableHolder > div.tabulator-placeholder > span").innerText = i18n.t('nextcloud-file-picker.no-favorites');
-                    this._('#directory-content-table').querySelector("div.tabulator-tableHolder > div.tabulator-placeholder > span").innerText = i18n.t('nextcloud-file-picker.no-favorites');
+                    if (this._('#directory-content-table').querySelector("div.tabulator-tableHolder > div.tabulator-placeholder > span")) {
+                        //this.tabulatorTable.querySelector("div.tabulator-tableHolder > div.tabulator-placeholder > span").innerText = i18n.t('nextcloud-file-picker.no-favorites');
+                        this._('#directory-content-table').querySelector("div.tabulator-tableHolder > div.tabulator-placeholder > span").innerText = i18n.t('nextcloud-file-picker.no-favorites');
+                    }
 
                     this.isPickerActive = true;
                     this._(".nextcloud-content").scrollTop = 0;
@@ -751,7 +755,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
         date.setMonth(date.getMonth() - 3);
         let searchDate = date.toISOString().split('.')[0] + 'Z';
 
-        if (this.webDavClient === null) {
+        if (this.webDavClient === null || this.userName === null) {
             // client is broken reload try to reset & reconnect
             this.tabulatorTable.clearData();
             this.webDavClient = null;
@@ -826,6 +830,12 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                     this.tabulatorTable.setSort([
                         {column: "lastmod", dir: "desc"}
                     ]);
+
+                    if (this._('#directory-content-table').querySelector("div.tabulator-tableHolder > div.tabulator-placeholder > span")) {
+                        //this.tabulatorTable.querySelector("div.tabulator-tableHolder > div.tabulator-placeholder > span").innerText = i18n.t('nextcloud-file-picker.no-recent-files');
+                        this._('#directory-content-table').querySelector("div.tabulator-tableHolder > div.tabulator-placeholder > span").innerText = i18n.t('nextcloud-file-picker.no-recent-files');
+                    }
+
                     this.isPickerActive = true;
                     this._(".nextcloud-content").scrollTop = 0;
                     this._("#download-button").setAttribute("disabled", "true");
-- 
GitLab