okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221apps/host: the owner's UI and the Node App Host0b3299a01

main
1.0 KiB26 linesraw
1import { tr } from '../lib/i18n';
2import { useEffect, useState } from 'react';
3import { photoData, type ChatPhoto } from '../lib/chat-photos';
4import { IconBtn } from './ui';
5export function ChatPhotos({ photos, onRemove }: {
6    photos: ChatPhoto[];
7    onRemove?: (id: string) => void;
8}) {
9    const [images, setImages] = useState<{
10        id: string;
11        name: string;
12        url: string;
13    }[]>([]);
14    useEffect(() => {
15        let current = true;
16        void Promise.all(photos.map(async (photo) => ({ ...await photoData(photo), id: photo.id }))).then(value => {
17            if (current)
18                setImages(value);
19        }).catch(() => {
20            if (current)
21                setImages([]);
22        });
23        return () => { current = false; };
24    }, [photos]);
25    return <div className="chat-photos">{tr(images.map(i => <div key={i.id}><img src={i.url} alt={i.name}/><span>{i.name}</span>{tr(onRemove ? <IconBtn name="x" title={tr("Remove {0}", [i.name])} onClick={() => onRemove(i.id)}/> : null)}</div>))}</div>;
26}