From 77a47ec574a5b3e6db1d8145ec8655cd2ae46b13 Mon Sep 17 00:00:00 2001
From: emma <hi@emma.cafe>
Date: Thu, 30 Jan 2025 18:00:02 -0500
Subject: [PATCH] allow closing the dialog with the top right x icon, and fix
 an issue with initial states

---
 .../collections/collection-edit-dialog.ts         | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/frontend/src/features/collections/collection-edit-dialog.ts b/frontend/src/features/collections/collection-edit-dialog.ts
index 6be51e7def..3c563db9c2 100644
--- a/frontend/src/features/collections/collection-edit-dialog.ts
+++ b/frontend/src/features/collections/collection-edit-dialog.ts
@@ -95,7 +95,8 @@ export class CollectionEdit extends BtrixElement {
       | undefined) || null;
 
   @state()
-  selectedSnapshot: CollectionThumbnailSource | null = null;
+  selectedSnapshot: CollectionThumbnailSource | null =
+    this.collection?.thumbnailSource ?? null;
 
   @state()
   blobIsLoaded = false;
@@ -170,8 +171,12 @@ export class CollectionEdit extends BtrixElement {
     this.dirty = false;
     this.errorTab = null;
     this.blobIsLoaded = false;
-    this.selectedSnapshot = null;
-    this.defaultThumbnailName = null;
+    this.selectedSnapshot = this.collection?.thumbnailSource ?? null;
+    this.defaultThumbnailName =
+      (this.collection?.defaultThumbnailName as
+        | `${Thumbnail}`
+        | null
+        | undefined) || null;
   }
 
   protected firstUpdated(): void {
@@ -193,6 +198,10 @@ export class CollectionEdit extends BtrixElement {
           this.tab = "general";
         }}
         @sl-request-close=${(e: SlRequestCloseEvent) => {
+          if (e.detail.source === "close-button") {
+            this.onReset();
+            return;
+          }
           // Prevent accidental closes unless data has been saved
           // Closing via the close buttons is fine though, cause it resets the form first.
           if (this.dirty) e.preventDefault();