finish implementation
This commit is contained in:
1 parent
3176a66568
commit
e4f5087091
2 files changed
+175
-1
No files matched your search
+1
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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<string>();
|
||||
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<File>();
|
||||
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 (
|
||||
<SettingTile
|
||||
title={
|
||||
<Text as="span" size="L400">
|
||||
Profile Banner
|
||||
</Text>
|
||||
}
|
||||
>
|
||||
<Box direction="Column" gap="300" grow="Yes">
|
||||
<Box
|
||||
style={{
|
||||
height: '100px',
|
||||
width: '100%',
|
||||
borderRadius: config.radii.R400,
|
||||
overflow: 'hidden',
|
||||
backgroundColor: 'var(--sable-surface-container)',
|
||||
position: 'relative',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center'
|
||||
}}
|
||||
>
|
||||
{previewUrl ? (
|
||||
<img
|
||||
src={previewUrl}
|
||||
key={previewUrl}
|
||||
style={{ width: '100%', height: '100%', objectFit: 'cover' }}
|
||||
alt="Banner Preview"
|
||||
/>
|
||||
) : (
|
||||
<Box justifyContent="Center" alignItems="Center">
|
||||
<Text priority="300" size="T200">No Banner Set</Text>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
{uploadAtom ? (
|
||||
<Box gap="200" direction="Column">
|
||||
<CompactUploadCardRenderer
|
||||
uploadAtom={uploadAtom}
|
||||
onRemove={handleRemoveUpload}
|
||||
onComplete={handleUploaded}
|
||||
/>
|
||||
</Box>
|
||||
) : (
|
||||
<Box gap="200">
|
||||
<Button
|
||||
onClick={handlePick}
|
||||
size="300"
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
outlined
|
||||
radii="300"
|
||||
>
|
||||
<Text size="B300">{bannerUrl ? 'Change Banner' : 'Upload Banner'}</Text>
|
||||
</Button>
|
||||
{bannerUrl && (
|
||||
<Button
|
||||
size="300"
|
||||
variant="Critical"
|
||||
fill="None"
|
||||
radii="300"
|
||||
onClick={() => setAlertRemove(true)}
|
||||
>
|
||||
<Text size="B300">Remove</Text>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
<Overlay open={alertRemove} backdrop={<OverlayBackdrop />}>
|
||||
<OverlayCenter>
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: () => setAlertRemove(false),
|
||||
clickOutsideDeactivates: true,
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Dialog variant="Surface">
|
||||
<Header
|
||||
style={{
|
||||
padding: `0 ${config.space.S200} 0 ${config.space.S400}`,
|
||||
borderBottomWidth: config.borderWidth.B300,
|
||||
}}
|
||||
variant="Surface"
|
||||
size="500"
|
||||
>
|
||||
<Box grow="Yes">
|
||||
<Text size="H4">Remove Banner</Text>
|
||||
</Box>
|
||||
<IconButton size="300" onClick={() => setAlertRemove(false)} radii="300">
|
||||
<Icon src={Icons.Cross} />
|
||||
</IconButton>
|
||||
</Header>
|
||||
<Box style={{ padding: config.space.S400 }} direction="Column" gap="400">
|
||||
<Text priority="400">Are you sure you want to remove profile banner?</Text>
|
||||
<Button variant="Critical" onClick={handleRemoveBanner}>
|
||||
<Text size="B400">Remove</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
</Dialog>
|
||||
</FocusTrap>
|
||||
</OverlayCenter>
|
||||
</Overlay>
|
||||
</SettingTile>
|
||||
);
|
||||
}
|
||||
|
||||
function ProfileDisplayName({ profile, userId }: ProfileProps) {
|
||||
const mx = useMatrixClient();
|
||||
const capabilities = useCapabilities();
|
||||
@@ -402,6 +575,7 @@ export function Profile() {
|
||||
direction="Column"
|
||||
gap="400"
|
||||
>
|
||||
<ProfileBanner userId={userId} profile={profile} />
|
||||
<ProfileAvatar userId={userId} profile={profile} />
|
||||
<ProfileDisplayName userId={userId} profile={profile} />
|
||||
</SequenceCard>
|
||||
|
||||
Reference in new issue
Block a user