({ community }: Props)
| 16 | } |
| 17 | |
| 18 | export default function CommunityIcon({ community }: Props) { |
| 19 | const [loaded, setLoaded] = useState(false); |
| 20 | |
| 21 | useEffect(() => { |
| 22 | let mounted = true; |
| 23 | setLoaded(false); |
| 24 | if (community.logoSquareUrl) { |
| 25 | preload(community.logoSquareUrl) |
| 26 | .then(() => { |
| 27 | if (mounted) { |
| 28 | setLoaded(true); |
| 29 | } |
| 30 | }) |
| 31 | .catch((exception) => { |
| 32 | if (mounted) { |
| 33 | setLoaded(false); |
| 34 | } |
| 35 | }); |
| 36 | } |
| 37 | return () => { |
| 38 | mounted = false; |
| 39 | }; |
| 40 | }, []); |
| 41 | |
| 42 | if (community.logoSquareUrl && loaded) { |
| 43 | return ( |
| 44 | <img |
| 45 | className={styles.icon} |
| 46 | src={community.logoSquareUrl} |
| 47 | alt={community.description || community.name || 'Community'} |
| 48 | width={36} |
| 49 | height={36} |
| 50 | /> |
| 51 | ); |
| 52 | } |
| 53 | const backgroundColor = community.brandColor || 'black'; |
| 54 | const fontColor = pickTextColorBasedOnBgColor( |
| 55 | backgroundColor, |
| 56 | 'white', |
| 57 | 'black' |
| 58 | ); |
| 59 | return ( |
| 60 | <div |
| 61 | className={styles.icon} |
| 62 | style={{ color: fontColor, background: backgroundColor }} |
| 63 | > |
| 64 | {getLetter(community.name)} |
| 65 | </div> |
| 66 | ); |
| 67 | } |
nothing calls this directly
no test coverage detected