Spaces:
Sleeping
Sleeping
trae-bot commited on
Commit ·
d014d32
1
Parent(s): df019aa
Replace hero banner with search bar on home page
Browse files- frontend/src/app/page.tsx +27 -14
frontend/src/app/page.tsx
CHANGED
|
@@ -3,12 +3,18 @@
|
|
| 3 |
import { useEffect, useState } from "react";
|
| 4 |
import { api } from "@/lib/api";
|
| 5 |
import Link from "next/link";
|
| 6 |
-
import { BookOpen } from "lucide-react";
|
| 7 |
|
| 8 |
export default function Home() {
|
| 9 |
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 10 |
const [courses, setCourses] = useState<any[]>([]);
|
| 11 |
const [loading, setLoading] = useState(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
useEffect(() => {
|
| 14 |
const fetchCourses = async () => {
|
|
@@ -28,22 +34,27 @@ export default function Home() {
|
|
| 28 |
}, []);
|
| 29 |
|
| 30 |
return (
|
| 31 |
-
<div className="space-y-
|
| 32 |
-
{/*
|
| 33 |
-
<section className="bg-
|
| 34 |
-
<div className="
|
| 35 |
-
<
|
| 36 |
-
<
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
| 40 |
</div>
|
| 41 |
</section>
|
| 42 |
|
| 43 |
{/* Course List */}
|
| 44 |
<section>
|
| 45 |
<div className="flex items-center justify-between mb-6">
|
| 46 |
-
<h2 className="text-2xl font-bold text-gray-900">
|
|
|
|
|
|
|
| 47 |
</div>
|
| 48 |
|
| 49 |
{loading ? (
|
|
@@ -52,9 +63,9 @@ export default function Home() {
|
|
| 52 |
<div key={i} className="bg-white rounded-xl h-80 animate-pulse"></div>
|
| 53 |
))}
|
| 54 |
</div>
|
| 55 |
-
) :
|
| 56 |
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
| 57 |
-
{
|
| 58 |
<Link href={`/course/${course.id}`} key={course.id}>
|
| 59 |
<div className="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden hover:shadow-md transition-shadow group">
|
| 60 |
<div className="aspect-video w-full bg-gray-200 relative overflow-hidden">
|
|
@@ -81,7 +92,9 @@ export default function Home() {
|
|
| 81 |
) : (
|
| 82 |
<div className="text-center py-12 bg-white rounded-xl border border-gray-100">
|
| 83 |
<BookOpen className="w-12 h-12 text-gray-300 mx-auto mb-3" />
|
| 84 |
-
<p className="text-gray-500">
|
|
|
|
|
|
|
| 85 |
</div>
|
| 86 |
)}
|
| 87 |
</section>
|
|
|
|
| 3 |
import { useEffect, useState } from "react";
|
| 4 |
import { api } from "@/lib/api";
|
| 5 |
import Link from "next/link";
|
| 6 |
+
import { BookOpen, Search } from "lucide-react";
|
| 7 |
|
| 8 |
export default function Home() {
|
| 9 |
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 10 |
const [courses, setCourses] = useState<any[]>([]);
|
| 11 |
const [loading, setLoading] = useState(true);
|
| 12 |
+
const [searchQuery, setSearchQuery] = useState("");
|
| 13 |
+
|
| 14 |
+
const filteredCourses = courses.filter(course =>
|
| 15 |
+
course.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
| 16 |
+
course.description?.toLowerCase().includes(searchQuery.toLowerCase())
|
| 17 |
+
);
|
| 18 |
|
| 19 |
useEffect(() => {
|
| 20 |
const fetchCourses = async () => {
|
|
|
|
| 34 |
}, []);
|
| 35 |
|
| 36 |
return (
|
| 37 |
+
<div className="space-y-8">
|
| 38 |
+
{/* Search Section */}
|
| 39 |
+
<section className="bg-white rounded-2xl p-6 shadow-sm border border-gray-100">
|
| 40 |
+
<div className="relative">
|
| 41 |
+
<Search className="absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400" />
|
| 42 |
+
<input
|
| 43 |
+
type="text"
|
| 44 |
+
placeholder="搜索课程..."
|
| 45 |
+
value={searchQuery}
|
| 46 |
+
onChange={(e) => setSearchQuery(e.target.value)}
|
| 47 |
+
className="w-full pl-12 pr-4 py-3 rounded-xl border border-gray-200 focus:border-blue-500 focus:ring-2 focus:ring-blue-200 outline-none transition-all text-gray-900 placeholder:text-gray-400"
|
| 48 |
+
/>
|
| 49 |
</div>
|
| 50 |
</section>
|
| 51 |
|
| 52 |
{/* Course List */}
|
| 53 |
<section>
|
| 54 |
<div className="flex items-center justify-between mb-6">
|
| 55 |
+
<h2 className="text-2xl font-bold text-gray-900">
|
| 56 |
+
{searchQuery ? '搜索结果' : '精选课程'}
|
| 57 |
+
</h2>
|
| 58 |
</div>
|
| 59 |
|
| 60 |
{loading ? (
|
|
|
|
| 63 |
<div key={i} className="bg-white rounded-xl h-80 animate-pulse"></div>
|
| 64 |
))}
|
| 65 |
</div>
|
| 66 |
+
) : filteredCourses.length > 0 ? (
|
| 67 |
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
| 68 |
+
{filteredCourses.map((course) => (
|
| 69 |
<Link href={`/course/${course.id}`} key={course.id}>
|
| 70 |
<div className="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden hover:shadow-md transition-shadow group">
|
| 71 |
<div className="aspect-video w-full bg-gray-200 relative overflow-hidden">
|
|
|
|
| 92 |
) : (
|
| 93 |
<div className="text-center py-12 bg-white rounded-xl border border-gray-100">
|
| 94 |
<BookOpen className="w-12 h-12 text-gray-300 mx-auto mb-3" />
|
| 95 |
+
<p className="text-gray-500">
|
| 96 |
+
{searchQuery ? '未找到匹配的课程' : '暂无可用课程'}
|
| 97 |
+
</p>
|
| 98 |
</div>
|
| 99 |
)}
|
| 100 |
</section>
|