From 6c90547ce5ccd53ba8e9dcbff9173bd31cb319ee Mon Sep 17 00:00:00 2001 From: Shea Duma Date: Thu, 5 Mar 2026 10:29:51 +0200 Subject: [PATCH 1/7] added basic plaintext image description adjacent to the text input --- .../upload-card/UploadCardRenderer.tsx | 16 ++++++++- src/app/features/room/RoomInput.tsx | 33 +++++++++++++++++-- src/app/features/room/msgContent.ts | 6 +++- src/app/state/room/roomInputDrafts.ts | 1 + 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/app/components/upload-card/UploadCardRenderer.tsx b/src/app/components/upload-card/UploadCardRenderer.tsx index 8ff54ff0..fabe8772 100644 --- a/src/app/components/upload-card/UploadCardRenderer.tsx +++ b/src/app/components/upload-card/UploadCardRenderer.tsx @@ -98,6 +98,7 @@ type UploadCardRendererProps = { isEncrypted?: boolean; fileItem: TUploadItem; setMetadata: (fileItem: TUploadItem, metadata: TUploadMetadata) => void; + setDescription: (fileContent: TUploadContent) => void; onRemove: (file: TUploadContent) => void; onComplete?: (upload: UploadSuccess) => void; }; @@ -105,6 +106,7 @@ export function UploadCardRenderer({ isEncrypted, fileItem, setMetadata, + setDescription, onRemove, onComplete, }: UploadCardRendererProps) { @@ -130,13 +132,15 @@ export function UploadCardRenderer({ cancelUpload(); onRemove(file); }; + const handleDescription = () => { + setDescription(file); + }; useEffect(() => { if (upload.status === UploadStatus.Success) { onComplete?.(upload); } }, [upload, onComplete]); - return ( Retry )} + + + + ( const [uploadBoard, setUploadBoard] = useState(true); const [selectedFiles, setSelectedFiles] = useAtom(roomIdToUploadItemsAtomFamily(roomId)); + const [describedFile, setDescribedFile] = useState(undefined); const uploadFamilyObserverAtom = createUploadFamilyObserverAtom( roomUploadAtomFamily, selectedFiles.map((f) => f.file) @@ -214,6 +215,7 @@ export const RoomInput = forwardRef( metadata: { markedAsSpoiler: false, }, + body: 'aaa', }) ); } else { @@ -225,6 +227,7 @@ export const RoomInput = forwardRef( metadata: { markedAsSpoiler: false, }, + body: 'aaa', }) ); } @@ -303,7 +306,12 @@ export const RoomInput = forwardRef( }, [setSelectedFiles] ); - + const handleDescription = useCallback( + (fileItem: TUploadContent) => { + setDescribedFile(fileItem); + }, + [setDescribedFile] + ); const handleRemoveUpload = useCallback( (upload: TUploadContent | TUploadContent[]) => { const uploads = Array.isArray(upload) ? upload : [upload]; @@ -331,6 +339,14 @@ export const RoomInput = forwardRef( const fileItem = selectedFiles.find((f) => f.file === upload.file); if (!fileItem) throw new Error('Broken upload'); + if (fileItem.file === describedFile) { + fileItem.body = plaintext; + resetEditor(editor); + resetEditorHistory(editor); + setInputKey((prev) => prev + 1); + sendTypingStatus(false); + setDescribedFile(undefined); + } if (fileItem.file.type.startsWith('image')) { return getImageMsgContent(mx, fileItem, upload.mxc); } @@ -364,6 +380,7 @@ export const RoomInput = forwardRef( const submit = useCallback(async () => { uploadBoardHandlers.current?.handleSend(); + if (describedFile !== undefined) return; const commandName = getBeginCommand(editor); let plainText = toPlainText(editor.children, isMarkdown).trim(); let customHtml = trimCustomHtml( @@ -436,13 +453,24 @@ export const RoomInput = forwardRef( resetEditorHistory(editor); setInputKey((prev) => prev + 1); sendTypingStatus(false); + setDescribedFile(undefined); try { await mx.sendMessage(roomId, content as any); } catch (error) { log.error('failed to send message', { roomId }, error); } - }, [mx, roomId, editor, replyDraft, sendTypingStatus, setReplyDraft, isMarkdown, commands]); + }, [ + mx, + roomId, + editor, + replyDraft, + describedFile, + sendTypingStatus, + setReplyDraft, + isMarkdown, + commands, + ]); const handleKeyDown: KeyboardEventHandler = useCallback( (evt) => { @@ -546,6 +574,7 @@ export const RoomInput = forwardRef( fileItem={fileItem} setMetadata={handleFileMetadata} onRemove={handleRemoveUpload} + setDescription={handleDescription} /> ))} diff --git a/src/app/features/room/msgContent.ts b/src/app/features/room/msgContent.ts index fa3b94cb..61b1306c 100644 --- a/src/app/features/room/msgContent.ts +++ b/src/app/features/room/msgContent.ts @@ -77,6 +77,7 @@ export const getImageMsgContent = async ( } else { content.url = mxc; } + if (item.body?.length && item.body.length > 0) content.body = item.body; return content; }; @@ -126,6 +127,7 @@ export const getVideoMsgContent = async ( } else { content.url = mxc; } + if (item.body?.length && item.body.length > 0) content.body = item.body; return content; }; @@ -148,6 +150,7 @@ export const getAudioMsgContent = (item: TUploadItem, mxc: string): IContent => } else { content.url = mxc; } + if (item.body?.length && item.body.length > 0) content.body = item.body; return content; }; @@ -155,8 +158,8 @@ export const getFileMsgContent = (item: TUploadItem, mxc: string): IContent => { const { file, encInfo } = item; const content: IContent = { msgtype: MsgType.File, - body: file.name, filename: file.name, + body: file.name, info: { mimetype: file.type, size: file.size, @@ -170,5 +173,6 @@ export const getFileMsgContent = (item: TUploadItem, mxc: string): IContent => { } else { content.url = mxc; } + if (item.body?.length && item.body.length > 0) content.body = item.body; return content; }; diff --git a/src/app/state/room/roomInputDrafts.ts b/src/app/state/room/roomInputDrafts.ts index f5cdd84a..abb93d1d 100644 --- a/src/app/state/room/roomInputDrafts.ts +++ b/src/app/state/room/roomInputDrafts.ts @@ -16,6 +16,7 @@ export type TUploadItem = { originalFile: TUploadContent; metadata: TUploadMetadata; encInfo: EncryptedAttachmentInfo | undefined; + body?: string; }; export type TUploadListAtom = ReturnType>; From 7bbda3450444d1fe26de5d9eeb91cbdcfdfa98b4 Mon Sep 17 00:00:00 2001 From: Shea Duma Date: Fri, 6 Mar 2026 04:51:27 +0200 Subject: [PATCH 2/7] added per item text inputs --- .../upload-card/UploadCardRenderer.tsx | 26 +- .../UploadDescriptionEditor.css.tsx | 28 ++ .../upload-card/UploadDescriptionEditor.tsx | 253 ++++++++++++++++++ src/app/features/room/RoomInput.tsx | 53 ++-- src/app/features/room/msgContent.ts | 32 ++- src/app/state/room/roomInputDrafts.ts | 2 + 6 files changed, 350 insertions(+), 44 deletions(-) create mode 100644 src/app/components/upload-card/UploadDescriptionEditor.css.tsx create mode 100644 src/app/components/upload-card/UploadDescriptionEditor.tsx diff --git a/src/app/components/upload-card/UploadCardRenderer.tsx b/src/app/components/upload-card/UploadCardRenderer.tsx index fabe8772..f4020f13 100644 --- a/src/app/components/upload-card/UploadCardRenderer.tsx +++ b/src/app/components/upload-card/UploadCardRenderer.tsx @@ -1,4 +1,4 @@ -import { ReactNode, useEffect } from 'react'; +import { ReactNode, useEffect, useState } from 'react'; import { Box, Chip, Icon, IconButton, Icons, Text, color, config, toRem } from 'folds'; import { UploadStatus, UploadSuccess, useBindUploadAtom } from '$state/upload'; import { useMatrixClient } from '$hooks/useMatrixClient'; @@ -8,6 +8,7 @@ import { roomUploadAtomFamily, TUploadItem, TUploadMetadata } from '$state/room/ import { useObjectURL } from '$hooks/useObjectURL'; import { useMediaConfig } from '$hooks/useMediaConfig'; import { UploadCard, UploadCardError, UploadCardProgress } from './UploadCard'; +import { DescriptionEditor } from './UploadDescriptionEditor'; type PreviewImageProps = { fileItem: TUploadItem; @@ -98,7 +99,7 @@ type UploadCardRendererProps = { isEncrypted?: boolean; fileItem: TUploadItem; setMetadata: (fileItem: TUploadItem, metadata: TUploadMetadata) => void; - setDescription: (fileContent: TUploadContent) => void; + setDesc: (fileItem: TUploadItem, body: string, formatted_body: string) => void; onRemove: (file: TUploadContent) => void; onComplete?: (upload: UploadSuccess) => void; }; @@ -106,7 +107,7 @@ export function UploadCardRenderer({ isEncrypted, fileItem, setMetadata, - setDescription, + setDesc, onRemove, onComplete, }: UploadCardRendererProps) { @@ -120,6 +121,8 @@ export function UploadCardRenderer({ const { file } = upload; const fileSizeExceeded = file.size >= allowSize; + const [isDescribed, setIsDescribed] = useState(false); + if (upload.status === UploadStatus.Idle && !fileSizeExceeded) { startUpload(); } @@ -132,9 +135,6 @@ export function UploadCardRenderer({ cancelUpload(); onRemove(file); }; - const handleDescription = () => { - setDescription(file); - }; useEffect(() => { if (upload.status === UploadStatus.Success) { @@ -160,13 +160,15 @@ export function UploadCardRenderer({ )} { + setIsDescribed(!isDescribed); + }} aria-label="Add Upload Description" variant="SurfaceVariant" radii="Pill" size="300" > - + )} + {isDescribed && ( + { + setDesc(fileItem, htmlBio, htmlBio); + }} + /> + )} } > diff --git a/src/app/components/upload-card/UploadDescriptionEditor.css.tsx b/src/app/components/upload-card/UploadDescriptionEditor.css.tsx new file mode 100644 index 00000000..d456b718 --- /dev/null +++ b/src/app/components/upload-card/UploadDescriptionEditor.css.tsx @@ -0,0 +1,28 @@ +import { style, globalStyle } from '@vanilla-extract/css'; +import { config } from 'folds'; + +export const BioEditorContainer = style({ + backgroundColor: 'var(--sable-bg-container)', + borderRadius: config.radii.R400, + overflow: 'hidden', +}); + +globalStyle(`${BioEditorContainer} div[class*="EditorTextarea"]`, { + backgroundColor: 'var(--sable-bg-container) !important', + border: 'none !important', +}); + +globalStyle(`${BioEditorContainer} [class*="Toolbar"]`, { + backgroundColor: 'var(--sable-bg-container) !important', + padding: 'var(--space-S100) !important', + borderTop: '1px solid var(--sable-outline-variant) !important', +}); + +globalStyle(`${BioEditorContainer} [class*="Toolbar"] button`, { + backgroundColor: 'transparent !important', + boxShadow: 'none !important', +}); + +globalStyle(`${BioEditorContainer} [class*="Toolbar"] button:hover`, { + backgroundColor: 'var(--sable-surface-variant) !important', +}); diff --git a/src/app/components/upload-card/UploadDescriptionEditor.tsx b/src/app/components/upload-card/UploadDescriptionEditor.tsx new file mode 100644 index 00000000..b702cefd --- /dev/null +++ b/src/app/components/upload-card/UploadDescriptionEditor.tsx @@ -0,0 +1,253 @@ +import { KeyboardEventHandler, useCallback, useEffect, useState, useRef } from 'react'; +import { + Box, + Chip, + Icon, + IconButton, + Icons, + Line, + PopOut, + RectCords, + Spinner, + Text, + config, +} from 'folds'; +import { Editor, Transforms } from 'slate'; +import { ReactEditor } from 'slate-react'; +import { isKeyHotkey } from 'is-hotkey'; +import { + AutocompletePrefix, + AutocompleteQuery, + CustomEditor, + EmoticonAutocomplete, + Toolbar, + createEmoticonElement, + getAutocompleteQuery, + getPrevWorldRange, + htmlToEditorInput, + plainToEditorInput, + moveCursor, + toMatrixCustomHTML, + toPlainText, + trimCustomHtml, + useEditor, +} from '$components/editor'; +import { useSetting } from '$state/hooks/settings'; +import { settingsAtom } from '$state/settings'; +import { UseStateProvider } from '$components/UseStateProvider'; +import { EmojiBoard } from '$components/emoji-board'; +import { mobileOrTablet } from '$utils/user-agent'; +import * as css from './UploadDescriptionEditor.css'; + +type BioEditorProps = { + value?: string | any; + isSaving?: boolean; + imagePackRooms?: any[]; + onSave: (htmlContent: string) => void; +}; + +export function DescriptionEditor({ value, isSaving, imagePackRooms, onSave }: BioEditorProps) { + const editor = useEditor(); + const [enterForNewline] = useSetting(settingsAtom, 'enterForNewline'); + const [isMarkdown] = useSetting(settingsAtom, 'isMarkdown'); + const [toolbar, setToolbar] = useState(false); + + const [autocompleteQuery, setAutocompleteQuery] = + useState>(); + const [hasChanged, setHasChanged] = useState(false); + + const prevValue = useRef(value); + const initialized = useRef(false); + const handleSave = useCallback(() => { + const plainText = toPlainText(editor.children, isMarkdown).trim(); + + const customHtml = trimCustomHtml( + toMatrixCustomHTML(editor.children, { + allowTextFormatting: true, + allowBlockMarkdown: isMarkdown, + allowInlineMarkdown: isMarkdown, + }) + ); + + onSave(customHtml || plainText); + setHasChanged(false); + }, [editor, isMarkdown, onSave]); + + useEffect(() => { + const valueChanged = prevValue.current !== value; + const isFirstValidLoad = !initialized.current && value !== undefined; + + if (valueChanged || isFirstValidLoad) { + prevValue.current = value; + + let normalizedValue = value; + if ( + typeof normalizedValue === 'object' && + normalizedValue !== null && + 'formatted_body' in normalizedValue + ) { + normalizedValue = normalizedValue.formatted_body; + } + + const safeValue = typeof normalizedValue === 'string' ? normalizedValue : ''; + + const incomingPlainText = toPlainText( + htmlToEditorInput(safeValue, isMarkdown), + isMarkdown + ).trim(); + const currentPlainText = toPlainText(editor.children, isMarkdown).trim(); + + if (currentPlainText === incomingPlainText && initialized.current) return; + + const isLikelyHtml = safeValue.includes('<') || safeValue.includes('>'); + const initialValue = isLikelyHtml + ? htmlToEditorInput(safeValue, isMarkdown) + : plainToEditorInput(safeValue, isMarkdown); + + editor.children = initialValue; + Editor.normalize(editor, { force: true }); + Transforms.select(editor, Editor.start(editor, [])); + + initialized.current = true; + setHasChanged(false); + } + }, [value, editor, isMarkdown]); + + const handleKeyDown: KeyboardEventHandler = useCallback( + (evt) => { + if (isKeyHotkey('mod+enter', evt) || (!enterForNewline && isKeyHotkey('enter', evt))) { + evt.preventDefault(); + handleSave(); + } + }, + [handleSave, enterForNewline] + ); + + const handleKeyUp: KeyboardEventHandler = useCallback( + (evt) => { + if (isKeyHotkey('escape', evt)) { + evt.preventDefault(); + return; + } + const prevWordRange = getPrevWorldRange(editor); + const query = prevWordRange + ? getAutocompleteQuery(editor, prevWordRange, [AutocompletePrefix.Emoticon]) + : undefined; + setAutocompleteQuery(query); + }, + [editor] + ); + + const handleCloseAutocomplete = useCallback(() => { + ReactEditor.focus(editor); + setAutocompleteQuery(undefined); + }, [editor]); + + const handleEmoticonSelect = (key: string, shortcode: string) => { + editor.insertNode(createEmoticonElement(key, shortcode)); + moveCursor(editor); + setHasChanged(true); + }; + + return ( + + + {autocompleteQuery?.prefix === AutocompletePrefix.Emoticon && ( + + )} + + + + {hasChanged && ( + : undefined + } + > + {isSaving ? 'Saving' : 'Save'} + + )} + + + setToolbar(!toolbar)} + > + + + + {(anchor: RectCords | undefined, setAnchor) => ( + + setAnchor((v) => { + if (v) { + if (!mobileOrTablet()) ReactEditor.focus(editor); + return undefined; + } + return v; + }) + } + /> + } + > + setAnchor(evt.currentTarget.getBoundingClientRect())} + > + + + + )} + + + + {toolbar && ( + + + + + )} + + } + /> + + + ); +} diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx index cef4ef2b..f0f47443 100644 --- a/src/app/features/room/RoomInput.tsx +++ b/src/app/features/room/RoomInput.tsx @@ -205,7 +205,6 @@ export const RoomInput = forwardRef( const [uploadBoard, setUploadBoard] = useState(true); const [selectedFiles, setSelectedFiles] = useAtom(roomIdToUploadItemsAtomFamily(roomId)); - const [describedFile, setDescribedFile] = useState(undefined); const uploadFamilyObserverAtom = createUploadFamilyObserverAtom( roomUploadAtomFamily, selectedFiles.map((f) => f.file) @@ -238,7 +237,6 @@ export const RoomInput = forwardRef( metadata: { markedAsSpoiler: false, }, - body: 'aaa', }) ); } else { @@ -250,7 +248,6 @@ export const RoomInput = forwardRef( metadata: { markedAsSpoiler: false, }, - body: 'aaa', }) ); } @@ -340,11 +337,15 @@ export const RoomInput = forwardRef( }, [setSelectedFiles] ); - const handleDescription = useCallback( - (fileItem: TUploadContent) => { - setDescribedFile(fileItem); + const setDesc = useCallback( + (fileItem: TUploadItem, body: string, formatted_body: string) => { + setSelectedFiles({ + type: 'REPLACE', + item: fileItem, + replacement: { ...fileItem, body, formatted_body }, + }); }, - [setDescribedFile] + [setSelectedFiles] ); const handleRemoveUpload = useCallback( (upload: TUploadContent | TUploadContent[]) => { @@ -368,19 +369,12 @@ export const RoomInput = forwardRef( }; const handleSendUpload = async (uploads: UploadSuccess[]) => { - const plaintext = toPlainText(editor.children, isMarkdown).trim(); + const plainText = toPlainText(editor.children, isMarkdown).trim(); + const contentsPromises = uploads.map(async (upload) => { const fileItem = selectedFiles.find((f) => f.file === upload.file); if (!fileItem) throw new Error('Broken upload'); - if (fileItem.file === describedFile) { - fileItem.body = plaintext; - resetEditor(editor); - resetEditorHistory(editor); - setInputKey((prev) => prev + 1); - sendTypingStatus(false); - setDescribedFile(undefined); - } if (fileItem.file.type.startsWith('image')) { return getImageMsgContent(mx, fileItem, upload.mxc); } @@ -396,7 +390,7 @@ export const RoomInput = forwardRef( const contents = fulfilledPromiseSettledResult(await Promise.allSettled(contentsPromises)); if (contents.length > 0) { - const replyContent = plaintext.length === 0 ? getReplyContent(replyDraft) : undefined; + const replyContent = plainText?.length === 0 ? getReplyContent(replyDraft) : undefined; if (replyContent) contents[0]['m.relates_to'] = replyContent; setReplyDraft(undefined); } @@ -414,7 +408,6 @@ export const RoomInput = forwardRef( const submit = useCallback(async () => { uploadBoardHandlers.current?.handleSend(); - if (describedFile !== undefined) return; const commandName = getBeginCommand(editor); let plainText = toPlainText(editor.children, isMarkdown).trim(); let customHtml = trimCustomHtml( @@ -489,7 +482,6 @@ export const RoomInput = forwardRef( setReplyDraft(undefined); sendTypingStatus(false); }; - if (scheduledTime) { try { const delayMs = computeDelayMs(scheduledTime); @@ -505,7 +497,6 @@ export const RoomInput = forwardRef( setEditingScheduledDelayId(null); setScheduledTime(null); resetInput(); - setDescribedFile(undefined); } catch { // Network/server error — leave editor and scheduled state intact for retry } @@ -516,7 +507,6 @@ export const RoomInput = forwardRef( invalidate(); setEditingScheduledDelayId(null); resetInput(); - setDescribedFile(undefined); } catch { // Cancel failed — leave state intact for retry } @@ -527,22 +517,21 @@ export const RoomInput = forwardRef( }); } }, [ + editor, + isMarkdown, mx, roomId, - room, - editor, replyDraft, - sendTypingStatus, - setReplyDraft, - describedFile, - isMarkdown, - commands, scheduledTime, - setScheduledTime, - isEncrypted, - queryClient, editingScheduledDelayId, + commands, + sendTypingStatus, + queryClient, + setReplyDraft, + isEncrypted, setEditingScheduledDelayId, + setScheduledTime, + room, ]); const handleKeyDown: KeyboardEventHandler = useCallback( @@ -682,7 +671,7 @@ export const RoomInput = forwardRef( fileItem={fileItem} setMetadata={handleFileMetadata} onRemove={handleRemoveUpload} - setDescription={handleDescription} + setDesc={setDesc} /> ))} diff --git a/src/app/features/room/msgContent.ts b/src/app/features/room/msgContent.ts index 61b1306c..3ecc0771 100644 --- a/src/app/features/room/msgContent.ts +++ b/src/app/features/room/msgContent.ts @@ -59,6 +59,8 @@ export const getImageMsgContent = async ( msgtype: MsgType.Image, filename: file.name, body: file.name, + format: 'org.matrix.custom.html', + formatted_body: file.name, [MATRIX_SPOILER_PROPERTY_NAME]: metadata.markedAsSpoiler, }; if (imgEl) { @@ -77,7 +79,11 @@ export const getImageMsgContent = async ( } else { content.url = mxc; } - if (item.body?.length && item.body.length > 0) content.body = item.body; + if (item.body && item.body.length > 0) content.body = item.body; + if (item.formatted_body && item.formatted_body.length > 0) { + content.format = 'org.matrix.custom.html'; + content.formatted_body = item.formatted_body; + } return content; }; @@ -95,6 +101,8 @@ export const getVideoMsgContent = async ( msgtype: MsgType.Video, filename: file.name, body: file.name, + format: 'org.matrix.custom.html', + formatted_body: file.name, [MATRIX_SPOILER_PROPERTY_NAME]: metadata.markedAsSpoiler, }; if (videoEl) { @@ -127,7 +135,11 @@ export const getVideoMsgContent = async ( } else { content.url = mxc; } - if (item.body?.length && item.body.length > 0) content.body = item.body; + if (item.body && item.body.length > 0) content.body = item.body; + if (item.formatted_body && item.formatted_body.length > 0) { + content.format = 'org.matrix.custom.html'; + content.formatted_body = item.formatted_body; + } return content; }; @@ -137,6 +149,8 @@ export const getAudioMsgContent = (item: TUploadItem, mxc: string): IContent => msgtype: MsgType.Audio, filename: file.name, body: file.name, + format: 'org.matrix.custom.html', + formatted_body: file.name, info: { mimetype: file.type, size: file.size, @@ -150,7 +164,11 @@ export const getAudioMsgContent = (item: TUploadItem, mxc: string): IContent => } else { content.url = mxc; } - if (item.body?.length && item.body.length > 0) content.body = item.body; + if (item.body && item.body.length > 0) content.body = item.body; + if (item.formatted_body && item.formatted_body.length > 0) { + content.format = 'org.matrix.custom.html'; + content.formatted_body = item.formatted_body; + } return content; }; @@ -160,6 +178,8 @@ export const getFileMsgContent = (item: TUploadItem, mxc: string): IContent => { msgtype: MsgType.File, filename: file.name, body: file.name, + format: 'org.matrix.custom.html', + formatted_body: file.name, info: { mimetype: file.type, size: file.size, @@ -173,6 +193,10 @@ export const getFileMsgContent = (item: TUploadItem, mxc: string): IContent => { } else { content.url = mxc; } - if (item.body?.length && item.body.length > 0) content.body = item.body; + if (item.body && item.body.length > 0) content.body = item.body; + if (item.formatted_body && item.formatted_body.length > 0) { + content.format = 'org.matrix.custom.html'; + content.formatted_body = item.formatted_body; + } return content; }; diff --git a/src/app/state/room/roomInputDrafts.ts b/src/app/state/room/roomInputDrafts.ts index abb93d1d..51c3cfaf 100644 --- a/src/app/state/room/roomInputDrafts.ts +++ b/src/app/state/room/roomInputDrafts.ts @@ -17,6 +17,8 @@ export type TUploadItem = { metadata: TUploadMetadata; encInfo: EncryptedAttachmentInfo | undefined; body?: string; + format?: string; + formatted_body?: string; }; export type TUploadListAtom = ReturnType>; From 19de8c9adfd34e79986fc719c8d2dffb8fba9683 Mon Sep 17 00:00:00 2001 From: Shea Duma Date: Fri, 6 Mar 2026 05:59:11 +0200 Subject: [PATCH 3/7] added desc preview when appropriate --- .../upload-card/UploadCardRenderer.tsx | 27 +++++++++-- .../UploadDescriptionEditor.css.tsx | 10 ++-- .../upload-card/UploadDescriptionEditor.tsx | 47 ++++++++++--------- 3 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/app/components/upload-card/UploadCardRenderer.tsx b/src/app/components/upload-card/UploadCardRenderer.tsx index f4020f13..1d068575 100644 --- a/src/app/components/upload-card/UploadCardRenderer.tsx +++ b/src/app/components/upload-card/UploadCardRenderer.tsx @@ -1,5 +1,5 @@ import { ReactNode, useEffect, useState } from 'react'; -import { Box, Chip, Icon, IconButton, Icons, Text, color, config, toRem } from 'folds'; +import { Box, Chip, Icon, IconButton, Icons, Text, Tooltip, color, config, toRem } from 'folds'; import { UploadStatus, UploadSuccess, useBindUploadAtom } from '$state/upload'; import { useMatrixClient } from '$hooks/useMatrixClient'; import { TUploadContent } from '$utils/matrix'; @@ -216,12 +216,31 @@ export function UploadCardRenderer({ )} {isDescribed && ( { - setDesc(fileItem, htmlBio, htmlBio); + value={fileItem.formatted_body || fileItem.body} + onSave={(plainText, htmlContent) => { + setDesc(fileItem, plainText, htmlContent); + setIsDescribed(false); }} /> )} + {!isDescribed && fileItem.body && fileItem.body.length > 0 && ( + + + {fileItem.body} + + + )} } > diff --git a/src/app/components/upload-card/UploadDescriptionEditor.css.tsx b/src/app/components/upload-card/UploadDescriptionEditor.css.tsx index d456b718..04037a7b 100644 --- a/src/app/components/upload-card/UploadDescriptionEditor.css.tsx +++ b/src/app/components/upload-card/UploadDescriptionEditor.css.tsx @@ -1,28 +1,28 @@ import { style, globalStyle } from '@vanilla-extract/css'; import { config } from 'folds'; -export const BioEditorContainer = style({ +export const DescriptionEditorContainer = style({ backgroundColor: 'var(--sable-bg-container)', borderRadius: config.radii.R400, overflow: 'hidden', }); -globalStyle(`${BioEditorContainer} div[class*="EditorTextarea"]`, { +globalStyle(`${DescriptionEditorContainer} div[class*="EditorTextarea"]`, { backgroundColor: 'var(--sable-bg-container) !important', border: 'none !important', }); -globalStyle(`${BioEditorContainer} [class*="Toolbar"]`, { +globalStyle(`${DescriptionEditorContainer} [class*="Toolbar"]`, { backgroundColor: 'var(--sable-bg-container) !important', padding: 'var(--space-S100) !important', borderTop: '1px solid var(--sable-outline-variant) !important', }); -globalStyle(`${BioEditorContainer} [class*="Toolbar"] button`, { +globalStyle(`${DescriptionEditorContainer} [class*="Toolbar"] button`, { backgroundColor: 'transparent !important', boxShadow: 'none !important', }); -globalStyle(`${BioEditorContainer} [class*="Toolbar"] button:hover`, { +globalStyle(`${DescriptionEditorContainer} [class*="Toolbar"] button:hover`, { backgroundColor: 'var(--sable-surface-variant) !important', }); diff --git a/src/app/components/upload-card/UploadDescriptionEditor.tsx b/src/app/components/upload-card/UploadDescriptionEditor.tsx index b702cefd..4893ba38 100644 --- a/src/app/components/upload-card/UploadDescriptionEditor.tsx +++ b/src/app/components/upload-card/UploadDescriptionEditor.tsx @@ -39,14 +39,19 @@ import { EmojiBoard } from '$components/emoji-board'; import { mobileOrTablet } from '$utils/user-agent'; import * as css from './UploadDescriptionEditor.css'; -type BioEditorProps = { +type DescriptionEditorProps = { value?: string | any; isSaving?: boolean; imagePackRooms?: any[]; - onSave: (htmlContent: string) => void; + onSave: (plaintext: string, htmlContent: string) => void; }; -export function DescriptionEditor({ value, isSaving, imagePackRooms, onSave }: BioEditorProps) { +export function DescriptionEditor({ + value, + isSaving, + imagePackRooms, + onSave, +}: DescriptionEditorProps) { const editor = useEditor(); const [enterForNewline] = useSetting(settingsAtom, 'enterForNewline'); const [isMarkdown] = useSetting(settingsAtom, 'isMarkdown'); @@ -54,7 +59,6 @@ export function DescriptionEditor({ value, isSaving, imagePackRooms, onSave }: B const [autocompleteQuery, setAutocompleteQuery] = useState>(); - const [hasChanged, setHasChanged] = useState(false); const prevValue = useRef(value); const initialized = useRef(false); @@ -69,8 +73,7 @@ export function DescriptionEditor({ value, isSaving, imagePackRooms, onSave }: B }) ); - onSave(customHtml || plainText); - setHasChanged(false); + onSave(plainText, customHtml || plainText); }, [editor, isMarkdown, onSave]); useEffect(() => { @@ -109,7 +112,6 @@ export function DescriptionEditor({ value, isSaving, imagePackRooms, onSave }: B Transforms.select(editor, Editor.start(editor, [])); initialized.current = true; - setHasChanged(false); } }, [value, editor, isMarkdown]); @@ -146,12 +148,15 @@ export function DescriptionEditor({ value, isSaving, imagePackRooms, onSave }: B const handleEmoticonSelect = (key: string, shortcode: string) => { editor.insertNode(createEmoticonElement(key, shortcode)); moveCursor(editor); - setHasChanged(true); }; return ( - + {autocompleteQuery?.prefix === AutocompletePrefix.Emoticon && ( - {hasChanged && ( - : undefined - } - > - {isSaving ? 'Saving' : 'Save'} - - )} + : undefined + } + > + {isSaving ? 'Saving' : 'Save'} + Date: Fri, 6 Mar 2026 06:24:54 +0200 Subject: [PATCH 4/7] fixed scrolling issue --- src/app/components/upload-card/UploadCardRenderer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/upload-card/UploadCardRenderer.tsx b/src/app/components/upload-card/UploadCardRenderer.tsx index 1d068575..b15a91c6 100644 --- a/src/app/components/upload-card/UploadCardRenderer.tsx +++ b/src/app/components/upload-card/UploadCardRenderer.tsx @@ -227,12 +227,12 @@ export function UploadCardRenderer({ Date: Fri, 6 Mar 2026 06:53:23 +0200 Subject: [PATCH 5/7] added knopes file thing idk --- .../feat_adding_basic_file_descriptions.md | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .changeset/feat_adding_basic_file_descriptions.md diff --git a/.changeset/feat_adding_basic_file_descriptions.md b/.changeset/feat_adding_basic_file_descriptions.md new file mode 100644 index 00000000..cb1faaea --- /dev/null +++ b/.changeset/feat_adding_basic_file_descriptions.md @@ -0,0 +1,36 @@ +--- +sable: minor +--- + +# Feat: Adding basic file descriptions + +#182 by @nushea + + + +### Description +This pr adds basic file description options, if one may choose to caption or provide additional details to an image itself. +Through this PR each item individually on the Upload Board has a chevron next to the delete button which when selected opens a text editor for setting up the caption for the item. If the editor is closed and a file has a description, a plaintext version of it will be displayed under the file. +Currently, descriptions have to be saved prior to sending a message, and selecting the chevron discards any changes as-well. + +(collapsed view when no file has a description) +image + +(collapsed view when files have descriptions) +image + +(open view when the editors are opened) +image + +#### Type of change + +- [x] New feature (non-breaking change which adds functionality) + +### Checklist: + +- [x] My code follows the style guidelines of this project +- [x] I have performed a self-review of my own code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have made corresponding changes to the documentation +- [x] My changes generate no new warnings + From 31f123893470cef9b502add54a81b4e67db848ba Mon Sep 17 00:00:00 2001 From: Shea Duma Date: Fri, 6 Mar 2026 07:01:19 +0200 Subject: [PATCH 6/7] corrected knopes thing --- .../feat_adding_basic_file_descriptions.md | 37 +------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/.changeset/feat_adding_basic_file_descriptions.md b/.changeset/feat_adding_basic_file_descriptions.md index cb1faaea..639d562a 100644 --- a/.changeset/feat_adding_basic_file_descriptions.md +++ b/.changeset/feat_adding_basic_file_descriptions.md @@ -1,36 +1 @@ ---- -sable: minor ---- - -# Feat: Adding basic file descriptions - -#182 by @nushea - - - -### Description -This pr adds basic file description options, if one may choose to caption or provide additional details to an image itself. -Through this PR each item individually on the Upload Board has a chevron next to the delete button which when selected opens a text editor for setting up the caption for the item. If the editor is closed and a file has a description, a plaintext version of it will be displayed under the file. -Currently, descriptions have to be saved prior to sending a message, and selecting the chevron discards any changes as-well. - -(collapsed view when no file has a description) -image - -(collapsed view when files have descriptions) -image - -(open view when the editors are opened) -image - -#### Type of change - -- [x] New feature (non-breaking change which adds functionality) - -### Checklist: - -- [x] My code follows the style guidelines of this project -- [x] I have performed a self-review of my own code -- [ ] I have commented my code, particularly in hard-to-understand areas -- [ ] I have made corresponding changes to the documentation -- [x] My changes generate no new warnings - +Added the ability to add descriptions to uploaded files From ed61bec48b7287de669a628f18ea99a692c6fcb8 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Thu, 5 Mar 2026 23:21:16 -0600 Subject: [PATCH 7/7] fix changeset formatting --- .changeset/feat_adding_basic_file_descriptions.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.changeset/feat_adding_basic_file_descriptions.md b/.changeset/feat_adding_basic_file_descriptions.md index 639d562a..8b6e9951 100644 --- a/.changeset/feat_adding_basic_file_descriptions.md +++ b/.changeset/feat_adding_basic_file_descriptions.md @@ -1 +1,5 @@ +--- +sable: patch +--- + Added the ability to add descriptions to uploaded files