Fix display of no avatar in avatar setting controls (#12558)
* New user profile UI in User Settings Using new Edit In Place component. * Show avatar upload error * Fix avatar upload error * Wire up errors & feedback for display name setting * Implement avatar upload / remove progress toast * Add 768px breakpoint * Fix display of no avatar in avatar setting controls There was supposed to be a person icon but it was invisible, and also would have been inappropriate for room avatars anyway. This makes it match the designs by being the same as whatever the default avatar is. * Fix room profile display * Update to released compund-web with required components / fixes * Require compound-web 4.4.0 because we do need it * Update snapshots Because of course all the auto-generated IDs of unrelated things have changed. * Fix duplicate import * Fix CSS comment * Update snapshot * Run all the tests so the ids stay the same * Start of a test for ProfileSettings * More tests * Test that a toast appears * Test ToastRack * Update snapshots * Add the usernamee control * Fix playwright tests * New compound version for editinplace fixes * Fix useId to not just generate a constant ID * Use the label in the username component * Fix widths of test boxes * Update screenshots * Put ^ back on compound-web version * Split CSS for room & user profile settings and name the components correspondingly * Fix playwright test * Update room settings screenshot * Use original screenshot instead * Add required props in test * Fix test * Also here * Update screenshots * Remove user icon ...which is unused now, as far as I can see. * Fix styling of unrelated buttons Needed to be added in other places otherwise the specificity changes. Also put the old screenshots back. * Add copyright year * Fix copyright year * Switch to useMatrixClientContext * Fix other test
This commit is contained in:
parent
cfa322cd62
commit
3c8010b719
14 changed files with 117 additions and 86 deletions
|
@ -44,6 +44,19 @@ interface IState {
|
|||
urls: string[];
|
||||
}
|
||||
|
||||
export function idNameForRoom(room: Room): string {
|
||||
const dmMapUserId = DMRoomMap.shared().getUserIdForRoomId(room.roomId);
|
||||
// If the room is a DM, we use the other user's ID for the color hash
|
||||
// in order to match the room avatar with their avatar
|
||||
if (dmMapUserId) return dmMapUserId;
|
||||
|
||||
if (room instanceof LocalRoom && room.targets.length === 1) {
|
||||
return room.targets[0].userId;
|
||||
}
|
||||
|
||||
return room.roomId;
|
||||
}
|
||||
|
||||
export default class RoomAvatar extends React.Component<IProps, IState> {
|
||||
public static defaultProps = {
|
||||
size: "36px",
|
||||
|
@ -117,17 +130,10 @@ export default class RoomAvatar extends React.Component<IProps, IState> {
|
|||
const room = this.props.room;
|
||||
|
||||
if (room) {
|
||||
const dmMapUserId = DMRoomMap.shared().getUserIdForRoomId(room.roomId);
|
||||
// If the room is a DM, we use the other user's ID for the color hash
|
||||
// in order to match the room avatar with their avatar
|
||||
if (dmMapUserId) return dmMapUserId;
|
||||
|
||||
if (room instanceof LocalRoom && room.targets.length === 1) {
|
||||
return room.targets[0].userId;
|
||||
}
|
||||
return idNameForRoom(room);
|
||||
} else {
|
||||
return this.props.oobData?.roomId;
|
||||
}
|
||||
|
||||
return this.props.room?.roomId || this.props.oobData?.roomId;
|
||||
}
|
||||
|
||||
public render(): React.ReactNode {
|
||||
|
|
|
@ -24,6 +24,7 @@ import Field from "../elements/Field";
|
|||
import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
|
||||
import AvatarSetting from "../settings/AvatarSetting";
|
||||
import { htmlSerializeFromMdIfNeeded } from "../../../editor/serialize";
|
||||
import { idNameForRoom } from "../avatars/RoomAvatar";
|
||||
|
||||
interface IProps {
|
||||
roomId: string;
|
||||
|
@ -254,6 +255,8 @@ export default class RoomProfileSettings extends React.Component<IProps, IState>
|
|||
disabled={!this.state.canSetAvatar}
|
||||
onChange={this.onAvatarChanged}
|
||||
removeAvatar={this.removeAvatar}
|
||||
placeholderId={idNameForRoom(MatrixClientPeg.safeGet().getRoom(this.props.roomId)!)}
|
||||
placeholderName={this.state.displayName}
|
||||
/>
|
||||
</div>
|
||||
{profileSettingsButtons}
|
||||
|
|
|
@ -21,6 +21,7 @@ import AccessibleButton from "../elements/AccessibleButton";
|
|||
import { mediaFromMxc } from "../../../customisations/Media";
|
||||
import { chromeFileInputFix } from "../../../utils/BrowserWorkarounds";
|
||||
import { useId } from "../../../utils/useId";
|
||||
import BaseAvatar from "../avatars/BaseAvatar";
|
||||
|
||||
interface IProps {
|
||||
/**
|
||||
|
@ -51,12 +52,30 @@ interface IProps {
|
|||
* The alt text for the avatar
|
||||
*/
|
||||
avatarAltText: string;
|
||||
|
||||
/**
|
||||
* String to use for computing the colour of the placeholder avatar if no avatar is set
|
||||
*/
|
||||
placeholderId: string;
|
||||
|
||||
/**
|
||||
* String to use for the placeholder display if no avatar is set
|
||||
*/
|
||||
placeholderName: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Component for setting or removing an avatar on something (eg. a user or a room)
|
||||
*/
|
||||
const AvatarSetting: React.FC<IProps> = ({ avatar, avatarAltText, onChange, removeAvatar, disabled }) => {
|
||||
const AvatarSetting: React.FC<IProps> = ({
|
||||
avatar,
|
||||
avatarAltText,
|
||||
onChange,
|
||||
removeAvatar,
|
||||
disabled,
|
||||
placeholderId,
|
||||
placeholderName,
|
||||
}) => {
|
||||
const fileInputRef = createRef<HTMLInputElement>();
|
||||
|
||||
// Real URL that we can supply to the img element, either a data URL or whatever mediaFromMxc gives
|
||||
|
@ -98,7 +117,9 @@ const AvatarSetting: React.FC<IProps> = ({ avatar, avatarAltText, onChange, remo
|
|||
aria-labelledby={disabled ? undefined : a11yId}
|
||||
// Inhibit tab stop as we have explicit upload/remove buttons
|
||||
tabIndex={-1}
|
||||
/>
|
||||
>
|
||||
<BaseAvatar idName={placeholderId} name={placeholderName} size="90px" />
|
||||
</AccessibleButton>
|
||||
);
|
||||
if (avatarURL) {
|
||||
avatarElement = (
|
||||
|
|
|
@ -19,7 +19,6 @@ import { logger } from "matrix-js-sdk/src/logger";
|
|||
import { EditInPlace, Alert } from "@vector-im/compound-web";
|
||||
|
||||
import { _t } from "../../../languageHandler";
|
||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||
import { OwnProfileStore } from "../../../stores/OwnProfileStore";
|
||||
import AvatarSetting from "./AvatarSetting";
|
||||
import PosthogTrackers from "../../../PosthogTrackers";
|
||||
|
@ -29,6 +28,7 @@ import InlineSpinner from "../elements/InlineSpinner";
|
|||
import UserIdentifierCustomisations from "../../../customisations/UserIdentifier";
|
||||
import { useId } from "../../../utils/useId";
|
||||
import CopyableText from "../elements/CopyableText";
|
||||
import { useMatrixClientContext } from "../../../contexts/MatrixClientContext";
|
||||
|
||||
const SpinnerToast: React.FC = ({ children }) => (
|
||||
<>
|
||||
|
@ -68,28 +68,30 @@ const UserProfileSettings: React.FC = () => {
|
|||
|
||||
const toastRack = useToastContext();
|
||||
|
||||
const client = useMatrixClientContext();
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
const mediaConfig = await MatrixClientPeg.safeGet().getMediaConfig();
|
||||
const mediaConfig = await client.getMediaConfig();
|
||||
setMaxUploadSize(mediaConfig["m.upload.size"]);
|
||||
} catch (e) {
|
||||
logger.warn("Failed to get media config", e);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
}, [client]);
|
||||
|
||||
const onAvatarRemove = useCallback(async () => {
|
||||
const removeToast = toastRack.displayToast(
|
||||
<SpinnerToast>{_t("settings|general|avatar_remove_progress")}</SpinnerToast>,
|
||||
);
|
||||
try {
|
||||
await MatrixClientPeg.safeGet().setAvatarUrl(""); // use empty string as Synapse 500s on undefined
|
||||
await client.setAvatarUrl(""); // use empty string as Synapse 500s on undefined
|
||||
setAvatarURL("");
|
||||
} finally {
|
||||
removeToast();
|
||||
}
|
||||
}, [toastRack]);
|
||||
}, [toastRack, client]);
|
||||
|
||||
const onAvatarChange = useCallback(
|
||||
async (avatarFile: File) => {
|
||||
|
@ -102,7 +104,6 @@ const UserProfileSettings: React.FC = () => {
|
|||
);
|
||||
try {
|
||||
setAvatarError(false);
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
const { content_uri: uri } = await client.uploadContent(avatarFile);
|
||||
await client.setAvatarUrl(uri);
|
||||
setAvatarURL(uri);
|
||||
|
@ -112,7 +113,7 @@ const UserProfileSettings: React.FC = () => {
|
|||
removeToast();
|
||||
}
|
||||
},
|
||||
[toastRack],
|
||||
[toastRack, client],
|
||||
);
|
||||
|
||||
const onDisplayNameChanged = useCallback((e: ChangeEvent<HTMLInputElement>) => {
|
||||
|
@ -126,19 +127,19 @@ const UserProfileSettings: React.FC = () => {
|
|||
const onDisplayNameSave = useCallback(async (): Promise<void> => {
|
||||
try {
|
||||
setDisplayNameError(false);
|
||||
await MatrixClientPeg.safeGet().setDisplayName(displayName);
|
||||
await client.setDisplayName(displayName);
|
||||
setInitialDisplayName(displayName);
|
||||
} catch (e) {
|
||||
setDisplayNameError(true);
|
||||
}
|
||||
}, [displayName]);
|
||||
}, [displayName, client]);
|
||||
|
||||
const userIdentifier = useMemo(
|
||||
() =>
|
||||
UserIdentifierCustomisations.getDisplayUserIdentifier(MatrixClientPeg.safeGet().getSafeUserId(), {
|
||||
UserIdentifierCustomisations.getDisplayUserIdentifier(client.getSafeUserId(), {
|
||||
withDisplayName: true,
|
||||
}),
|
||||
[],
|
||||
[client],
|
||||
);
|
||||
|
||||
return (
|
||||
|
@ -151,6 +152,8 @@ const UserProfileSettings: React.FC = () => {
|
|||
avatarAltText={_t("common|user_avatar")}
|
||||
onChange={onAvatarChange}
|
||||
removeAvatar={onAvatarRemove}
|
||||
placeholderName={displayName}
|
||||
placeholderId={client.getUserId() ?? ""}
|
||||
/>
|
||||
<EditInPlace
|
||||
className="mx_UserProfileSettings_profile_displayName"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue