Skip to content

Commit

Permalink
fix uploading logic & pass correct params in initial view selection d…
Browse files Browse the repository at this point in the history
…ialog
  • Loading branch information
emma-sg committed Feb 10, 2025
1 parent e422855 commit c103123
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions frontend/src/features/collections/collection-replay-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ export class CollectionStartPageDialog extends BtrixElement {
homeView === HomeView.URL &&
useThumbnail === "on" &&
this.selectedSnapshot &&
this.collection?.homeUrlPageId !== this.selectedSnapshot.pageId;
this.collection?.thumbnailSource?.urlPageId !==
this.selectedSnapshot.pageId;
// TODO get filename from rwp?
const fileName = `page-thumbnail_${this.selectedSnapshot?.pageId}.jpeg`;
let file: File | undefined;
Expand All @@ -325,12 +326,22 @@ export class CollectionStartPageDialog extends BtrixElement {

if (shouldUpload) {
try {
if (!file || !fileName) throw new Error("file or fileName missing");
await this.api.upload(
`/orgs/${this.orgId}/collections/${this.collectionId}/thumbnail?filename=${fileName}`,
file,
);
await this.updateThumbnail({ defaultThumbnailName: null });
if (!file || !fileName || !this.selectedSnapshot)
throw new Error("file or fileName missing");
const searchParams = new URLSearchParams({
filename: fileName,
sourceUrl: this.selectedSnapshot.url,
sourceTs: this.selectedSnapshot.ts,
sourcePageId: this.selectedSnapshot.pageId,
});
const tasks = [
this.api.upload(
`/orgs/${this.orgId}/collections/${this.collectionId}/thumbnail?${searchParams.toString()}`,
file,
),
this.updateThumbnail({ defaultThumbnailName: null }),
];
await Promise.all(tasks);

this.notify.toast({
message: msg("Home view and collection thumbnail updated."),
Expand Down

0 comments on commit c103123

Please sign in to comment.