Add Random resource retrieval and navigation.

This commit is contained in:
2025-06-08 17:49:49 +08:00
parent b0680fa94f
commit 99a2d328f1
9 changed files with 132 additions and 10 deletions

View File

@@ -0,0 +1,28 @@
import Loading from "../components/loading.tsx";
import { useNavigate } from "react-router";
import { useEffect } from "react";
import { network } from "../network/network.ts";
import showToast from "../components/toast.ts";
export default function RandomPage() {
const navigate = useNavigate();
useEffect(() => {
network.getRandomResource().then((res) => {
if (res.success) {
navigate(`/resources/${res.data!.id}`, {
state: {
resource: res.data,
},
});
} else {
showToast({
type: "error",
message: res.message || "Failed to fetch random resource",
});
}
});
}, [navigate]);
return <Loading />;
}