diff --git a/src/app/organisms/navigation/SideBar.jsx b/src/app/organisms/navigation/SideBar.jsx index 4a305227..fe354b59 100644 --- a/src/app/organisms/navigation/SideBar.jsx +++ b/src/app/organisms/navigation/SideBar.jsx @@ -72,7 +72,7 @@ function ProfileAvatarMenu() { return ( { + let isMounted = true; mx.getProfileInfo(mx.getUserId()).then((info) => { + if (!isMounted) return; setAvatarSrc(info.avatar_url ? mx.mxcUrlToHttp(info.avatar_url, 80, 80, 'crop') : null); }); + return () => { + isMounted = false; + }; }, [userId]); - // Sets avatar URL and updates the avatar component in profile editor to reflect new upload - function handleAvatarUpload(url) { + const handleAvatarUpload = (url) => { if (url === null) { if (confirm('Are you sure you want to remove avatar?')) { mx.setAvatarUrl(''); @@ -39,48 +47,72 @@ function ProfileEditor({ } mx.setAvatarUrl(url); setAvatarSrc(mx.mxcUrlToHttp(url, 80, 80, 'crop')); - } + }; - function saveDisplayName() { + const saveDisplayName = () => { const newDisplayName = displayNameRef.current.value; if (newDisplayName !== null && newDisplayName !== username) { mx.setDisplayName(newDisplayName); - username = newDisplayName; + setUsername(newDisplayName); setDisabled(true); + setIsEditing(false); } - } + }; - function onDisplayNameInputChange() { + const onDisplayNameInputChange = () => { setDisabled(username === displayNameRef.current.value || displayNameRef.current.value == null); - } - function cancelDisplayNameChanges() { + }; + const cancelDisplayNameChanges = () => { displayNameRef.current.value = username; onDisplayNameInputChange(); - } + setIsEditing(false); + }; - return ( + const renderForm = () => (
{ e.preventDefault(); saveDisplayName(); }} > + + + +
+ ); + + const renderInfo = () => ( +
+
+ {twemojify(username)} + setIsEditing(true)} + /> +
+ {mx.getUserId()} +
+ ); + + return ( +
handleAvatarUpload(null)} /> -
- - - -
- + { + isEditing ? renderForm() : renderInfo() + } +
); } diff --git a/src/app/organisms/profile-editor/ProfileEditor.scss b/src/app/organisms/profile-editor/ProfileEditor.scss index 9f95e5b3..2e2ef917 100644 --- a/src/app/organisms/profile-editor/ProfileEditor.scss +++ b/src/app/organisms/profile-editor/ProfileEditor.scss @@ -1,28 +1,41 @@ @use '../../partials/dir'; +@use '../../partials/flex'; .profile-editor { display: flex; - align-items: flex-start; + align-items: flex-end; } -.profile-editor__input-wrapper { - flex: 1; - min-width: 0; - margin-top: 10px; - +.profile-editor__info, +.profile-editor__form { + @extend .cp-fx__item-one; + @include dir.side(margin, var(--sp-loose), 0); display: flex; - align-items: flex-end; +} + +.profile-editor__info { + flex-direction: column; + & > div:first-child { + display: flex; + align-items: center; + } + .ic-btn { + margin: 0 var(--sp-extra-tight); + } +} + +.profile-editor__form { + margin-top: 10px; flex-wrap: wrap; + align-items: flex-end; & > .input-container { - flex: 1; + @extend .cp-fx__item-one; } & > button { height: 46px; margin-top: var(--sp-normal); - } - - & > * { @include dir.side(margin, var(--sp-normal), 0); } + } \ No newline at end of file diff --git a/src/app/organisms/settings/Settings.jsx b/src/app/organisms/settings/Settings.jsx index 84013cc9..cb41f023 100644 --- a/src/app/organisms/settings/Settings.jsx +++ b/src/app/organisms/settings/Settings.jsx @@ -306,7 +306,7 @@ function Settings() { Settings} + title={User settings} contentOptions={( <>