Remove redundant code when resolving an avatar

This commit is contained in:
Daniel Abramov
2023-07-03 18:24:07 +01:00
parent 0105162ffa
commit e6047f8583

View File

@@ -16,7 +16,6 @@ limitations under the License.
import { useMemo, CSSProperties, HTMLAttributes, FC } from "react";
import classNames from "classnames";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { getAvatarUrl } from "./matrix-utils";
import { useClient } from "./ClientContext";
@@ -59,9 +58,6 @@ function hashStringToArrIndex(str: string, arrLength: number) {
return sum % arrLength;
}
const resolveAvatarSrc = (client: MatrixClient, src: string, size: number) =>
src?.startsWith("mxc://") ? client && getAvatarUrl(client, src, size) : src;
interface Props extends HTMLAttributes<HTMLDivElement> {
bgKey?: string;
src?: string;
@@ -101,7 +97,7 @@ export const Avatar: FC<Props> = ({
const resolvedSrc = useMemo(() => {
if (!client || !src || !sizePx) return undefined;
return resolveAvatarSrc(client, src, sizePx);
return src.startsWith("mxc://") ? getAvatarUrl(client, src, sizePx) : src;
}, [client, src, sizePx]);
const backgroundColor = useMemo(() => {