新增前端接口,修改种子发布页面
Change-Id: I9d9f4bde524caeaab9cbadcd0e14f44e521b0abb
diff --git a/front/src/GamePage.js b/front/src/GamePage.js
index 23383b6..2528acd 100644
--- a/front/src/GamePage.js
+++ b/front/src/GamePage.js
@@ -21,7 +21,13 @@
{ label: "发布", icon: <AccountCircleIcon />, path: "/publish" }, // Added Publish option
];
-const gameTypes = ["PC", "主机", "移动", "掌机", "视频"];
+const gameTypesList = [
+ ["PC"],
+ ["主机"],
+ ["移动"],
+ ["掌机"],
+ ["视频"]
+];
const areaTabs = [
{ label: "PC", icon: <MovieIcon fontSize="small" /> },
@@ -31,15 +37,20 @@
{ label: "视频", icon: <PersonIcon fontSize="small" /> },
];
-const exampleTorrents = [
- { type: "RPG", title: "实例1", id: 1 },
- { type: "Shooter", title: "实例2", id: 2 },
- { type: "Adventure", title: "实例3", id: 3 },
-];
-
export default function GamePage() {
const navigate = useNavigate();
const [activeTab, setActiveTab] = useState(0);
+ const [gameList, setGameList] = useState([]);
+
+ const gameTypes = gameTypesList[activeTab] || [];
+
+ React.useEffect(() => {
+ const area = areaTabs[activeTab].label;
+ fetch(`http://192.168.5.9:8080/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
+ .then(res => res.json())
+ .then(data => setGameList(data))
+ .catch(() => setGameList([]));
+ }, [activeTab]);
return (
<div className="container">
@@ -153,27 +164,39 @@
</tr>
</thead>
<tbody>
- {gameTypes.map((type, idx) => (
- <tr key={type}>
- <td>
- <a
- href={`/torrent/${type}`}
- style={{ color: "#1a237e", textDecoration: "none" }}
- >
- {type}
- </a>
- </td>
- <td>
- <a
- href={`/torrent/${type}`}
- style={{ color: "#1a237e", textDecoration: "none" }}
- >
- 种子{idx + 1}
- </a>
- </td>
- <td></td>
- </tr>
- ))}
+ {gameList.length > 0 ? (
+ gameList.map((item, idx) => (
+ <tr key={item.id || idx}>
+ <td>
+ <a href={`/torrent/${item.seedid}`} style={{ color: "#1a237e", textDecoration: "none" }}>
+ {item.seedtag}
+ </a>
+ </td>
+ <td>
+ <a href={`/torrent/${item.seedid}`} style={{ color: "#1a237e", textDecoration: "none" }}>
+ {item.title}
+ </a>
+ </td>
+ <td>{item.user.username}</td>
+ </tr>
+ ))
+ ) : (
+ gameTypes.map((type, idx) => (
+ <tr key={type}>
+ <td>
+ <a href={`/torrent/${type}`} style={{ color: "#1a237e", textDecoration: "none" }}>
+ {type}
+ </a>
+ </td>
+ <td>
+ <a href={`/torrent/${type}`} style={{ color: "#1a237e", textDecoration: "none" }}>
+ 种子{idx + 1}
+ </a>
+ </td>
+ <td></td>
+ </tr>
+ ))
+ )}
</tbody>
</table>
</div>