Skip to content

Commit

Permalink
refactor: home page and add game default cover
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnsonMao committed Oct 13, 2024
1 parent 627cd67 commit 7df9d6d
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type GroupedGamesType = {

function GameList({ gameList, onGameChange, activeGameId }: GameListProp) {
const groupedGames = gameList.reduce((result: GroupedGamesType, game) => {
const category = game.category || "其他";
const category = "其他";
if (!result[category]) {
result[category] = [];
}
Expand Down
2 changes: 1 addition & 1 deletion components/shared/Carousel/v2/Carousel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const meta: Meta<typeof Carousel> = {
},
],
args: {
uniqueKey: "name",
renderKey: (props: any) => props.name,
items: [{ name: "TEST 1" }, { name: "TEST 2" }, { name: "TEST 3" }],
Component: Card,
},
Expand Down
15 changes: 6 additions & 9 deletions components/shared/Carousel/v2/Carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { CSSProperties, FC, useEffect, useRef, useState } from "react";
import { CSSProperties, FC, Key, useEffect, useRef, useState } from "react";
import Icon from "../../Icon/v2/Icon";

interface CarouselProps<
Item extends Record<string, unknown>,
Key extends keyof Item = keyof Item,
> {
items: (Item & Record<Key, string>)[];
uniqueKey: Key;
interface CarouselProps<Item extends Record<string, unknown>> {
items: Item[];
renderKey: (item: Item) => Key;
Component: FC<Item>;
}

export default function Carousel<Item extends Record<string, unknown>>({
items,
uniqueKey,
renderKey,
Component,
}: Readonly<CarouselProps<Item>>) {
const [showIndex, setShowIndex] = useState(0);
Expand Down Expand Up @@ -68,7 +65,7 @@ export default function Carousel<Item extends Record<string, unknown>>({
{Array.isArray(items) &&
items.map((item) => (
<li
key={item[uniqueKey]}
key={renderKey(item)}
className="shrink-0 w-[var(--max-width)]"
style={
{
Expand Down
2 changes: 1 addition & 1 deletion hooks/useRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const useRequest = () => {
requestWrapper: IRequestWrapper<T>,
options: FetchOptions = {
toast: {
show: true,
show: false,
options: {
position: "bottom-right",
},
Expand Down
7 changes: 5 additions & 2 deletions mocks/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ const mock_gameList: GameType[] = [
img: "http://localhost:3030/images/game-avatar.jpg",
minPlayers: 3,
maxPlayers: 10,
category: "心機",
createdOn: "2024-01-01T00:00:00",
},
{
id: "133456",
name: "璀璨寶石",
img: "http://localhost:3030/images/game-avatar.jpg",
minPlayers: 2,
maxPlayers: 4,
createdOn: "2024-01-01T00:00:00",
},
{
id: "133416",
name: "富饒之城",
img: "http://localhost:3030/images/game-avatar.jpg",
minPlayers: 3,
maxPlayers: 8,
createdOn: "2024-01-01T00:00:00",
},

{
Expand All @@ -29,14 +31,15 @@ const mock_gameList: GameType[] = [
img: "http://localhost:3030/images/game-avatar.jpg",
minPlayers: 3,
maxPlayers: 6,
createdOn: "2024-01-01T00:00:00",
},
{
id: "184456",
name: "農家樂",
img: "http://localhost:3030/images/game-avatar.jpg",
minPlayers: 1,
maxPlayers: 5,
category: "策略",
createdOn: "2024-01-01T00:00:00",
},
];

Expand Down
Loading

0 comments on commit 7df9d6d

Please sign in to comment.