um-react/src/features/file-listing/FileListing.tsx

73 lines
1.9 KiB
TypeScript

import {
Avatar,
Box,
Link,
Table,
TableContainer,
Tbody,
Td,
Text,
Th,
Thead,
Tr,
Wrap,
WrapItem,
} from '@chakra-ui/react';
import { ProcessState, selectFiles } from './fileListingSlice';
import { useAppSelector } from '../../hooks';
export function FileListing() {
const files = useAppSelector(selectFiles);
return (
<TableContainer>
<Table variant="striped">
<Thead>
<Tr>
<Th w="1%"></Th>
<Th></Th>
<Th></Th>
</Tr>
</Thead>
<Tbody>
{Object.entries(files).map(([id, file]) => (
<Tr key={id}>
<Td>
{file.metadata.cover && <Avatar size="sm" name="专辑封面" src={file.metadata.cover} />}
{!file.metadata.cover && <Text></Text>}
</Td>
<Td>
<Box as="h4" fontWeight="semibold" mt="1">
{file.metadata.name || file.fileName}
</Box>
{file.state === ProcessState.COMPLETE && (
<>
<Text>: {file.metadata.album}</Text>
<Text>: {file.metadata.artist}</Text>
<Text>: {file.metadata.albumArtist}</Text>
</>
)}
</Td>
<Td>
<Wrap>
<WrapItem></WrapItem>
<WrapItem>
{/* TODO: Use correct file name */}
{file.decrypted && (
<Link isExternal href={file.decrypted} download="test.flac">
</Link>
)}
</WrapItem>
<WrapItem></WrapItem>
</Wrap>
</Td>
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
);
}