"use client" import { useState } from "react" import Link from "next/link" import { ArrowRight, ArrowUpDown, CheckCircle, ExternalLink, Filter, Search, SortAsc, SortDesc } from "lucide-react" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Input } from "@/components/ui/input" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" // Mock data for contributions const mockContributions = [ { id: 1, title: "After-School Programs", description: "Create free after-school programs for K-8 students in public schools", category: "Education", votes: { yes: 312, no: 28 }, perspectives: 42, date: "2023-11-15", }, { id: 2, title: "Community Health Clinics", description: "Establish walk-in clinics in underserved areas with sliding scale fees", category: "Healthcare", votes: { yes: 278, no: 42 }, perspectives: 36, date: "2023-12-03", }, { id: 3, title: "Public Library Expansion", description: "Increase funding for public libraries to expand hours and digital resources", category: "Education", votes: { yes: 245, no: 35 }, perspectives: 29, date: "2024-01-10", }, { id: 4, title: "Green Space Preservation", description: "Protect existing green spaces from development and create new community gardens", category: "Environmental Policy", votes: { yes: 289, no: 41 }, perspectives: 38, date: "2024-01-22", }, ] // Add state for search, filter, and sort export default function ContributionsPage() { const [searchQuery, setSearchQuery] = useState("") const [categoryFilter, setCategoryFilter] = useState("all") const [sortOrder, setSortOrder] = useState<"asc" | "desc">("desc") const [sortBy, setSortBy] = useState<"votes" | "date">("date") // Filter and sort the contributions const filteredContributions = mockContributions.filter((contribution) => { // Filter by search query if ( searchQuery && !contribution.title.toLowerCase().includes(searchQuery.toLowerCase()) && !contribution.description.toLowerCase().includes(searchQuery.toLowerCase()) ) return false // Filter by category if (categoryFilter !== "all" && contribution.category !== categoryFilter) return false return true }) // Sort the filtered contributions const sortedContributions = [...filteredContributions].sort((a, b) => { if (sortBy === "votes") { const totalVotesA = a.votes.yes + a.votes.no const totalVotesB = b.votes.yes + b.votes.no return sortOrder === "desc" ? totalVotesB - totalVotesA : totalVotesA - totalVotesB } else { const dateA = new Date(a.date).getTime() const dateB = new Date(b.date).getTime() return sortOrder === "desc" ? dateB - dateA : dateA - dateB } }) // Add the search, filter, and sort UI return (

Validated Contributions

These insights have reached community consensus and become formal contributions.

{/* Filters and Search */}
setSearchQuery(e.target.value)} />
Sort by setSortBy("votes")}>Votes {sortBy === "votes" && "✓"} setSortBy("date")}>Date {sortBy === "date" && "✓"} setSortOrder(sortOrder === "desc" ? "asc" : "desc")}> {sortOrder === "desc" ? "Ascending" : "Descending"}
{sortedContributions.map((contribution) => (
{contribution.title} {contribution.category}
Validated

{contribution.description}

Consensus

{Math.round((contribution.votes.yes / (contribution.votes.yes + contribution.votes.no)) * 100)}% approval

Based on

{contribution.perspectives} perspectives

Date Validated

{new Date(contribution.date).toLocaleDateString()}

Status

Added to Resolution #12

))}
{sortedContributions.length === 0 && (

No contributions match your filters

Try adjusting your search or filters

)}
) }