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 2 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
12 changes: 11 additions & 1 deletion src/common/pages/submit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { useUpdateApi } from "./api/update";
import "./_index.scss";
import { SubmitVideoAttachments } from "./submit-video-attachments";
import { useThreeSpeakMigrationAdapter } from "./hooks/three-speak-migration-adapter";
import { useEntryCache } from "../../core/caches/entries-cache";

interface MatchProps {
match: MatchType;
Expand Down Expand Up @@ -133,12 +134,19 @@ export function Submit(props: PageProps & MatchProps) {
setTags([...tags, community]);
});

const { data } = useEntryCache(
"",
props.match.params.username?.replace("@", ""),
props.match.params.permlink
);
dkildar marked this conversation as resolved.
Show resolved Hide resolved

useEntryDetector(props.match, props.history, (entry) => {
if (entry) {
setTitle(entry.title);
setTags([...new Set(entry.json_metadata?.tags ?? [])]);
setBody(entry.body);
setDescription(entry.json_metadata?.description ?? postBodySummary(body, 200));
data?.json_metadata?.image && setSelectedThumbnail(data?.json_metadata?.image[0]);
setEditingEntry(entry);
threeSpeakManager.setIsEditing(true);
} else if (editingEntry) {
Expand Down Expand Up @@ -244,7 +252,9 @@ export function Submit(props: PageProps & MatchProps) {
_updateTimer = setTimeout(() => {
const { thumbnails } = extractMetaData(body);
setPreview({ title, tags, body, description });
setThumbnails(thumbnails ?? []);
const existingImages = data.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