matrix-art

An image gallery for Matrix
git clone git://archive.git.mtrnord.blog/MTRNord/matrix-art.git
Log | Files | Refs | README | LICENSE

commit c6cd6c5806130637b84dd845fe9fc75f4cadd6bf
parent 573dc1ca59cbcbb04dede13c8f3fbd8e7d114372
Author: MTRNord <mtrnord1@gmail.com>
Date:   Thu, 27 Jan 2022 23:21:12 +0100

Fix title on post

Diffstat:
Mcomponents/FrontPageImage.tsx | 3+--
Mpages/post/[id].tsx | 15++++++++-------
2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/components/FrontPageImage.tsx b/components/FrontPageImage.tsx @@ -91,8 +91,7 @@ export default class FrontPageImage extends PureComponent<Props, State> { render_image(event: ImageEvent) { - let caption_text = event.content['m.caption'].filter(cap => { - + const caption_text = event.content['m.caption'].filter(cap => { const possible_html_caption = (cap as { body: string; mimetype: string; }); const possible_text_caption = (cap as { "m.text": string; }); return (possible_html_caption.body && possible_html_caption.mimetype === "text/html") || possible_text_caption["m.text"]; diff --git a/pages/post/[id].tsx b/pages/post/[id].tsx @@ -163,14 +163,15 @@ class Post extends PureComponent<Props, State> { } if (image_event) { - let post_title = ""; - const caption = image_event.content['m.caption'].filter((cap) => { + const post_title = image_event.content['m.caption'].filter(cap => { const possible_html_caption = (cap as { body: string; mimetype: string; }); - return possible_html_caption.body !== undefined && possible_html_caption.mimetype === "text/html"; - }); - if (caption.length > 0) { - post_title = (caption[0] as { body: string; mimetype: string; }).body; - } + const possible_text_caption = (cap as { "m.text": string; }); + return (possible_html_caption.body && possible_html_caption.mimetype === "text/html") || possible_text_caption["m.text"]; + }).map(cap => { + const possible_html_caption = (cap as { body: string; mimetype: string; }); + const possible_text_caption = (cap as { "m.text": string; }); + return (possible_html_caption.body && possible_html_caption.mimetype === "text/html") ? possible_html_caption.body : possible_text_caption["m.text"]; + })[0]; return ( <div className="min-h-full flex flex-col justify-between bg-[#fefefe]/[.95] dark:bg-[#14181E]/[.95]"> <Head>