From e9dfad6828be9754f14c4e3e2f5ba2e1d22a7760 Mon Sep 17 00:00:00 2001
From: Tamara Steinwender <tamara.steinwender@tugraz.at>
Date: Wed, 27 Jan 2021 12:05:35 +0100
Subject: [PATCH] Fix endless loop in filehandling demo

---
 packages/file-handling/src/dbp-nextcloud-file-picker.js | 2 +-
 packages/file-handling/src/file-sink.js                 | 2 +-
 packages/file-handling/src/file-source.js               | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/packages/file-handling/src/dbp-nextcloud-file-picker.js b/packages/file-handling/src/dbp-nextcloud-file-picker.js
index 426b2753..158af262 100644
--- a/packages/file-handling/src/dbp-nextcloud-file-picker.js
+++ b/packages/file-handling/src/dbp-nextcloud-file-picker.js
@@ -374,7 +374,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                 console.error(error.message);
 
                 // on Error: try to reload with home directory
-                if ((path !== "/" || path !== "") && this.webDavClient !== null && error.message.search("401") === -1) {
+                if ((path !== "/" && path !== "") && this.webDavClient !== null && error.message.search("401") === -1) {
                     console.log("error in load directory");
                     this.directoryPath = "";
                     this.loadDirectory("");
diff --git a/packages/file-handling/src/file-sink.js b/packages/file-handling/src/file-sink.js
index 2662e768..fec3f127 100644
--- a/packages/file-handling/src/file-sink.js
+++ b/packages/file-handling/src/file-sink.js
@@ -200,7 +200,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
 
 
         //check if default destination is set
-        if (this.defaultSink !== '' && this.firstOpen) {
+        if (this.defaultSink !== '' && typeof this.defaultSink !== 'undefined'  && this.firstOpen) {
             this.activeDestination = this.defaultSink;
             this.nextcloudDir = this.nextcloudDefaultDir;
             if (this._('#nextcloud-file-picker').webDavClient !== null) {
diff --git a/packages/file-handling/src/file-source.js b/packages/file-handling/src/file-source.js
index 1bdf9341..1119e56e 100644
--- a/packages/file-handling/src/file-source.js
+++ b/packages/file-handling/src/file-source.js
@@ -368,12 +368,12 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
 
 
         //check if default source is set
-        if (this.defaultSink !== '' && this.firstOpen) {
-            this.activeDestination = this.defaultSink;
+        if (this.defaultSource !== '' && typeof this.defaultSource !== 'undefined' && this.firstOpen) {
+            this.activeDestination = this.defaultSource;
             this.nextcloudDir = this.nextcloudDefaultDir;
             if (this._('#nextcloud-file-picker').webDavClient !== null) {
                 this._('#nextcloud-file-picker').loadDirectory(this.nextcloudDefaultDir);
-                console.log("load default nextcloud source");
+                console.log("load default nextcloud source", this.defaultSource);
             }
             this.firstOpen = false;
         }
-- 
GitLab