chore: move file row's grid layout to its own file

This commit is contained in:
鲁树人 2023-05-21 15:38:07 +01:00
parent 940a61daab
commit 65e1e0caa2
2 changed files with 32 additions and 27 deletions

View File

@ -1,3 +1,4 @@
import { useRef } from 'react';
import { import {
Box, Box,
Button, Button,
@ -5,7 +6,6 @@ import {
CardBody, CardBody,
Center, Center,
Collapse, Collapse,
Grid,
GridItem, GridItem,
Image, Image,
Link, Link,
@ -15,8 +15,8 @@ import {
Wrap, Wrap,
WrapItem, WrapItem,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { FileRowResponsiveGrid } from './FileRowResponsiveGrid';
import { DecryptedAudioFile, deleteFile, ProcessState } from './fileListingSlice'; import { DecryptedAudioFile, deleteFile, ProcessState } from './fileListingSlice';
import { useCallback, useRef } from 'react';
import { useAppDispatch } from '~/hooks'; import { useAppDispatch } from '~/hooks';
import noCoverFallbackImageURL from '~/assets/no-cover.svg'; import noCoverFallbackImageURL from '~/assets/no-cover.svg';
@ -59,29 +59,7 @@ export function FileRow({ id, file }: FileRowProps) {
<Collapse in={isOpen} animateOpacity unmountOnExit startingHeight={0} style={{ width: '100%', padding: '0.25rem' }}> <Collapse in={isOpen} animateOpacity unmountOnExit startingHeight={0} style={{ width: '100%', padding: '0.25rem' }}>
<Card w="full" data-testid="file-row"> <Card w="full" data-testid="file-row">
<CardBody> <CardBody>
<Grid <FileRowResponsiveGrid>
templateAreas={{
base: `
"cover"
"title"
"meta"
"action"
`,
md: `
"cover title title"
"cover meta action"
`,
}}
gridTemplateRows={{
base: 'repeat(auto-fill)',
md: 'min-content 1fr',
}}
gridTemplateColumns={{
base: '1fr',
md: '160px 1fr',
}}
gap="1"
>
<GridItem area="cover"> <GridItem area="cover">
<Center w="160px" h="160px" m="auto"> <Center w="160px" h="160px" m="auto">
<Image <Image
@ -111,7 +89,7 @@ export function FileRow({ id, file }: FileRowProps) {
</Box> </Box>
)} )}
</GridItem> </GridItem>
<GridItem area="action"> <GridItem area="action" alignSelf="center">
<VStack> <VStack>
{file.decrypted && <audio controls autoPlay={false} src={file.decrypted} ref={audioPlayerRef} />} {file.decrypted && <audio controls autoPlay={false} src={file.decrypted} ref={audioPlayerRef} />}
@ -138,7 +116,7 @@ export function FileRow({ id, file }: FileRowProps) {
</Wrap> </Wrap>
</VStack> </VStack>
</GridItem> </GridItem>
</Grid> </FileRowResponsiveGrid>
</CardBody> </CardBody>
</Card> </Card>
</Collapse> </Collapse>

View File

@ -0,0 +1,27 @@
import { Grid, chakra } from '@chakra-ui/react';
export const FileRowResponsiveGrid = chakra(Grid, {
baseStyle: {
gridTemplateAreas: {
base: `
"cover"
"title"
"meta"
"action"
`,
md: `
"cover title action"
"cover meta action"
`,
},
gridTemplateRows: {
base: 'repeat(auto-fill)',
md: 'min-content 1fr',
},
gridTemplateColumns: {
base: '1fr',
md: '160px 1fr',
},
gap: 3,
},
});