mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-14 11:10:29 +03:00
Add profile editor in settings
This commit is contained in:
parent
cdf421f0f1
commit
6c78060876
6 changed files with 196 additions and 0 deletions
66
src/app/molecules/profile-editor/ProfileEditor.jsx
Normal file
66
src/app/molecules/profile-editor/ProfileEditor.jsx
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import React, { useState, useRef } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import colorMXID from '../../../util/colorMXID';
|
||||
|
||||
import Button from '../../atoms/button/Button';
|
||||
import ImageUpload from '../../atoms/image-upload/ImageUpload';
|
||||
import Input from '../../atoms/input/Input';
|
||||
import Text from '../../atoms/text/Text';
|
||||
|
||||
import './ProfileEditor.scss';
|
||||
|
||||
// TODO Fix bug that prevents 'Save' button from enabling up until second changed.
|
||||
function ProfileEditor({
|
||||
userId,
|
||||
}) {
|
||||
const mx = initMatrix.matrixClient;
|
||||
const displayNameRef = useRef(null);
|
||||
const bgColor = colorMXID(userId);
|
||||
const [imageSrc, updateImgSrc] = useState(mx.mxcUrlToHttp(mx.getUser(mx.getUserId()).avatarUrl));
|
||||
const [disabled, setDisabled] = useState(true);
|
||||
|
||||
let username = mx.getUser(mx.getUserId()).displayName;
|
||||
|
||||
function handleUpload(e) {
|
||||
mx.setAvatarUrl(e.content_uri);
|
||||
updateImgSrc(mx.mxcUrlToHttp(e.content_uri));
|
||||
}
|
||||
|
||||
function saveDisplayName() {
|
||||
if (displayNameRef.current.value !== null && displayNameRef.current.value !== '') {
|
||||
mx.setDisplayName(displayNameRef.current.value);
|
||||
username = displayNameRef.current.value;
|
||||
setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
function onDisplayNameInputChange() {
|
||||
setDisabled((username === displayNameRef.current.value) || displayNameRef.current.value === '' || displayNameRef.current.value == null);
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="profile-editor">
|
||||
<ImageUpload text={username} bgColor={bgColor} imageSrc={imageSrc} onUpload={handleUpload} />
|
||||
<div className="display-name-input-container">
|
||||
<Text variant="b3">
|
||||
Display name of
|
||||
{mx.getUserId()}
|
||||
</Text>
|
||||
<Input id="display-name-input" onChange={onDisplayNameInputChange} placeholder={mx.getUser(mx.getUserId()).displayName} forwardRef={displayNameRef} />
|
||||
</div>
|
||||
<Button variant="primary" onClick={saveDisplayName} disabled={disabled}>Save</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
ProfileEditor.defaultProps = {
|
||||
userId: null,
|
||||
};
|
||||
|
||||
ProfileEditor.propTypes = {
|
||||
userId: PropTypes.string,
|
||||
};
|
||||
|
||||
export default ProfileEditor;
|
||||
24
src/app/molecules/profile-editor/ProfileEditor.scss
Normal file
24
src/app/molecules/profile-editor/ProfileEditor.scss
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
.profile-editor {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
}
|
||||
|
||||
.img-upload-container {
|
||||
margin-right: var(--sp-normal)
|
||||
}
|
||||
|
||||
.display-name-input-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-right: var(--sp-normal);
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.display-name-input-container > .text-b3 {
|
||||
margin-bottom: var(--sp-ultra-tight)
|
||||
}
|
||||
|
||||
.profile-editor > .btn-primary {
|
||||
height: 46px;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue