Skip to content

Commit

Permalink
Merge pull request #1480 from ecency/bug/thumbnail
Browse files Browse the repository at this point in the history
Thumbnails bugfix
  • Loading branch information
feruzm authored Oct 17, 2023
2 parents e8cf594 + 1a98436 commit a47c4c0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/common/pages/submit/api/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export function useUpdateApi(history: History, onClear: () => void) {
tags,
description,
selectionTouched,
selectedThumbnail
selectedThumbnail,
images: json_metadata.image
}),
{ tags },
{ description }
Expand Down
8 changes: 7 additions & 1 deletion src/common/pages/submit/functions/build-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export function buildMetadata({
description,
selectedThumbnail,
selectionTouched,
videoMetadata
videoMetadata,
images
}: {
tags: string[];
title: string;
Expand All @@ -20,10 +21,15 @@ export function buildMetadata({
selectedThumbnail?: string;
selectionTouched: boolean;
videoMetadata?: ThreeSpeakVideo;
images?: string[];
}) {
const { thumbnails, ...meta } = extractMetaData(body);
let localThumbnail = ls.get("draft_selected_image");

if (images?.length) {
meta.image = [...images, ...(meta.image || [])];
}

if (meta.image) {
if (selectionTouched && selectedThumbnail) {
meta.image = [selectedThumbnail, ...meta.image!.splice(0, 9)];
Expand Down
5 changes: 4 additions & 1 deletion src/common/pages/submit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export function Submit(props: PageProps & MatchProps) {
setTags([...new Set(entry.json_metadata?.tags ?? [])]);
setBody(entry.body);
setDescription(entry.json_metadata?.description ?? postBodySummary(body, 200));
entry?.json_metadata?.image && setSelectedThumbnail(entry?.json_metadata?.image[0]);
setEditingEntry(entry);
threeSpeakManager.setIsEditing(true);
} else if (editingEntry) {
Expand Down Expand Up @@ -248,7 +249,9 @@ export function Submit(props: PageProps & MatchProps) {
_updateTimer = setTimeout(() => {
const { thumbnails } = extractMetaData(body);
setPreview({ title, tags, body, description });
setThumbnails(thumbnails ?? []);
const existingImages = editingEntry?.json_metadata.image ?? [];
const newThumbnails = thumbnails ? [...existingImages, ...thumbnails] : existingImages;
setThumbnails([...new Set(newThumbnails)]);
if (editingEntry === null) {
setLocalDraft({ title, tags, body, description });
}
Expand Down
1 change: 1 addition & 0 deletions src/common/store/entries/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface JsonMetadata {
format?: string;
original_author?: string;
original_permlink?: string;
image?: string[];
}

export interface Entry {
Expand Down

0 comments on commit a47c4c0

Please sign in to comment.