({
face,
motion,
motionKey,
}: {
face: PatchyFace;
motion?: PatchyMotion | null;
motionKey?: string;
})
| 149 | // an empty circle. The image can fail before hydration attaches onError, so |
| 150 | // it is also checked once it mounts. |
| 151 | const FaceImage = ({ |
| 152 | face, |
| 153 | motion, |
| 154 | motionKey, |
| 155 | }: { |
| 156 | face: PatchyFace; |
| 157 | motion?: PatchyMotion | null; |
| 158 | motionKey?: string; |
| 159 | }): ReactElement => { |
| 160 | const { faceImage } = getPatchyConfig(); |
| 161 | const [failed, setFailed] = useState<Partial<Record<PatchyFace, boolean>>>( |
| 162 | {}, |
| 163 | ); |
| 164 | const shown = failed[face] ? 'neutral' : face; |
| 165 | const onFail = useCallback(() => { |
| 166 | if (shown !== 'neutral') { |
| 167 | setFailed((current) => ({ ...current, [shown]: true })); |
| 168 | } |
| 169 | }, [shown]); |
| 170 | const ref = useCallback( |
| 171 | (image: HTMLImageElement | null) => { |
| 172 | if (image?.complete && image.naturalWidth === 0) { |
| 173 | onFail(); |
| 174 | } |
| 175 | }, |
| 176 | [onFail], |
| 177 | ); |
| 178 | return ( |
| 179 | <img |
| 180 | key={motion ? `${motionKey}-${motion}` : 'still'} |
| 181 | ref={ref} |
| 182 | src={faceImage[shown]} |
| 183 | alt="" |
| 184 | className={classNames( |
| 185 | 'size-full object-cover', |
| 186 | motion && motionClass[motion], |
| 187 | )} |
| 188 | draggable={false} |
| 189 | onError={onFail} |
| 190 | /> |
| 191 | ); |
| 192 | }; |
| 193 | |
| 194 | // Patchy's face in the Streak tab, in place of the flame badge. The glyph box |
| 195 | // stays the shared 24px so the tab keeps its height; the face overflows it a |
nothing calls this directly
no test coverage detected