Skip to content

Commit

Permalink
chore: added new component
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Nov 17, 2023
1 parent cd090c5 commit daf0f2c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 81 deletions.
41 changes: 41 additions & 0 deletions src/components/BooksSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { Suspense } from 'react';
import { Box, Flex, Divider, Spinner } from '@chakra-ui/react';

import { BooksSectionType } from './types';

export function BooksSection({
title,
data,
booksComponent,
}: BooksSectionType) {
return (
<>
<Box my='10'>
<Divider borderColor='gray.400' />
</Box>
<Flex direction='column'>
<Box
p='2'
mb='3'
fontSize={{ base: 'xl', md: '2xl' }}
textAlign={{ base: 'center', lg: 'left' }}
ml={{ base: 0, lg: 2 }}
>
{title}{' '}
<Box as='span' fontWeight='semibold'>
{data}
</Box>
</Box>
<Suspense
fallback={
<Box p='3'>
<Spinner size='lg' />
</Box>
}
>
<Box>{booksComponent}</Box>
</Suspense>
</Flex>
</>
);
}
7 changes: 7 additions & 0 deletions src/components/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ interface SkeletonType {
showTags?: boolean;
}

interface BooksSectionType {
title: string;
data?: string;
booksComponent: RNode;
}

export type {
LinkType,
SelectBooksType,
Expand All @@ -148,6 +154,7 @@ export type {
HeadType,
TagType,
BookType,
BooksSectionType,
ModalCroppType,
ModalCropperType,
ModalType,
Expand Down
100 changes: 19 additions & 81 deletions src/pages/Book.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { MainHead } from '../components/Head';
import { MyTag } from '../components/MyTag';
import { ModalShare } from '../components/ModalShare';
import { MyLink } from '../components/MyLink';
import { BooksSection } from '../components/BooksSection';

const Categories = lazy(() => import('../components/Categories'));
const MoreBooksAuthors = lazy(
Expand Down Expand Up @@ -298,87 +299,24 @@ export default function Book() {
shareUrl={shareUrl}
data={data.title}
/>
<Box my='10'>
<Divider borderColor='gray.400' />
</Box>
<Flex direction='column'>
<Box
p='2'
mb='3'
fontSize={{ base: 'xl', md: '2xl' }}
textAlign={{ base: 'center', lg: 'left' }}
ml={{ base: 0, lg: 2 }}
>
Más libros del autor{' '}
<Box as='span' fontWeight='semibold'>
{data.authors[0]}
</Box>
</Box>
<Suspense
fallback={
<Box p='3'>
<Spinner size='lg' />
</Box>
}
>
<Box>
<MoreBooksAuthors id={data.id} currentBookId={pathUrl} />
</Box>
</Suspense>
</Flex>
<Box my='10'>
<Divider borderColor='gray.400' />
</Box>
<Flex direction='column'>
<Box
p='2'
mb='3'
fontSize={{ base: 'xl', md: '2xl' }}
textAlign={{ base: 'center', lg: 'left' }}
ml={{ base: 0, lg: 2 }}
>
Libros relacionados con{' '}
<Box as='span' fontWeight='semibold'>
{data.category[0]}
</Box>
</Box>
<Suspense
fallback={
<Box p='3'>
<Spinner size='lg' />
</Box>
}
>
<Box>
<RelatedBooks id={data.id} currentBookId={pathUrl} />
</Box>
</Suspense>
</Flex>
<Box my='10'>
<Divider borderColor='gray.400' />
</Box>
<Flex direction='column'>
<Box
p='2'
mb='3'
fontSize={{ base: 'xl', md: '2xl' }}
textAlign={{ base: 'center', lg: 'left' }}
ml={{ base: 0, lg: 2 }}
>
Más libros en XBuniverse
</Box>
<Suspense
fallback={
<Box p='3'>
<Spinner size='lg' />
</Box>
}
>
<Box>
<MoreBooks currentBookId={pathUrl} />
</Box>
</Suspense>
</Flex>
<BooksSection
title='Más libros del autor'
data={data.authors[0]}
booksComponent={
<MoreBooksAuthors id={data.id} currentBookId={pathUrl} />
}
/>
<BooksSection
title='Libros relacionados con'
data={data.category[0]}
booksComponent={
<RelatedBooks id={data.id} currentBookId={pathUrl} />
}
/>
<BooksSection
title='Más libros en XBuniverse'
booksComponent={<MoreBooks currentBookId={pathUrl} />}
/>
</Flex>
<Flex
display={{ base: 'none', lg: 'block' }}
Expand Down

1 comment on commit daf0f2c

@vercel
Copy link

@vercel vercel bot commented on daf0f2c Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

xbu – ./

xbu-franqsanz.vercel.app
xbu.vercel.app
xbu-git-main-franqsanz.vercel.app

Please sign in to comment.