import { JoinRule } from 'matrix-js-sdk'; import { AvatarFallback, AvatarImage, Icon, Icons, color } from 'folds'; import React, { ComponentProps, ReactEventHandler, ReactNode, forwardRef, useState } from 'react'; import * as css from './RoomAvatar.css'; import { joinRuleToIconSrc } from '../../utils/room'; import colorMXID from '../../../util/colorMXID'; type RoomAvatarProps = { roomId: string; src?: string; alt?: string; renderFallback: () => ReactNode; }; export function RoomAvatar({ roomId, src, alt, renderFallback }: RoomAvatarProps) { const [error, setError] = useState(false); const handleLoad: ReactEventHandler = (evt) => { evt.currentTarget.setAttribute('data-image-loaded', 'true'); }; if (!src || error) { return ( {renderFallback()} ); } return ( setError(true)} onLoad={handleLoad} draggable={false} /> ); } export const RoomIcon = forwardRef< SVGSVGElement, Omit, 'src'> & { joinRule: JoinRule; space?: boolean; } >(({ joinRule, space, ...props }, ref) => ( ));