From 8d598fdf3fdce1521d03036f7767bb3c2fe4d660 Mon Sep 17 00:00:00 2001 From: Rye Date: Wed, 18 Mar 2026 14:48:20 +0100 Subject: [PATCH] fix a few pmp editing bugs --- .../Persona/PerMessageProfileEditor.tsx | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/src/app/features/settings/Persona/PerMessageProfileEditor.tsx b/src/app/features/settings/Persona/PerMessageProfileEditor.tsx index bbfcbcde..00a0ff9f 100644 --- a/src/app/features/settings/Persona/PerMessageProfileEditor.tsx +++ b/src/app/features/settings/Persona/PerMessageProfileEditor.tsx @@ -65,6 +65,7 @@ export function PerMessageProfileEditor({ const [newDisplayName, setNewDisplayName] = useState(currentDisplayName); const [imageFile, setImageFile] = useState(); + const [imageHasChanges, setImageHasChanges] = useState(false); const [avatarMxc, setAvatarMxc] = useState(avatarMxcUrl); const imageFileURL = useObjectURL(imageFile); const avatarUrl = useMemo(() => { @@ -81,12 +82,14 @@ export function PerMessageProfileEditor({ const pickFile = useFilePicker(setImageFile, false); const handleRemoveUpload = useCallback(() => { setImageFile(undefined); + setImageHasChanges(true); }, []); const handleUploaded = useCallback( (upload: { status: string; mxc: string }) => { - if (upload && upload.status === 'success') { + if (upload?.status === 'success') { setAvatarMxc(upload.mxc); if (onChange) onChange({ id: profileId, name: newDisplayName, avatarUrl: upload.mxc }); + setImageHasChanges(true); } setImageFile(undefined); }, @@ -108,31 +111,31 @@ export function PerMessageProfileEditor({ newDisplayName !== (currentDisplayName ?? '') || newPronounsString !== currentPronounsString || hasIdChange || - !!imageFile, + imageHasChanges, [ newDisplayName, currentDisplayName, newPronounsString, currentPronounsString, hasIdChange, - imageFile, + imageHasChanges, ] ); /** - * Reset handler to reset the display name and pronouns to their current values, and clear the image file if there is one. + * handler for resetting the display name */ - const handleReset = useCallback(() => { - setNewDisplayName(currentDisplayName); + const handleDisplayNameReset = useCallback(() => { + setNewDisplayName(currentDisplayName ?? ''); + }, [currentDisplayName]); + + /** + * handler for resetting the pronouns + */ + const handlePronounsReset = useCallback(() => { setNewPronouns(currentPronouns); - setNewPronounsString( - Array.isArray(currentPronouns) - ? currentPronouns.map((p) => `${p.language ? `${p.language}:` : ''}${p.summary}`).join(', ') - : '' - ); - setChangingDisplayName(false); - setDisableSetDisplayname(false); - }, [currentDisplayName, currentPronouns]); + setNewPronounsString(currentPronounsString); + }, [currentPronouns, currentPronounsString]); /** * persisting the data :3 @@ -146,14 +149,15 @@ export function PerMessageProfileEditor({ }).then(() => { setCurrentDisplayName(newDisplayName); setCurrentPronouns(newPronouns); + setImageHasChanges(false); + setChangingDisplayName(false); + setDisableSetDisplayname(false); + if (hasIdChange) { + renamePerMessageProfile(mx, profileId, newId).then(() => { + setCurrentId(newId); + }); + } }); - if (hasIdChange) { - renamePerMessageProfile(mx, profileId, newId).then(() => { - setCurrentId(newId); - }); - } - setChangingDisplayName(false); - setDisableSetDisplayname(false); }, [mx, profileId, newDisplayName, avatarMxc, newPronouns, hasIdChange, newId]); const handleDelete = useCallback(() => { @@ -344,11 +348,11 @@ export function PerMessageProfileEditor({ aria-label={`Display name for ${profileId}`} title={`Display name for ${profileId}`} after={ - hasChanges && + newDisplayName !== (currentDisplayName ?? '') && !changingDisplayName && (