diff --git a/CHANGELOG.md b/CHANGELOG.md index 2515af23..712040c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Version 1.1.2 -- Profile banners. Cached after first load. +- Profile banners. Support's Commet's format. ## Version 1.1.1 diff --git a/src/app/features/settings/account/Profile.tsx b/src/app/features/settings/account/Profile.tsx index 3a61c6cc..23bff743 100644 --- a/src/app/features/settings/account/Profile.tsx +++ b/src/app/features/settings/account/Profile.tsx @@ -214,6 +214,179 @@ function ProfileAvatar({ profile, userId }: ProfileProps) { ); } +function ProfileBanner({ profile, userId }: ProfileProps) { + const mx = useMatrixClient(); + const useAuthentication = useMediaAuthentication(); + const [alertRemove, setAlertRemove] = useState(false); + + const [stagedUrl, setStagedUrl] = useState(); + const [isRemoving, setIsRemoving] = useState(false); + + const bannerUrl = profile.bannerUrl + ? mxcUrlToHttp(mx, profile.bannerUrl, useAuthentication) ?? undefined + : undefined; + + useEffect(() => { + if (bannerUrl) { + setStagedUrl(undefined); + } + }, [bannerUrl]); + + 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 handlePick = useCallback(() => { + setIsRemoving(false); + setStagedUrl(undefined); + pickFile('image/*'); + }, [pickFile]); + + const handleRemoveUpload = useCallback(() => { + setImageFile(undefined); + }, []); + + const handleUploaded = useCallback( + (upload: UploadSuccess) => { + const { mxc } = upload; + + if (imageFileURL) setStagedUrl(imageFileURL); + + mx.setExtendedProfileProperty?.("chat.commet.profile_banner", mxc); + setImageFile(undefined); + }, + [mx, imageFileURL] + ); + + const handleRemoveBanner = async () => { + setIsRemoving(true); + setStagedUrl(undefined); + setImageFile(undefined); + + await mx.setExtendedProfileProperty?.("chat.commet.profile_banner", null); + + setAlertRemove(false); + }; + + const previewUrl = isRemoving ? undefined : (imageFileURL || stagedUrl || bannerUrl); + + return ( + + Profile Banner + + } + > + + + {previewUrl ? ( + Banner Preview + ) : ( + + No Banner Set + + )} + + + {uploadAtom ? ( + + + + ) : ( + + + {bannerUrl && ( + + )} + + )} + + + }> + + setAlertRemove(false), + clickOutsideDeactivates: true, + escapeDeactivates: stopPropagation, + }} + > + +
+ + Remove Banner + + setAlertRemove(false)} radii="300"> + + +
+ + Are you sure you want to remove profile banner? + + +
+
+
+
+
+ ); +} + function ProfileDisplayName({ profile, userId }: ProfileProps) { const mx = useMatrixClient(); const capabilities = useCapabilities(); @@ -402,6 +575,7 @@ export function Profile() { direction="Column" gap="400" > +