Merge remote-tracking branch 'houkunlin/feat/file-row' into merge-houkunlin
This commit is contained in:
commit
c0bc9858d0
@ -4,19 +4,21 @@ import {
|
|||||||
Card,
|
Card,
|
||||||
CardBody,
|
CardBody,
|
||||||
Center,
|
Center,
|
||||||
|
Collapse,
|
||||||
Grid,
|
Grid,
|
||||||
GridItem,
|
GridItem,
|
||||||
Image,
|
Image,
|
||||||
Link,
|
Link,
|
||||||
Text,
|
Text,
|
||||||
|
useDisclosure,
|
||||||
VStack,
|
VStack,
|
||||||
Wrap,
|
Wrap,
|
||||||
WrapItem,
|
WrapItem,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { DecryptedAudioFile, ProcessState, deleteFile } from './fileListingSlice';
|
import { DecryptedAudioFile, deleteFile, ProcessState } from './fileListingSlice';
|
||||||
import { useRef } from 'react';
|
import { useCallback, useRef } from 'react';
|
||||||
import { useAppDispatch } from '~/hooks';
|
import { useAppDispatch } from '~/hooks';
|
||||||
import coverFallback from '~/assets/no-cover.svg';
|
import coverSvgUrl from '~/assets/no-cover.svg';
|
||||||
|
|
||||||
interface FileRowProps {
|
interface FileRowProps {
|
||||||
id: string;
|
id: string;
|
||||||
@ -24,6 +26,7 @@ interface FileRowProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function FileRow({ id, file }: FileRowProps) {
|
export function FileRow({ id, file }: FileRowProps) {
|
||||||
|
const { isOpen, onClose } = useDisclosure({ defaultIsOpen: true });
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const isDecrypted = file.state === ProcessState.COMPLETE;
|
const isDecrypted = file.state === ProcessState.COMPLETE;
|
||||||
const metadata = file.metadata;
|
const metadata = file.metadata;
|
||||||
@ -45,11 +48,15 @@ export function FileRow({ id, file }: FileRowProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteRow = () => {
|
const handleDeleteRow = useCallback(() => {
|
||||||
|
onClose();
|
||||||
|
setTimeout(() => {
|
||||||
dispatch(deleteFile({ id }));
|
dispatch(deleteFile({ id }));
|
||||||
};
|
}, 500);
|
||||||
|
}, [dispatch, id, onClose]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<Collapse in={isOpen} animateOpacity unmountOnExit startingHeight={0} style={{ width: '100%' }}>
|
||||||
<Card w="full" data-testid="file-row">
|
<Card w="full" data-testid="file-row">
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<Grid
|
<Grid
|
||||||
@ -77,14 +84,12 @@ export function FileRow({ id, file }: FileRowProps) {
|
|||||||
>
|
>
|
||||||
<GridItem area="cover">
|
<GridItem area="cover">
|
||||||
<Center w="160px" h="160px" m="auto">
|
<Center w="160px" h="160px" m="auto">
|
||||||
{metadata && (
|
|
||||||
<Image
|
<Image
|
||||||
objectFit="cover"
|
objectFit="cover"
|
||||||
src={metadata.cover}
|
src={metadata?.cover}
|
||||||
alt={`"${metadata.album}" 的专辑封面`}
|
alt={`${metadata?.album} 的专辑封面`}
|
||||||
fallbackSrc={coverFallback}
|
fallbackSrc={coverSvgUrl}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</Center>
|
</Center>
|
||||||
</GridItem>
|
</GridItem>
|
||||||
<GridItem area="title">
|
<GridItem area="title">
|
||||||
@ -137,5 +142,6 @@ export function FileRow({ id, file }: FileRowProps) {
|
|||||||
</Grid>
|
</Grid>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
|
</Collapse>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user