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
|
@ -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