|
1 |
| -//Dependents页面 |
| 1 | +//Versions页面 |
2 | 2 | "use client";
|
3 | 3 | import React, { useEffect, useState } from 'react';
|
4 |
| - |
5 |
| -import VersionsTable from '@/components/VersionsTable'; |
6 |
| -// import { VersionsInfo } from '@/app/lib/all_interface'; |
7 | 4 | import { useParams } from 'next/navigation';
|
| 5 | +import Image from 'next/image'; |
| 6 | +import Link from 'next/link'; |
| 7 | +import VersionsTable from '@/components/VersionsTable'; |
8 | 8 |
|
9 | 9 | interface VersionInfo {
|
10 | 10 | version: string;
|
11 |
| - // publishDay: string; |
12 |
| - dependents_number: number; |
| 11 | + updated_at: string; |
| 12 | + downloads: string; |
| 13 | + dependents: number; |
13 | 14 | }
|
14 | 15 |
|
15 |
| -// interface VersionsTableProps { |
16 |
| -// data: VersionInfo[] | undefined; |
17 |
| - |
18 |
| -// } |
19 |
| - |
20 | 16 | const CratePage = () => {
|
21 | 17 | const [results, setResults] = useState<VersionInfo[] | undefined>(undefined);
|
| 18 | + console.log(results); |
22 | 19 | const [loading, setLoading] = useState(true);
|
23 |
| - |
24 |
| - const [error, setError] = useState(null); |
| 20 | + const [error, setError] = useState<string | null>(null); |
25 | 21 |
|
26 | 22 | const params = useParams();
|
27 | 23 |
|
28 |
| - |
29 |
| - |
30 | 24 | useEffect(() => {
|
31 | 25 | const fetchCrateData = async () => {
|
32 | 26 | try {
|
| 27 | + setError(null); |
33 | 28 | const response = await fetch(`/api/crates/${params.nsfront}/${params.nsbehind}/${params.name}/${params.version}/versions`);
|
34 | 29 |
|
35 | 30 | if (!response.ok) {
|
36 | 31 | throw new Error(`HTTP error! status: ${response.status}`);
|
37 | 32 | }
|
38 | 33 |
|
39 | 34 | const data = await response.json();
|
40 |
| - |
41 |
| - |
42 | 35 | setResults(data); // 设置获取的数据
|
43 |
| - |
44 | 36 | } catch (error) {
|
45 |
| - setError(null); |
46 | 37 | console.log('Error fetching data:', error);
|
| 38 | + setError("Failed to fetch data."); |
47 | 39 | } finally {
|
48 | 40 | setLoading(false); // 完成加载
|
49 | 41 | }
|
50 | 42 | };
|
51 | 43 | fetchCrateData(); // 调用函数来获取数据
|
52 |
| - }, [params.name, params.version, params.nsfront, params.nsbehind]); // 依赖项数组,确保在 crateName 或 version 改变时重新获取数据 |
53 |
| - console.log('results in versionsssssss', results); |
54 |
| - if (loading) return <div>Loading...</div>; |
55 |
| - if (error) return <div className="text-red-500">Error: {error}</div>; |
56 |
| - |
| 44 | + }, [params.name, params.version, params.nsfront, params.nsbehind]); // 依赖项数组,确保在参数改变时重新获取数据 |
57 | 45 |
|
| 46 | + if (loading) return <div className="flex justify-center items-center min-h-screen">Loading...</div>; |
| 47 | + if (error) return <div className="flex justify-center items-center min-h-screen text-red-500">Error: {error}</div>; |
58 | 48 |
|
59 | 49 | return (
|
60 |
| - <div> |
61 |
| - |
62 |
| - <VersionsTable /> |
63 |
| - |
| 50 | + <div className="min-h-screen bg-white flex flex-col"> |
| 51 | + <div className="flex justify-center w-full py-4"> |
| 52 | + <div className="w-[1500px] px-8"> |
| 53 | + <VersionsTable /> |
| 54 | + </div> |
| 55 | + </div> |
| 56 | + |
| 57 | + {/* 页脚 */} |
| 58 | + <footer className="bg-[#002851] text-white py-12 mt-auto"> |
| 59 | + <div className="flex justify-center w-full"> |
| 60 | + <div className="w-[1500px] px-8"> |
| 61 | + <div className="grid grid-cols-1 md:grid-cols-4 gap-8"> |
| 62 | + <div> |
| 63 | + <Image |
| 64 | + src="/images/homepage/logo-footer.png" |
| 65 | + alt="CratesPro Logo" |
| 66 | + width={180} |
| 67 | + height={60} |
| 68 | + className="mb-4" |
| 69 | + /> |
| 70 | + </div> |
| 71 | + |
| 72 | + <div> |
| 73 | + <h4 className="text-lg font-semibold mb-4">Resources</h4> |
| 74 | + <ul className="space-y-2"> |
| 75 | + <li><Link href="#" className="hover:text-blue-300">Documentation</Link></li> |
| 76 | + <li><Link href="#" className="hover:text-blue-300">About</Link></li> |
| 77 | + <li><Link href="#" className="hover:text-blue-300">Blog</Link></li> |
| 78 | + <li><Link href="#" className="hover:text-blue-300">FAQ</Link></li> |
| 79 | + </ul> |
| 80 | + </div> |
| 81 | + |
| 82 | + <div> |
| 83 | + <h4 className="text-lg font-semibold mb-4">API</h4> |
| 84 | + <ul className="space-y-2"> |
| 85 | + <li><Link href="#" className="hover:text-blue-300">API</Link></li> |
| 86 | + <li><Link href="#" className="hover:text-blue-300">BigQuery Dataset</Link></li> |
| 87 | + <li><Link href="#" className="hover:text-blue-300">GitHub</Link></li> |
| 88 | + </ul> |
| 89 | + </div> |
| 90 | + |
| 91 | + <div> |
| 92 | + <h4 className="text-lg font-semibold mb-4">Legal</h4> |
| 93 | + <ul className="space-y-2"> |
| 94 | + <li><Link href="#" className="hover:text-blue-300">Legal</Link></li> |
| 95 | + <li><Link href="#" className="hover:text-blue-300">Privacy</Link></li> |
| 96 | + <li><Link href="#" className="hover:text-blue-300">Terms</Link></li> |
| 97 | + </ul> |
| 98 | + </div> |
| 99 | + </div> |
| 100 | + |
| 101 | + <div className="border-t border-gray-700 mt-8 pt-8 text-center text-sm"> |
| 102 | + <p>Copyright © 2023 jp21.com.cn All Rights Reserved(@ICPBH180237号)</p> |
| 103 | + </div> |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + </footer> |
64 | 107 | </div>
|
65 | 108 | );
|
66 | 109 | };
|
|
0 commit comments