|
| 1 | +import { HiOutlineCalendar, HiOutlineCog, HiOutlinePlus, HiOutlineUser, HiOutlineUsers } from "react-icons/hi"; |
| 2 | +import { NavLink } from "react-router"; |
| 3 | +import { type InvolvedProjects, involvedProjectsResSchema } from "../../../common/schema"; |
| 4 | +import Header from "../components/Header"; |
| 5 | +import { useData } from "../hooks"; |
| 6 | +import { API_ENDPOINT } from "../utils"; |
| 7 | + |
| 8 | +export default function HomePage() { |
| 9 | + const { data: involvedProjects, loading } = useData(`${API_ENDPOINT}/projects/mine`, involvedProjectsResSchema); |
| 10 | + |
| 11 | + return ( |
| 12 | + <> |
| 13 | + <Header /> |
| 14 | + {loading ? ( |
| 15 | + <div className="min-h-[calc(100dvh_-_64px)] bg-blue-50 flex items-center justify-center"> |
| 16 | + <div className="py-4"> |
| 17 | + <span className="loading loading-dots loading-md text-gray-400" /> |
| 18 | + </div> |
| 19 | + </div> |
| 20 | + ) : involvedProjects ? ( |
| 21 | + <ProjectDashboard involvedProjects={involvedProjects} /> |
| 22 | + ) : ( |
| 23 | + <div className="min-h-[calc(100dvh_-_64px)] bg-blue-50 flex items-center justify-center"> |
| 24 | + <EmptyState /> |
| 25 | + </div> |
| 26 | + )} |
| 27 | + </> |
| 28 | + ); |
| 29 | +} |
| 30 | + |
| 31 | +function ProjectDashboard({ involvedProjects }: { involvedProjects: InvolvedProjects }) { |
| 32 | + const sortedProjects = [...involvedProjects].sort((a, b) => { |
| 33 | + if (a.isHost !== b.isHost) { |
| 34 | + return a.isHost ? -1 : 1; |
| 35 | + } |
| 36 | + return new Date(b.startDate).getTime() - new Date(a.startDate).getTime(); |
| 37 | + }); |
| 38 | + |
| 39 | + return ( |
| 40 | + <div className="min-h-[calc(100dvh_-_64px)] bg-blue-50"> |
| 41 | + <div className="container mx-auto px-4 py-8"> |
| 42 | + {/* Hero Section */} |
| 43 | + <div className="text-center mb-12"> |
| 44 | + <div className="flex items-center justify-center mt-2 mb-6"> |
| 45 | + <img src="/logo.svg" alt="logo" width={48} className="mr-4" /> |
| 46 | + <h1 className="text-4xl text-primary font-mplus">イツヒマ</h1> |
| 47 | + </div> |
| 48 | + <p className="text-xl text-gray-600 mb-8">「いつヒマ?」で日程調整しよう</p> |
| 49 | + <NavLink |
| 50 | + to="/new" |
| 51 | + className="btn btn-primary btn-lg px-8 py-4 text-lg shadow-lg hover:shadow-xl transition-all duration-300 transform hover:-translate-y-1" |
| 52 | + > |
| 53 | + <HiOutlinePlus className="mr-2" size={20} /> |
| 54 | + 新しいイベントを作成 |
| 55 | + </NavLink> |
| 56 | + </div> |
| 57 | + |
| 58 | + {involvedProjects.length > 0 ? ( |
| 59 | + <div className="space-y-8"> |
| 60 | + {/* All Projects */} |
| 61 | + <section> |
| 62 | + <h2 className="text-2xl font-bold text-gray-800 mb-6 flex items-center"> |
| 63 | + <HiOutlineCalendar className="mr-3 text-gray-700" size={28} /> |
| 64 | + あなたのイベント |
| 65 | + </h2> |
| 66 | + <div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6"> |
| 67 | + {sortedProjects.map((project) => ( |
| 68 | + <ProjectCard key={project.id} project={project} /> |
| 69 | + ))} |
| 70 | + </div> |
| 71 | + </section> |
| 72 | + </div> |
| 73 | + ) : ( |
| 74 | + <EmptyState /> |
| 75 | + )} |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + ); |
| 79 | +} |
| 80 | + |
| 81 | +function ProjectCard({ project }: { project: InvolvedProjects[0] }) { |
| 82 | + return ( |
| 83 | + <NavLink |
| 84 | + to={`/${project.id}`} |
| 85 | + className={`group relative block bg-white rounded-xl shadow-lg hover:shadow-xl |
| 86 | + transition-all duration-300 transform hover:-translate-y-1 overflow-hidden |
| 87 | + border-l-4 ${project.isHost ? "border-primary" : "border-secondary"} |
| 88 | + focus:outline-none focus:ring-4 focus:ring-primary/20`} |
| 89 | + aria-label={`「${project.name}」の詳細を見る`} |
| 90 | + > |
| 91 | + <div className="p-6"> |
| 92 | + <div className="flex justify-between items-start mb-4"> |
| 93 | + <div className="flex-1 mr-2"> |
| 94 | + <h3 className="text-xl font-semibold text-gray-800 mb-2 break-words">{project.name}</h3> |
| 95 | + <span className={`badge badge-sm ${project.isHost ? "badge-primary" : "badge-secondary"}`}> |
| 96 | + {project.isHost ? ( |
| 97 | + <> |
| 98 | + <HiOutlineUser size={12} /> |
| 99 | + <span>主催者</span> |
| 100 | + </> |
| 101 | + ) : ( |
| 102 | + <> |
| 103 | + <HiOutlineUsers size={12} /> |
| 104 | + <span>参加者</span> |
| 105 | + </> |
| 106 | + )} |
| 107 | + </span> |
| 108 | + </div> |
| 109 | + |
| 110 | + {project.isHost && ( |
| 111 | + <NavLink |
| 112 | + to={`/${project.id}/edit`} |
| 113 | + onClick={(e) => e.stopPropagation()} |
| 114 | + className="btn btn-ghost btn-sm px-3 py-1 text-gray-500 hover:text-gray-700 hover:bg-gray-100 transition-all" |
| 115 | + > |
| 116 | + <HiOutlineCog size={14} /> |
| 117 | + <span className="text-xs">管理</span> |
| 118 | + </NavLink> |
| 119 | + )} |
| 120 | + </div> |
| 121 | + |
| 122 | + <div className="flex items-center text-gray-600 mb-4"> |
| 123 | + <HiOutlineCalendar className="mr-2" size={16} /> |
| 124 | + <span className="text-sm"> |
| 125 | + {formatDate(project.startDate.toLocaleDateString())} ~{formatDate(project.endDate.toLocaleDateString())} |
| 126 | + </span> |
| 127 | + </div> |
| 128 | + </div> |
| 129 | + |
| 130 | + <span |
| 131 | + className={`absolute bottom-4 right-4 ${project.isHost ? "text-primary" : "text-secondary"} text-2xl pointer-events-none |
| 132 | + group-hover:translate-x-1 transition-transform`} |
| 133 | + aria-hidden="true" |
| 134 | + > |
| 135 | + › |
| 136 | + </span> |
| 137 | + </NavLink> |
| 138 | + ); |
| 139 | +} |
| 140 | + |
| 141 | +function EmptyState() { |
| 142 | + return ( |
| 143 | + <div className="text-center py-16"> |
| 144 | + <div className="mb-8"> |
| 145 | + <div className="w-32 h-32 mx-auto mb-6 bg-gray-100 rounded-full flex items-center justify-center"> |
| 146 | + <HiOutlineCalendar className="text-gray-400" size={64} /> |
| 147 | + </div> |
| 148 | + <h3 className="text-2xl font-semibold text-gray-800 mb-3">まだイベントがありません</h3> |
| 149 | + <p className="text-gray-600 mb-8 max-w-md mx-auto">イベントを作成して、日程調整を始めましょう</p> |
| 150 | + </div> |
| 151 | + <NavLink |
| 152 | + to="/new" |
| 153 | + className="btn btn-primary btn-lg px-8 py-4 text-lg shadow-lg hover:shadow-xl transition-all duration-300" |
| 154 | + > |
| 155 | + <HiOutlinePlus className="mr-2" size={20} /> |
| 156 | + イベントを作成する |
| 157 | + </NavLink> |
| 158 | + </div> |
| 159 | + ); |
| 160 | +} |
| 161 | + |
| 162 | +// ---------- Utility ---------- |
| 163 | +const formatDate = (isoDate: string) => { |
| 164 | + const date = new Date(isoDate); |
| 165 | + return date.toLocaleDateString("ja-JP"); |
| 166 | +}; |
0 commit comments