import { Box, Button, Card, CardBody, Center, Collapse, Grid, GridItem, Image, Link, Text, useDisclosure, VStack, Wrap, WrapItem, } from '@chakra-ui/react'; import { DecryptedAudioFile, deleteFile, ProcessState } from './fileListingSlice'; import { useCallback, useRef } from 'react'; import { useAppDispatch } from '~/hooks'; import coverFallback from '~/assets/no-cover.svg'; interface FileRowProps { id: string; file: DecryptedAudioFile; } export function FileRow({ id, file }: FileRowProps) { const { isOpen, onClose } = useDisclosure({ defaultIsOpen: true }); const dispatch = useAppDispatch(); const isDecrypted = file.state === ProcessState.COMPLETE; const metadata = file.metadata; const nameWithoutExt = file.fileName.replace(/\.[a-z\d]{3,6}$/, ''); const decryptedName = nameWithoutExt + '.' + file.ext; const audioPlayerRef = useRef(null); const togglePlay = useCallback(() => { const player = audioPlayerRef.current; if (!player) { return; } if (player.paused) { player.play(); } else { player.pause(); } }, []); const handleDeleteRow = useCallback(() => { onClose(); setTimeout(() => { dispatch(deleteFile({ id })); }, 500); }, [dispatch, id, onClose]); return (
{metadata && ( {`"${metadata.album}" )}
{metadata?.name ?? nameWithoutExt} {isDecrypted && metadata && ( 专辑: {metadata.album} 艺术家: {metadata.artist} 专辑艺术家: {metadata.albumArtist} )} {file.decrypted &&
); }