From a949b5096a51ef0e1fe143732e224719bf3a472d Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Sun, 28 Apr 2024 17:40:05 +0200 Subject: [PATCH] style(post): translate link types, anonymous displayName --- src/components/comment-media/comment-media.tsx | 16 +++++++++------- src/components/post/post.tsx | 18 ++++++++++-------- src/lib/utils/media-utils.ts | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/components/comment-media/comment-media.tsx b/src/components/comment-media/comment-media.tsx index 899ca88f..55ec8e76 100644 --- a/src/components/comment-media/comment-media.tsx +++ b/src/components/comment-media/comment-media.tsx @@ -1,11 +1,11 @@ import React from 'react'; -import styles from './comment-media.module.css'; -import { CommentMediaInfo, getHasThumbnail } from '../../lib/utils/media-utils'; -import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame'; -import Embed, { canEmbed } from '../embed'; import { useTranslation } from 'react-i18next'; -import useWindowWidth from '../../hooks/use-window-width'; +import styles from './comment-media.module.css'; +import { CommentMediaInfo, getDisplayMediaInfoType, getHasThumbnail } from '../../lib/utils/media-utils'; import { getHostname } from '../../lib/utils/url-utils'; +import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame'; +import useWindowWidth from '../../hooks/use-window-width'; +import Embed, { canEmbed } from '../embed'; interface MediaProps { commentMediaInfo?: CommentMediaInfo; @@ -129,7 +129,7 @@ const Media = ({ commentMediaInfo, isReply, setShowThumbnail }: MediaProps) => { {url && url.length > 30 ? url.slice(0, 30) + '...' : url} {' '} - ({type}) + ({getDisplayMediaInfoType(type, t)}) )} {isMobile && (type === 'iframe' || type === 'video' || type === 'audio') && ( @@ -144,8 +144,10 @@ const Media = ({ commentMediaInfo, isReply, setShowThumbnail }: MediaProps) => { }; const CommentMedia = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWidth, showThumbnail, setShowThumbnail }: MediaProps) => { + const { t } = useTranslation(); const isMobile = useWindowWidth() < 640; const { type, url } = commentMediaInfo || {}; + return ( @@ -160,7 +162,7 @@ const CommentMedia = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, link setShowThumbnail={setShowThumbnail} /> )} - {isMobile && type &&
{type}
} + {isMobile && type &&
{getDisplayMediaInfoType(type, t)}
}
{!showThumbnail && }
diff --git a/src/components/post/post.tsx b/src/components/post/post.tsx index ff426650..09a34523 100644 --- a/src/components/post/post.tsx +++ b/src/components/post/post.tsx @@ -70,7 +70,7 @@ const PostDesktop = ({ post, roles, showAllReplies }: PostProps) => { {url.length > 30 ? url.slice(0, 30) + '...' : url} {' '} - ({type}) + ({type && getDisplayMediaInfoType(type, t)}) {!showThumbnail && (type === 'iframe' || type === 'video' || type === 'audio') && ( {' '} @@ -112,7 +112,7 @@ const PostDesktop = ({ post, roles, showAllReplies }: PostProps) => { {title && {displayTitle} } - {displayName || 'Anonymous'} + {displayName || _.capitalize(t('anonymous'))} {authorRole && ` ## Board ${authorRole}`}{' '} {!(isDescription || isRules) && (u/{shortAddress}) } @@ -226,7 +226,7 @@ const ReplyDesktop = ({ reply, roles }: PostProps) => { - {displayName || 'Anonymous'} + {displayName || _.capitalize(t('anonymous'))} {authorRole && ` ## Board ${authorRole}`}{' '} (u/{shortAddress}) @@ -268,7 +268,8 @@ const ReplyDesktop = ({ reply, roles }: PostProps) => { {t('link')}:{' '} {link.length > 30 ? link?.slice(0, 30) + '...' : link} - + {' '} + ({type && getDisplayMediaInfoType(type, t)}) {!showThumbnail && (type === 'iframe' || type === 'video' || type === 'audio') && ( {' '} @@ -362,7 +363,7 @@ const PostMobile = ({ post, roles, showAllReplies }: PostProps) => { - {displayName || 'Anonymous'} + {displayName || _.capitalize(t('anonymous'))} {authorRole && ` ## Board ${authorRole}`}{' '} {!(isDescription || isRules) && (u/{shortAddress || address?.slice(0, 12) + '...'})} @@ -468,7 +469,7 @@ const ReplyMobile = ({ reply, roles }: PostProps) => { ... - {displayName || 'Anonymous'} + {displayName || _.capitalize(t('anonymous'))} {authorRole && ` ## Board ${authorRole}`}{' '} (u/{shortAddress}) @@ -528,11 +529,12 @@ const Post = ({ post, showAllReplies = false }: PostProps) => { const isMobile = useWindowWidth() < 640; return (
+ {showReplyModal && }
{isMobile ? ( - + ) : ( - + )}
diff --git a/src/lib/utils/media-utils.ts b/src/lib/utils/media-utils.ts index 86c6f3b4..2fd0a2f0 100644 --- a/src/lib/utils/media-utils.ts +++ b/src/lib/utils/media-utils.ts @@ -11,6 +11,21 @@ export interface CommentMediaInfo { patternThumbnailUrl?: string; } +export const getDisplayMediaInfoType = (type: string, t: any) => { + switch (type) { + case 'image': + return t('image'); + case 'iframe': + return t('iframe'); + case 'video': + return t('video'); + case 'audio': + return t('audio'); + default: + return t('webpage'); + } +}; + export const getHasThumbnail = (commentMediaInfo: CommentMediaInfo | undefined, link: string | undefined): boolean => { const iframeThumbnail = commentMediaInfo?.patternThumbnailUrl || commentMediaInfo?.thumbnail; return link &&