diff --git a/src/app/features/settings/Account.tsx b/src/app/features/settings/Account.tsx index e4d41453..82841b97 100644 --- a/src/app/features/settings/Account.tsx +++ b/src/app/features/settings/Account.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { Box, Text, @@ -14,6 +14,9 @@ import { OverlayBackdrop, OverlayCenter, Modal, + Dialog, + Header, + config, } from 'folds'; import FocusTrap from 'focus-trap-react'; import { Page, PageContent, PageHeader } from '../../components/page'; @@ -33,6 +36,9 @@ import { useObjectURL } from '../../hooks/useObjectURL'; import { stopPropagation } from '../../utils/keyboard'; import { ImageEditor } from '../../components/image-editor'; import { ModalWide } from '../../styles/Modal.css'; +import { createUploadAtom, UploadSuccess } from '../../state/upload'; +import { CompactUploadCardRenderer } from '../../components/upload-card'; +import { useCapabilities } from '../../hooks/useCapabilities'; function MatrixId() { const mx = useMatrixClient(); @@ -67,6 +73,9 @@ type ProfileAvatarProps = { function ProfileAvatar({ profile, userId }: ProfileAvatarProps) { const mx = useMatrixClient(); const useAuthentication = useMediaAuthentication(); + const capabilities = useCapabilities(); + const [alertRemove, setAlertRemove] = useState(false); + const disableSetAvatar = capabilities['m.set_avatar_url']?.enabled === false; const defaultDisplayName = profile.displayName ?? getMxIdLocalPart(userId) ?? userId; const avatarUrl = profile.avatarUrl @@ -75,13 +84,31 @@ function ProfileAvatar({ profile, userId }: ProfileAvatarProps) { const [imageFile, setImageFile] = useState(); const imageFileURL = useObjectURL(imageFile); + const uploadAtom = useMemo(() => { + if (imageFile) return createUploadAtom(imageFile); + return undefined; + }, [imageFile]); const pickFile = useFilePicker(setImageFile, false); - const handleImageCropperClose = useCallback(() => { + const handleRemoveUpload = useCallback(() => { setImageFile(undefined); }, []); + const handleUploaded = useCallback( + (upload: UploadSuccess) => { + const { mxc } = upload; + mx.setAvatarUrl(mxc); + handleRemoveUpload(); + }, + [mx, handleRemoveUpload] + ); + + const handleRemoveAvatar = () => { + mx.setAvatarUrl(''); + setAlertRemove(false); + }; + return ( } > - - - {avatarUrl && ( - - )} + {avatarUrl && ( + + )} + + )} - {imageFileURL && ( - }> - - }> + + + + + + + + + )} + + }> + + setAlertRemove(false), + clickOutsideDeactivates: true, + escapeDeactivates: stopPropagation, + }} + > + +
- - - - - - - )} - + + Remove Avatar + + setAlertRemove(false)} radii="300"> + + +
+ + + Are you sure you want to remove profile avatar? + + + +
+
+
+
); }