diff --git a/src/common/pages/submit/api/update.ts b/src/common/pages/submit/api/update.ts index 41bd71db406..9b92e764399 100644 --- a/src/common/pages/submit/api/update.ts +++ b/src/common/pages/submit/api/update.ts @@ -60,7 +60,8 @@ export function useUpdateApi(history: History, onClear: () => void) { tags, description, selectionTouched, - selectedThumbnail + selectedThumbnail, + images: json_metadata.image }), { tags }, { description } diff --git a/src/common/pages/submit/functions/build-metadata.ts b/src/common/pages/submit/functions/build-metadata.ts index b4245ea9acf..391e0e0c924 100644 --- a/src/common/pages/submit/functions/build-metadata.ts +++ b/src/common/pages/submit/functions/build-metadata.ts @@ -11,7 +11,8 @@ export function buildMetadata({ description, selectedThumbnail, selectionTouched, - videoMetadata + videoMetadata, + images }: { tags: string[]; title: string; @@ -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)]; diff --git a/src/common/pages/submit/index.tsx b/src/common/pages/submit/index.tsx index 4db4c2a1e36..97f3e794e71 100644 --- a/src/common/pages/submit/index.tsx +++ b/src/common/pages/submit/index.tsx @@ -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) { @@ -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 }); } diff --git a/src/common/store/entries/types.ts b/src/common/store/entries/types.ts index 017a0e997ae..13dc32a814c 100644 --- a/src/common/store/entries/types.ts +++ b/src/common/store/entries/types.ts @@ -27,6 +27,7 @@ export interface JsonMetadata { format?: string; original_author?: string; original_permlink?: string; + image?: string[]; } export interface Entry {