+
+
-
-
-
+
+ {uploadPromise === null && Upload}
+ {uploadPromise !== null && }
+
+
+ { (typeof imageSrc === 'string' || uploadPromise !== null) && (
+
+ )}
-
+
);
}
@@ -50,14 +75,14 @@ ImageUpload.defaultProps = {
text: null,
bgColor: 'transparent',
imageSrc: null,
- onUpload: null,
};
ImageUpload.propTypes = {
text: PropTypes.string,
bgColor: PropTypes.string,
imageSrc: PropTypes.string,
- onUpload: PropTypes.func,
+ onUpload: PropTypes.func.isRequired,
+ onRequestRemove: PropTypes.func.isRequired,
};
export default ImageUpload;
diff --git a/src/app/molecules/image-upload/ImageUpload.scss b/src/app/molecules/image-upload/ImageUpload.scss
index dbf2bace..9e0f312f 100644
--- a/src/app/molecules/image-upload/ImageUpload.scss
+++ b/src/app/molecules/image-upload/ImageUpload.scss
@@ -1,20 +1,50 @@
+.img-upload__wrapper {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+}
+
.img-upload {
display: flex;
- flex-direction: row-reverse;
- width: 80px;
- height: 80px;
-}
-
-.img-upload:hover {
cursor: pointer;
-}
+ position: relative;
-.img-upload__mask {
- mask: url('../../../../public/res/svg/avatar-clip.svg');
- -webkit-mask: url('../../../../public/res/svg/avatar-clip.svg');
-}
+ &__process {
+ width: 100%;
+ height: 100%;
+ border-radius: var(--bo-radius);
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ background-color: rgba(0, 0, 0, .6);
+
+ position: absolute;
+ left: 0;
+ right: 0;
+ z-index: 1;
+ & .text {
+ text-transform: uppercase;
+ font-weight: 600;
+ color: white;
+ }
+ &--stopped {
+ display: none;
+ }
+ & .donut-spinner {
+ border-color: rgb(255, 255, 255, .3);
+ border-left-color: white;
+ }
+ }
+ &:hover .img-upload__process--stopped {
+ display: flex;
+ }
-.img-upload__icon {
- z-index: 1;
- position: absolute;
-}
\ No newline at end of file
+
+ &__btn-cancel {
+ margin-top: var(--sp-extra-tight);
+ cursor: pointer;
+ & .text {
+ color: var(--tc-danger-normal)
+ }
+ }
+}
diff --git a/src/app/organisms/profile-editor/ProfileEditor.jsx b/src/app/organisms/profile-editor/ProfileEditor.jsx
index 61cd896d..9dd308a4 100644
--- a/src/app/organisms/profile-editor/ProfileEditor.jsx
+++ b/src/app/organisms/profile-editor/ProfileEditor.jsx
@@ -18,15 +18,22 @@ function ProfileEditor({
const mx = initMatrix.matrixClient;
const displayNameRef = useRef(null);
const bgColor = colorMXID(userId);
- const [imageSrc, updateImgSrc] = useState(mx.mxcUrlToHttp(mx.getUser(mx.getUserId()).avatarUrl));
+ const [avatarSrc, setAvatarSrc] = useState(mx.mxcUrlToHttp(mx.getUser(mx.getUserId()).avatarUrl, 80, 80, 'crop') || null);
const [disabled, setDisabled] = useState(true);
let username = mx.getUser(mx.getUserId()).displayName;
// Sets avatar URL and updates the avatar component in profile editor to reflect new upload
- function handleUpload(e) {
- mx.setAvatarUrl(e.content_uri);
- updateImgSrc(mx.mxcUrlToHttp(e.content_uri));
+ function handleAvatarUpload(url) {
+ if (url === null) {
+ if (confirm('Are you sure you want to remove avatar?')) {
+ mx.setAvatarUrl('');
+ setAvatarSrc(null);
+ }
+ return;
+ }
+ mx.setAvatarUrl(url);
+ setAvatarSrc(mx.mxcUrlToHttp(url, 80, 80, 'crop'));
}
function saveDisplayName() {
@@ -44,7 +51,13 @@ function ProfileEditor({
return (