Skip to content

Commit 16aad48

Browse files
author
xiaoyusu
committed
feat: 新增可配置数据
1 parent edd41e0 commit 16aad48

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

app/components/ActivityTicker.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ import Link from "next/link";
55
import { useCallback, useEffect, useMemo, useState } from "react";
66
import { ChevronLeft, ChevronRight } from "lucide-react";
77
import eventsData from "@/data/event.json";
8-
import type { ActivityEvent } from "@/app/types/event";
8+
import type { ActivityEvent, ActivityEventsConfig } from "@/app/types/event";
99
import { cn } from "@/lib/utils";
1010

11-
const MAX_ITEMS = 3;
12-
//
13-
const ROTATION_INTERVAL_MS = 8000;
11+
const {
12+
events: rawEvents,
13+
settings: {
14+
maxItems: configuredMaxItems = 3,
15+
rotationIntervalMs: configuredRotationIntervalMs = 8000,
16+
},
17+
} = eventsData as ActivityEventsConfig;
18+
19+
// 默认配置,从data/event.json中读取配置
20+
const MAX_ITEMS = configuredMaxItems;
21+
const ROTATION_INTERVAL_MS = configuredRotationIntervalMs;
1422

1523
/** ActivityTicker 外部传入的样式配置 */
1624
type ActivityTickerProps = {
@@ -39,14 +47,14 @@ function resolveCoverUrl(coverUrl: string): string {
3947

4048
/**
4149
* 首页活动轮播组件:
42-
* - 读取 event.json 前三条活动
50+
* - 读取 event.json 配置的活动数量
4351
* - 自动轮播封面图,顶部指示器支持手动切换
4452
* - 底部两个毛玻璃按钮:Discord 永远可见,Playback 仅在 deprecated=true 时显示
4553
*/
4654
export function ActivityTicker({ className }: ActivityTickerProps) {
4755
// 预处理活动列表,保持初次渲染后的引用稳定
4856
const events = useMemo<ActivityEvent[]>(() => {
49-
return (eventsData as ActivityEvent[]).slice(0, MAX_ITEMS);
57+
return rawEvents.slice(0, MAX_ITEMS);
5058
}, []);
5159

5260
// 当前展示的活动索引

app/types/event.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@ export interface ActivityEvent {
1818
/** 是否为已结束活动,true 时展示 Playback 按钮 */
1919
deprecated: boolean;
2020
}
21+
22+
/** 活动轮播可配置参数 */
23+
export interface ActivityTickerSettings {
24+
/** 首屏最多展示的活动数量 */
25+
maxItems: number;
26+
/** 自动轮播的间隔时间(毫秒) */
27+
rotationIntervalMs: number;
28+
}
29+
30+
/** event.json 的整体结构 */
31+
export interface ActivityEventsConfig {
32+
settings: ActivityTickerSettings;
33+
events: ActivityEvent[];
34+
}

data/event.json

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
[
2-
{
3-
"name": "Mock Interview",
4-
"discord": "https://discord.gg/QHsjqezfC?event=1430500169299922965",
5-
"playback": "https://involutionhell.com/docs/jobs/event-keynote/event-takeway",
6-
"coverUrl": "./event/mockInterview.png",
7-
"deprecated": true
1+
{
2+
"settings": {
3+
"maxItems": 3,
4+
"rotationIntervalMs": 8000
85
},
9-
{
10-
"name": "Coffee Chat",
11-
"discord": "https://discord.com/invite/8AQZj7sa?event=1432010537402761348",
12-
"playback": "https://involutionhell.com/docs/jobs/event-keynote/coffee-chat",
13-
"coverUrl": "./event/coffeeChat.png",
14-
"deprecated": true
15-
}
16-
]
6+
"events": [
7+
{
8+
"name": "Mock Interview",
9+
"discord": "https://discord.gg/QHsjqezfC?event=1430500169299922965",
10+
"playback": "https://involutionhell.com/docs/jobs/event-keynote/event-takeway",
11+
"coverUrl": "./event/mockInterview.png",
12+
"deprecated": true
13+
},
14+
{
15+
"name": "Coffee Chat",
16+
"discord": "https://discord.com/invite/8AQZj7sa?event=1432010537402761348",
17+
"playback": "https://involutionhell.com/docs/jobs/event-keynote/coffee-chat",
18+
"coverUrl": "./event/coffeeChat.png",
19+
"deprecated": true
20+
}
21+
]
22+
}

0 commit comments

Comments
 (0)