Skip to content

Commit

Permalink
fix missing type conversions
Browse files Browse the repository at this point in the history
emma-sg committed Jan 30, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f146c3e commit 1bc2ab3
Showing 4 changed files with 48 additions and 13 deletions.
15 changes: 8 additions & 7 deletions frontend/src/features/collections/collection-snapshot-preview.ts
Original file line number Diff line number Diff line change
@@ -58,22 +58,22 @@ export class CollectionSnapshotPreview extends TailwindElement {
return this.blobTask.taskComplete.then(() => this.blobTask.value);
}

// public async getBlob() {
// return (
// this.blobTask.value ??
// this.blobTask.run([this.collectionId, this.snapshot])
// );
// }

private readonly blobTask = new Task(this, {
task: async ([collectionId, snapshot], { signal }) => {
console.debug("waiting for iframe to load");
await this.iframeLoadedPromise;
if (
!collectionId ||
!snapshot?.ts ||
!snapshot.url ||
!this.iframe?.contentWindow
) {
console.debug(
"exiting early due to missing props",
collectionId,
snapshot,
this.iframe?.contentWindow,
);
return;
}

@@ -197,6 +197,7 @@ export class CollectionSnapshotPreview extends TailwindElement {
@load=${() => {
this.iframeLoaded = true;
this.iframeLoadComplete();
console.debug("iframe loaded");
}}
></iframe>
</div>
15 changes: 11 additions & 4 deletions frontend/src/features/collections/edit-dialog/general-section.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ import {
Thumbnail,
} from "../collection-thumbnail";

import { sourceToSnapshot } from "./helpers/snapshots";

import type { PublicCollection } from "@/types/collection";
import { tw } from "@/utils/tailwind";

@@ -199,8 +201,8 @@ function renderPageThumbnail(
const isSelected = this.defaultThumbnailName == null;

this.thumbnailPreview?.thumbnailBlob
.then(() => {
this.blobIsLoaded = true;
.then((value) => {
this.blobIsLoaded = !!value;
})
.catch(() => {
this.blobIsLoaded = false;
@@ -209,6 +211,12 @@ function renderPageThumbnail(
const enabled =
(!!this.selectedSnapshot && this.blobIsLoaded) || !!initialPath;

console.log({
selectedSnapshot: !!this.selectedSnapshot,
blobIsLoaded: !!this.blobIsLoaded,
initialPath: !!initialPath,
});

return html`
<button
class=${clsx(
@@ -242,8 +250,7 @@ function renderPageThumbnail(
collectionId=${this.collection!.id || ""}
view="url"
replaySrc=${`/replay/?${query}#view=pages`}
.snapshot=${this.selectedSnapshot}
?noSpinner=${!!initialPath}
.snapshot=${sourceToSnapshot(this.selectedSnapshot)}
>
</btrix-collection-snapshot-preview>
</div>
26 changes: 26 additions & 0 deletions frontend/src/features/collections/edit-dialog/helpers/snapshots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { type SnapshotItem } from "../../select-collection-start-page";

import { type CollectionThumbnailSource } from "@/types/collection";

export function sourceToSnapshot(
source: CollectionThumbnailSource | null,
): SnapshotItem | null {
if (source == null) return null;
return {
pageId: source.urlPageId,
status: 200,
ts: source.urlTs,
url: source.url,
};
}

export function snapshotToSource(
source: SnapshotItem | null,
): CollectionThumbnailSource | null {
if (source == null) return null;
return {
urlPageId: source.pageId,
urlTs: source.ts,
url: source.url,
};
}
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ import { customElement, property, state } from "lit/decorators.js";

import type { SelectSnapshotDetail } from "../select-collection-start-page";

import { snapshotToSource } from "./helpers/snapshots";

import { BtrixElement } from "@/classes/BtrixElement";
import {
type Collection,
@@ -49,8 +51,7 @@ export class CollectionThumbnailSelect extends BtrixElement {
}),
);
if (!e.detail.item) return;
const { url, ts, pageId } = e.detail.item;
this.selectedSnapshot = { url, urlTs: ts, urlPageId: pageId };
this.selectedSnapshot = snapshotToSource(e.detail.item);
}}
></btrix-select-collection-page>
</section>`;

0 comments on commit 1bc2ab3

Please sign in to comment.