okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0b3299a01
main
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} :{ 6photos :ChatPhoto []; 7onRemove ?:( id :string ) => void ; 8}) { 9const [ images , setImages ] = useState <{ 10id :string ; 11name :string ; 12url :string ; 13}[]>([]); 14useEffect (() => { 15let current = true ; 16void Promise . all ( photos . map ( async ( photo ) => ({ ...await photoData ( photo ), id :photo . id }))). then ( value => { 17if ( current ) 18setImages ( value ); 19}). catch (() => { 20if ( current ) 21setImages ([]); 22}); 23return () => { current = false ; }; 24}, [ photos ]); 25return < 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}