Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Thumbnails bugfix #1480

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -139,6 +139,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 @@ -244,7 +245,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