MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / CommunityIcon

Function CommunityIcon

apps/web/ui/CommunityIcon/index.tsx:18–67  ·  view source on GitHub ↗
({ community }: Props)

Source from the content-addressed store, hash-verified

16}
17
18export 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}

Callers

nothing calls this directly

Calls 3

preloadFunction · 0.85
getLetterFunction · 0.70

Tested by

no test coverage detected