trae-bot commited on
Commit
d014d32
·
1 Parent(s): df019aa

Replace hero banner with search bar on home page

Browse files
Files changed (1) hide show
  1. 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-12">
32
- {/* Hero Section */}
33
- <section className="bg-gradient-to-r from-blue-600 to-blue-800 rounded-2xl p-12 text-white shadow-xl">
34
- <div className="max-w-2xl">
35
- <h1 className="text-4xl font-bold mb-4">获取优质课程,提升你的技能</h1>
36
- <p className="text-blue-100 text-lg mb-8">访问由行业专家精心打造的高质量课程资料。一次购买,终身受益。</p>
37
- <button className="bg-white text-blue-600 px-6 py-3 rounded-lg font-medium hover:bg-blue-50 transition-colors">
38
- 浏览课程
39
- </button>
 
 
 
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">精选课程</h2>
 
 
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
- ) : courses.length > 0 ? (
56
  <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
57
- {courses.map((course) => (
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">暂无可用课程。</p>
 
 
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>