Skip to content

Commit 5f5b102

Browse files
committed
small bugfixes
1 parent 9b69b6a commit 5f5b102

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

frontend/src/features/collections/collection-edit-dialog.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import renderGeneral from "./edit-dialog/general-section";
1717
import checkChanged from "./edit-dialog/helpers/check-changed";
1818
import submitTask from "./edit-dialog/helpers/submit-task";
1919
import { type CollectionShareSettings } from "./edit-dialog/sharing-section";
20+
import { type SelectCollectionPage } from "./select-collection-page";
2021

2122
import { BtrixElement } from "@/classes/BtrixElement";
2223
import type { Dialog } from "@/components/ui/dialog";
@@ -108,8 +109,8 @@ export class CollectionEdit extends BtrixElement {
108109
@queryAsync("btrix-collection-share-settings")
109110
readonly shareSettings?: Promise<CollectionShareSettings>;
110111

111-
// @query("btrix-collection-thumbnail-select")
112-
// readonly thumbnailSelector?: CollectionThumbnailSelect;
112+
@query("btrix-select-collection-page")
113+
readonly thumbnailSelector?: SelectCollectionPage;
113114

114115
@query("btrix-collection-snapshot-preview")
115116
public readonly thumbnailPreview?: CollectionSnapshotPreview | null;

frontend/src/features/collections/edit-dialog/general-section.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,8 @@ export default function renderGeneral(this: CollectionEdit) {
6868
mode="thumbnail"
6969
.collection=${this.collection}
7070
.collectionId=${this.collection.id}
71-
.initialSelectedSnapshot=${this.selectedSnapshot
72-
? {
73-
pageId: this.selectedSnapshot.urlPageId,
74-
ts: this.selectedSnapshot.urlTs,
75-
status: 200,
76-
}
77-
: undefined}
71+
.selectedSnapshot=${sourceToSnapshot(this.selectedSnapshot) ??
72+
undefined}
7873
@btrix-select=${async (e: CustomEvent<SelectSnapshotDetail>) => {
7974
if (!e.detail.item) return;
8075
await this.updateComplete;
@@ -221,7 +216,11 @@ function renderThumbnails(this: CollectionEdit) {
221216
<div class="row-start-1 text-xs text-neutral-500">
222217
${msg("Page Thumbnail")}
223218
</div>
224-
${renderPageThumbnail.bind(this)(this.collection?.thumbnail?.path)}
219+
${renderPageThumbnail.bind(this)(
220+
this.defaultThumbnailName == null
221+
? this.collection?.thumbnail?.path
222+
: null,
223+
)}
225224
<div class="sticky left-0 row-start-1 text-xs text-neutral-600">
226225
${msg("Placeholder")}
227226
</div>
@@ -257,9 +256,6 @@ function renderPageThumbnail(
257256
this.blobIsLoaded = false;
258257
});
259258

260-
const enabled =
261-
(!!this.selectedSnapshot && this.blobIsLoaded) || !!initialPath;
262-
263259
console.log({
264260
selectedSnapshot: this.selectedSnapshot,
265261
blobIsLoaded: !!this.blobIsLoaded,
@@ -270,15 +266,13 @@ function renderPageThumbnail(
270266
<button
271267
class=${clsx(
272268
isSelected ? tw`ring-2 ring-blue-300` : tw` ring-1 ring-stone-600/10`,
273-
tw`row-start-2 aspect-video min-w-48 overflow-hidden rounded transition-all`,
274-
enabled && tw`hover:ring-2 hover:ring-blue-300`,
269+
tw`row-start-2 aspect-video min-w-48 overflow-hidden rounded transition-all hover:ring-2 hover:ring-blue-300`,
275270
)}
276-
?disabled=${!enabled}
277271
role="radio"
278272
type="button"
279273
aria-checked=${isSelected}
280274
@click=${() => {
281-
if (!enabled) return;
275+
this.thumbnailSelector?.input?.focus();
282276
this.defaultThumbnailName = null;
283277
void this.checkChanged.bind(this)();
284278
}}
@@ -302,7 +296,7 @@ function renderPageThumbnail(
302296
replaySrc=${`/replay/?${query}#view=pages`}
303297
.snapshot=${sourceToSnapshot(this.selectedSnapshot)}
304298
?noSpinner=${!!initialPath &&
305-
isEqual(this.selectedSnapshot, this.collection?.thumbnailSource)}
299+
!isEqual(this.selectedSnapshot, this.collection?.thumbnailSource)}
306300
@btrix-validate=${({
307301
detail: { valid },
308302
}: CustomEvent<BtrixValidateDetails>) => {

frontend/src/features/collections/select-collection-page.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import clsx from "clsx";
99
import { html, type PropertyValues } from "lit";
1010
import { customElement, property, query, state } from "lit/decorators.js";
1111
import { when } from "lit/directives/when.js";
12+
import { isEqual } from "lodash";
1213
import debounce from "lodash/fp/debounce";
1314
import filter from "lodash/fp/filter";
1415
import flow from "lodash/fp/flow";
@@ -69,11 +70,8 @@ export class SelectCollectionPage extends BtrixElement {
6970
@state()
7071
private selectedPage?: Page;
7172

72-
@property({ type: Object })
73-
public initialSelectedSnapshot?: Snapshot;
74-
75-
@state()
76-
public selectedSnapshot?: Snapshot = this.initialSelectedSnapshot;
73+
@property({ type: Object, hasChanged: (a, b) => !isEqual(a, b) })
74+
public selectedSnapshot?: Snapshot;
7775

7876
@state()
7977
private pageUrlError?: string;
@@ -82,7 +80,7 @@ export class SelectCollectionPage extends BtrixElement {
8280
private readonly combobox?: Combobox | null;
8381

8482
@query("#pageUrlInput")
85-
private readonly input?: SlInput | null;
83+
readonly input?: SlInput | null;
8684

8785
private get url() {
8886
return this.mode === "homepage"

0 commit comments

Comments
 (0)