Skip to content

Commit

Permalink
TopPageの無駄なリクエストを削減
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-20 committed Mar 23, 2024
1 parent d0037aa commit c0342ae
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
11 changes: 5 additions & 6 deletions workspaces/app/src/features/book/components/BookCard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Suspense } from 'react';
import { styled } from 'styled-components';

import type { GetReleaseResponse } from '@wsh-2024/schema/src/api/releases/GetReleaseResponse';

import { Flex } from '../../../foundation/components/Flex';
import { Image } from '../../../foundation/components/Image';
import { Link } from '../../../foundation/components/Link';
import { Text } from '../../../foundation/components/Text';
import { useImage } from '../../../foundation/hooks/useImage';
import { Color, Radius, Space, Typography } from '../../../foundation/styles/variables';
import { useBook } from '../hooks/useBook';

const _Wrapper = styled(Link)`
display: flex;
Expand All @@ -33,17 +34,15 @@ const _AvatarWrapper = styled.div`
`;

type Props = {
bookId: string;
book: GetReleaseResponse['books'][number];
};

const BookCard: React.FC<Props> = ({ bookId }) => {
const { data: book } = useBook({ params: { bookId } });

const BookCard: React.FC<Props> = ({ book }) => {
const imageUrl = useImage({ height: 128, imageId: book.image.id, width: 192 });
const authorImageUrl = useImage({ height: 32, imageId: book.author.image.id, width: 32 });

return (
<_Wrapper href={`/books/${bookId}`}>
<_Wrapper href={`/books/${book.id}`}>
{imageUrl != null && (
<_ImgWrapper>
<Image alt={book.image.alt} height={128} objectFit="cover" src={imageUrl} width={192} />
Expand Down
11 changes: 5 additions & 6 deletions workspaces/app/src/features/feature/components/FeatureCard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Suspense } from 'react';
import { styled } from 'styled-components';

import type { GetFeatureListResponse } from '@wsh-2024/schema/src/api/features/GetFeatureListResponse';

import { Flex } from '../../../foundation/components/Flex';
import { Image } from '../../../foundation/components/Image';
import { Link } from '../../../foundation/components/Link';
import { Text } from '../../../foundation/components/Text';
import { useImage } from '../../../foundation/hooks/useImage';
import { Color, Radius, Space, Typography } from '../../../foundation/styles/variables';
import { useBook } from '../../book/hooks/useBook';

const _Wrapper = styled(Link)`
display: grid;
Expand Down Expand Up @@ -44,17 +45,15 @@ const _AvatarWrapper = styled.div`
`;

type Props = {
bookId: string;
book: GetFeatureListResponse[number]['book'];
};

const FeatureCard: React.FC<Props> = ({ bookId }) => {
const { data: book } = useBook({ params: { bookId } });

const FeatureCard: React.FC<Props> = ({ book }) => {
const imageUrl = useImage({ height: 96, imageId: book.image.id, width: 96 });
const authorImageUrl = useImage({ height: 32, imageId: book.author.image.id, width: 32 });

return (
<_Wrapper href={`/books/${bookId}`}>
<_Wrapper href={`/books/${book.id}`}>
{imageUrl != null && (
<_ImgWrapper>
<Image alt={book.image.alt} height={96} objectFit="cover" src={imageUrl} width={96} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Suspense } from 'react';
import styled from 'styled-components';

import type { GetRankingListResponse } from '@wsh-2024/schema/src/api/rankings/GetRankingListResponse';

import { SvgIcon } from '../../../features/icons/components/SvgIcon';
import { Box } from '../../../foundation/components/Box';
import { Flex } from '../../../foundation/components/Flex';
Expand All @@ -11,7 +13,6 @@ import { Spacer } from '../../../foundation/components/Spacer';
import { Text } from '../../../foundation/components/Text';
import { useImage } from '../../../foundation/hooks/useImage';
import { Color, Radius, Space, Typography } from '../../../foundation/styles/variables';
import { useBook } from '../../book/hooks/useBook';

const _Wrapper = styled.li`
width: 100%;
Expand All @@ -38,12 +39,10 @@ const _AvatarWrapper = styled.div`
`;

type Props = {
bookId: string;
book: GetRankingListResponse[number]['book'];
};

const RankingCard: React.FC<Props> = ({ bookId }) => {
const { data: book } = useBook({ params: { bookId } });

const RankingCard: React.FC<Props> = ({ book }) => {
const imageUrl = useImage({ height: 96, imageId: book.image.id, width: 96 });
const authorImageUrl = useImage({ height: 32, imageId: book.author.image.id, width: 32 });

Expand Down
6 changes: 3 additions & 3 deletions workspaces/app/src/pages/TopPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const TopPage: React.FC = () => {
<Box maxWidth="100%" overflowX="scroll" overflowY="hidden">
<Flex align="stretch" direction="row" gap={Space * 2} justify="flex-start">
{featureList.map((feature) => (
<FeatureCard key={feature.id} bookId={feature.book.id} />
<FeatureCard key={feature.id} book={feature.book} />
))}
</Flex>
</Box>
Expand All @@ -55,7 +55,7 @@ const TopPage: React.FC = () => {
<Box maxWidth="100%" overflowX="hidden" overflowY="hidden">
<Flex align="center" as="ul" direction="column" justify="center">
{rankingList.map((ranking) => (
<RankingCard key={ranking.id} bookId={ranking.book.id} />
<RankingCard key={ranking.id} book={ranking.book} />
))}
</Flex>
</Box>
Expand All @@ -71,7 +71,7 @@ const TopPage: React.FC = () => {
<Box maxWidth="100%" overflowX="scroll" overflowY="hidden">
<Flex align="stretch" gap={Space * 2} justify="flex-start">
{release.books.map((book) => (
<BookCard key={book.id} bookId={book.id} />
<BookCard key={book.id} book={book} />
))}
</Flex>
</Box>
Expand Down

0 comments on commit c0342ae

Please sign in to comment.