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'; 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 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 (
{file.metadata.album}
{file.metadata.name || nameWithoutExt} {isDecrypted && ( 专辑: {file.metadata.album} 艺术家: {file.metadata.artist} 专辑艺术家: {file.metadata.albumArtist} )} {file.decrypted &&
); }