Cleaning up
Cleaning up the Genres
- 修复左侧分类名称过长不换行导致的 UI 问题
- 修复图片比例被拉伸的问题
- 添加分类列表标题
GenreList.tsx |
---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 | import {
List,
ListItem,
HStack,
Image,
Spinner,
Button,
Heading,
} from "@chakra-ui/react";
import useGenres, { Genre } from "../hooks/useGenres";
import getCroppedImageUrl from "../services/image-url";
interface Props {
onSelectGenre: (genre: Genre) => void;
selectedGenre: Genre | null;
}
const GenreList = ({ onSelectGenre, selectedGenre }: Props) => {
const { data, isLoading, error } = useGenres();
if (error) return null;
if (isLoading) return <Spinner />;
return (
<>
<Heading fontSize="2xl" marginBottom={3}>
Genres
</Heading>
<List>
{data.map((genre) => (
<ListItem key={genre.id} paddingY="5px">
<HStack>
<Image
boxSize="32px"
borderRadius={8}
// 自适应显示并保持宽高比
objectFit="cover"
src={getCroppedImageUrl(genre.image_background)}
></Image>
<Button
// 文字自动换行
whiteSpace="normal"
textAlign="left"
fontWeight={
genre.id == selectedGenre?.id
? "bold"
: "normal"
}
onClick={() => onSelectGenre(genre)}
variant="link"
>
{genre.name}
</Button>
</HStack>
</ListItem>
))}
</List>
</>
);
};
export default GenreList;
|
Cleaning up the Game Cards
- 游戏标题下移,增大和图标的距离
- 增加卡片间距
- 调整单行卡片数量
GameCard.tsx |
---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 | import { Card, Image, CardBody, Heading, HStack } from "@chakra-ui/react";
import { Game } from "../hooks/useGames";
import PlatformIconList from "./PlatformIconList";
import CriticScore from "./CriticScore";
import getCroppedImageUrl from "../services/image-url";
interface Props {
game: Game;
}
const GameCard = ({ game }: Props) => {
return (
<Card>
<Image src={getCroppedImageUrl(game.background_image)} />
<CardBody>
<HStack justifyContent={"space-between"} marginBottom={3}>
<PlatformIconList
platforms={game.parent_platforms.map(
({ platform }) => platform
)}
/>
<CriticScore score={game.metacritic} />
</HStack>
<Heading fontSize="2xl">{game.name}</Heading>
</CardBody>
</Card>
);
};
export default GameCard;
|
GameGrid.tsx |
---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 | import { Text, SimpleGrid, Skeleton } from "@chakra-ui/react";
import useGames, { Platform } from "../hooks/useGames";
import GameCard from "./GameCard";
import GameCardSkeleton from "./GameCardSkeleton";
import GameCardContainer from "./GameCardContainer";
import { Genre } from "../hooks/useGenres";
import { GameQuery } from "../App";
interface Props {
gameQuery: GameQuery;
}
const GameGrid = ({ gameQuery }: Props) => {
const { data, error, isLoading } = useGames(gameQuery);
const skeletons = [1, 2, 3, 4, 5, 6];
// Array.from({ length: data.length + 1 }, (_, i) => i++);
return (
<>
{error && <Text>{error}</Text>}
<SimpleGrid
columns={{ sm: 1, md: 2, lg: 3, xl: 4 }}
padding="10px"
spacing={6}
>
{isLoading &&
skeletons.map((Skeleton) => (
<GameCardContainer key={Skeleton}>
<GameCardSkeleton />
</GameCardContainer>
))}
{data.map((game) => (
<GameCardContainer key={game.id}>
<GameCard game={game} />
</GameCardContainer>
))}
</SimpleGrid>
</>
);
};
export default GameGrid;
|
2024-09-12 00:01 2024-09-12 00:33