MCPcopy Create free account
hub / github.com/dailydotdev/apps / FaceImage

Function FaceImage

packages/shared/src/features/patchy/PatchyRailIcon.tsx:188–237  ·  view source on GitHub ↗
({
  face,
  motion,
  motionKey,
}: {
  face: PatchyFace;
  motion?: PatchyMotion | null;
  motionKey?: string;
})

Source from the content-addressed store, hash-verified

186// an empty circle. The image can fail before hydration attaches onError, so
187// it is also checked once it mounts.
188const FaceImage = ({
189 face,
190 motion,
191 motionKey,
192}: {
193 face: PatchyFace;
194 motion?: PatchyMotion | null;
195 motionKey?: string;
196}): ReactElement => {
197 const { faceImage } = getPatchyConfig();
198 const [failed, setFailed] = useState<Partial<Record<PatchyFace, boolean>>>(
199 {},
200 );
201 const shown = failed[face] ? 'neutral' : face;
202 const onFail = useCallback(() => {
203 if (shown !== 'neutral') {
204 setFailed((current) => ({ ...current, [shown]: true }));
205 }
206 }, [shown]);
207 const ref = useCallback(
208 (image: HTMLImageElement | null) => {
209 if (image?.complete && image.naturalWidth === 0) {
210 onFail();
211 }
212 },
213 [onFail],
214 );
215 const isOneShot = isPatchyOneShotFace(shown);
216 const src = usePatchyFaceUrl(faceImage[shown], motionKey ?? '', isOneShot);
217 let key = 'still';
218 if (isOneShot) {
219 key = `${shown}-${motionKey}`;
220 } else if (motion) {
221 key = `${motionKey}-${motion}`;
222 }
223 return (
224 <img
225 key={key}
226 ref={ref}
227 src={src}
228 alt=""
229 className={classNames(
230 'size-full object-cover',
231 motion && motionClass[motion],
232 )}
233 draggable={false}
234 onError={onFail}
235 />
236 );
237};
238
239// Patchy's face in the Streak tab, in place of the flame badge. The glyph box
240// stays the shared 24px so the tab keeps its height; the face overflows it a

Callers

nothing calls this directly

Calls 3

getPatchyConfigFunction · 0.90
isPatchyOneShotFaceFunction · 0.90
usePatchyFaceUrlFunction · 0.90

Tested by

no test coverage detected