diff --git a/.changeset/improved_description_ui.md b/.changeset/improved_description_ui.md new file mode 100644 index 00000000..3aa2f0c8 --- /dev/null +++ b/.changeset/improved_description_ui.md @@ -0,0 +1,5 @@ +--- +sable: patch +--- + +Improved the UI of file descriptions diff --git a/src/app/components/RenderMessageContent.tsx b/src/app/components/RenderMessageContent.tsx index 6811b116..5fcfb472 100644 --- a/src/app/components/RenderMessageContent.tsx +++ b/src/app/components/RenderMessageContent.tsx @@ -2,10 +2,10 @@ import { memo, useMemo, useCallback } from 'react'; import { MsgType } from '$types/matrix-sdk'; import { testMatrixTo } from '$plugins/matrix-to'; import { useSetting } from '$state/hooks/settings'; -import { settingsAtom } from '$state/settings'; +import { settingsAtom, CaptionPosition } from '$state/settings'; import { HTMLReactParserOptions } from 'html-react-parser'; import { Opts } from 'linkifyjs'; -import { config } from 'folds'; +import { Box, config } from 'folds'; import { AudioContent, DownloadFile, @@ -74,6 +74,13 @@ function RenderMessageContentInternal({ const content = useMemo(() => getContent(), [getContent]); const [autoplayGifs] = useSetting(settingsAtom, 'autoplayGifs'); + const [captionPosition] = useSetting(settingsAtom, 'captionPosition'); + const captionPositionMap = { + [CaptionPosition.Above]: 'column-reverse', + [CaptionPosition.Below]: 'column', + [CaptionPosition.Inline]: 'row', + [CaptionPosition.Hidden]: 'row', + } satisfies Record; const renderBody = useCallback( (props: any) => ( @@ -112,54 +119,89 @@ function RenderMessageContentInternal({ ); const renderCaption = () => { + if (captionPosition === CaptionPosition.Hidden) return null; if (content.filename && content.filename !== content.body) { + if (captionPosition !== CaptionPosition.Inline) + return ( + + ); return ( - + + + ); } return null; }; const renderFile = () => ( - <> - ( - ( - +
+ ( + ( + } + /> + )} + renderAsTextFile={() => ( + } + /> + )} + > + } + info={info} /> - )} - renderAsTextFile={() => ( - } - /> - )} - > - - - )} - outlined={outlineAttachment} - /> + + )} + outlined={outlineAttachment} + /> +
{renderCaption()} - + ); if (msgType === MsgType.Text) { @@ -205,79 +247,100 @@ function RenderMessageContentInternal({ (typeof content.url === 'string' && content.url.toLowerCase().includes('gif')); return ( - <> - ( - { - if (isGif && !autoplayGifs && p.src) { - return ( - - - - ); - } - return ; - }} - renderViewer={(p) => } - /> - )} - outlined={outlineAttachment} - /> +
+
+ ( + { + if (isGif && !autoplayGifs && p.src) { + return ( + + + + ); + } + return ; + }} + renderViewer={(p) => } + /> + )} + outlined={outlineAttachment} + /> +
{renderCaption()} - +
); } if (msgType === MsgType.Video) { return ( - <> - ( - ( - ( - {body} - )} - /> - ) - : undefined - } - renderVideo={(p) =>