From b8c3a517562b614b061298148c067ded7937c72c Mon Sep 17 00:00:00 2001 From: HouKunLin Date: Tue, 16 May 2023 16:24:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=AD=8C=E6=9B=B2=E5=B0=81=E9=9D=A2?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20Image=20=E7=BB=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=AD=8C=E6=9B=B2=E8=A1=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=97=B6=E4=BD=BF=E7=94=A8=E4=B8=80=E4=B8=AA=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E6=95=88=E6=9E=9C=E6=9D=A5=E8=BF=87=E6=B8=A1=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/file-listing/FileRow.tsx | 153 ++++++++++++++------------ 1 file changed, 83 insertions(+), 70 deletions(-) diff --git a/src/features/file-listing/FileRow.tsx b/src/features/file-listing/FileRow.tsx index 07c04c3..9cdc12d 100644 --- a/src/features/file-listing/FileRow.tsx +++ b/src/features/file-listing/FileRow.tsx @@ -1,20 +1,22 @@ import { - Avatar, Box, Button, Card, CardBody, Center, + Collapse, Grid, GridItem, + Image, Link, Text, + useDisclosure, VStack, Wrap, WrapItem, } from '@chakra-ui/react'; -import { DecryptedAudioFile, ProcessState, deleteFile } from './fileListingSlice'; -import { useRef } from 'react'; +import { DecryptedAudioFile, deleteFile, ProcessState } from './fileListingSlice'; +import { useCallback, useRef } from 'react'; import { useAppDispatch } from '~/hooks'; interface FileRowProps { @@ -23,6 +25,7 @@ interface FileRowProps { } export function FileRow({ id, file }: FileRowProps) { + const { isOpen, onToggle } = useDisclosure({ defaultIsOpen: true }); const dispatch = useAppDispatch(); const isDecrypted = file.state === ProcessState.COMPLETE; @@ -30,7 +33,7 @@ export function FileRow({ id, file }: FileRowProps) { const decryptedName = nameWithoutExt + '.' + file.ext; const audioPlayerRef = useRef(null); - const togglePlay = () => { + const togglePlay = useCallback(() => { const player = audioPlayerRef.current; if (!player) { return; @@ -41,87 +44,97 @@ export function FileRow({ id, file }: FileRowProps) { } else { player.pause(); } - }; + }, []); - const handleDeleteRow = () => { - dispatch(deleteFile({ id })); - }; + const handleDeleteRow = useCallback(() => { + onToggle(); + setTimeout(() => { + dispatch(deleteFile({ id })); + }, 500); + }, [dispatch, id, onToggle]); return ( - - - + + + - -
- {file.metadata.cover && } - {!file.metadata.cover && 暂无封面} -
-
- - - {file.metadata.name || nameWithoutExt} - - - - {isDecrypted && ( - - 专辑: {file.metadata.album} - 艺术家: {file.metadata.artist} - 专辑艺术家: {file.metadata.albumArtist} + }} + gridTemplateRows={{ + base: 'repeat(auto-fill)', + md: 'min-content 1fr', + }} + gridTemplateColumns={{ + base: '1fr', + md: '160px 1fr', + }} + gap="1" + > + +
+ {file.metadata.album} +
+
+ + + {file.metadata.name || nameWithoutExt} - )} - - - - {file.decrypted && + + {isDecrypted && ( + + 专辑: {file.metadata.album} + 艺术家: {file.metadata.artist} + 专辑艺术家: {file.metadata.albumArtist} + + )} + + + + {file.decrypted && - -
-
-
+ + + +
+
+
+ ); }