|
1 | | -import { ArrowRight, Search, Users, Vote } from "lucide-react"; |
| 1 | +import { ArrowRight, Clock, Search, Users, Vote } from "lucide-react"; |
2 | 2 | import { Link } from "react-router-dom"; |
3 | 3 |
|
4 | 4 | import { Card, CardContent } from "@/components/ui/Card"; |
5 | 5 | import { useGetMotionStatistics } from "@/hooks/useGetMotionStatistics"; |
| 6 | +import { useRecentSessions } from "@/hooks/api"; |
6 | 7 | import logo from "../assets/tug.png"; |
7 | 8 | import { Button } from "../components/ui/Button"; |
| 9 | +import { formatPercentage } from "../lib/utils"; |
8 | 10 |
|
9 | 11 | export function HomePage() { |
10 | 12 | const { data: motionStatisticsData, isLoading } = useGetMotionStatistics(); |
| 13 | + const { sessions, isLoading: isLoadingSessions } = useRecentSessions(); |
| 14 | + |
11 | 15 | return ( |
12 | 16 | <div className="pb-16 "> |
13 | 17 | {/* Hero Section */} |
@@ -55,6 +59,97 @@ export function HomePage() { |
55 | 59 | </div> |
56 | 60 | </div> |
57 | 61 |
|
| 62 | + {/* Recent Sessions Section */} |
| 63 | + {!isLoadingSessions && sessions.length > 0 && ( |
| 64 | + <div className="bg-white border-b border-gray-200"> |
| 65 | + <div className="container mx-auto px-4 py-8"> |
| 66 | + <div className="mb-4 flex items-center justify-between"> |
| 67 | + <div> |
| 68 | + <h2 className="text-2xl font-bold text-gray-900"> |
| 69 | + Eerdere resultaten |
| 70 | + </h2> |
| 71 | + <p className="text-sm text-gray-600 mt-1"> |
| 72 | + Ga terug naar je vorige kieswijzer sessies |
| 73 | + </p> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | + <div className="grid md:grid-cols-2 lg:grid-cols-3 gap-4"> |
| 77 | + {sessions.slice(0, 3).map((session) => { |
| 78 | + const topParty = session.data?.partyResults[0]; |
| 79 | + const formattedDate = new Date( |
| 80 | + session.createdAt, |
| 81 | + ).toLocaleDateString("nl-NL", { |
| 82 | + day: "numeric", |
| 83 | + month: "short", |
| 84 | + year: "numeric", |
| 85 | + hour: "2-digit", |
| 86 | + minute: "2-digit", |
| 87 | + }); |
| 88 | + |
| 89 | + return ( |
| 90 | + <Card |
| 91 | + key={session.id} |
| 92 | + className="h-full transition-all hover:shadow-md border-2 border-gray-100 hover:border-blue-200" |
| 93 | + > |
| 94 | + <CardContent className="p-5"> |
| 95 | + <div className="flex items-start justify-between mb-3"> |
| 96 | + <div className="flex items-center text-sm text-gray-500"> |
| 97 | + <Clock className="h-4 w-4 mr-1.5" /> |
| 98 | + {formattedDate} |
| 99 | + </div> |
| 100 | + {topParty && ( |
| 101 | + <div className="text-2xl font-bold text-blue-600"> |
| 102 | + {formatPercentage(topParty.agreement)} |
| 103 | + </div> |
| 104 | + )} |
| 105 | + </div> |
| 106 | + {topParty && ( |
| 107 | + <div className="mb-2"> |
| 108 | + <div className="text-sm text-gray-600 mb-1"> |
| 109 | + Beste match: |
| 110 | + </div> |
| 111 | + <div className="font-semibold text-gray-900"> |
| 112 | + {topParty.party.shortName} |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + )} |
| 116 | + {session.data && ( |
| 117 | + <div className="text-xs text-gray-500 mt-3 pt-3 border-t border-gray-100"> |
| 118 | + {session.data.totalAnswers} stellingen beantwoord |
| 119 | + </div> |
| 120 | + )} |
| 121 | + <div className="mt-4 flex gap-2"> |
| 122 | + <Link to={`/results/${session.id}`} className="flex-1"> |
| 123 | + <Button |
| 124 | + variant="secondary" |
| 125 | + size="sm" |
| 126 | + className="w-full text-xs" |
| 127 | + > |
| 128 | + Resultaten |
| 129 | + </Button> |
| 130 | + </Link> |
| 131 | + <Link |
| 132 | + to={`/compass?session=${session.id}`} |
| 133 | + className="flex-1" |
| 134 | + > |
| 135 | + <Button |
| 136 | + variant="primary" |
| 137 | + size="sm" |
| 138 | + className="w-full text-xs" |
| 139 | + > |
| 140 | + Ga verder |
| 141 | + </Button> |
| 142 | + </Link> |
| 143 | + </div> |
| 144 | + </CardContent> |
| 145 | + </Card> |
| 146 | + ); |
| 147 | + })} |
| 148 | + </div> |
| 149 | + </div> |
| 150 | + </div> |
| 151 | + )} |
| 152 | + |
58 | 153 | {/* Main Tools Section */} |
59 | 154 | <div className="container mx-auto px-4 py-16"> |
60 | 155 | <div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6"> |
|
0 commit comments