'use client'; import { Button, Card, CardContent, CardHeader, CardTitle } from '@components'; import { AnimatePresence, motion } from 'framer-motion'; import { useEffect, useState } from 'react'; import { BiUpvote } from 'react-icons/bi'; import { FiCheckCircle } from 'react-icons/fi'; import { MdOutlineOpenInNew } from 'react-icons/md'; interface RoadmapItem { id: string; title: string; description: string; status: 'upcoming' | 'in_progress' | 'completed'; votes: number; created_at: string; } export default function ProjectsVote() { const [items, setItems] = useState([]); const [loading, setLoading] = useState(true); const [votedIds, setVotedIds] = useState>(new Set()); useEffect(() => { fetch('https://api.imphnen.dev/v1/landing/cms/roadmap') .then((r) => r.json()) .then((json) => { setItems(json.data || []); }) .catch(() => {}) .finally(() => setLoading(false)); }, []); const upcomingItems = items.filter((i) => i.status === 'upcoming'); const inProgressItems = items.filter((i) => i.status === 'in_progress'); const completedItems = items.filter((i) => i.status === 'completed'); const handleVote = (id: string) => { const alreadyVoted = votedIds.has(id); // Optimistic update setItems((prev) => prev.map((item) => item.id === id ? { ...item, votes: item.votes + (alreadyVoted ? -1 : 1) } : item ) ); if (alreadyVoted) { setVotedIds((prev) => { const next = new Set(prev); next.delete(id); return next; }); } else { setVotedIds((prev) => new Set(prev).add(id)); fetch(`https://api.imphnen.dev/v1/landing/cms/roadmap/vote/${id}`, { method: 'POST', }).catch(() => {}); } }; const containerVariants = { hidden: { opacity: 0 }, visible: { opacity: 1, transition: { staggerChildren: 0.05, }, }, }; const itemVariants = { hidden: { opacity: 0, y: 10 }, visible: { opacity: 1, y: 0, transition: { duration: 0.2 } }, }; if (loading) { return (
); } return (
🔥

Vote Now

{upcomingItems.map((item) => ( {item.title}

{item.description}

handleVote(item.id)} className={`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-all ${ votedIds.has(item.id) ? 'bg-primary-500 text-white hover:bg-primary-600' : 'bg-gray-100 text-gray-700 hover:bg-gray-200' }`} > {votedIds.has(item.id) ? 'Voted' : 'Vote'}
{item.votes}
))} {upcomingItems.length === 0 && (

No upcoming items yet.

)}
🧑‍🔧

In Progress

{inProgressItems.map((item, index) => ( {item.title}

{item.description}

In development

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

Nothing in progress.

)}
🤓

Completed

{completedItems.map((item) => ( {item.title}

{item.description}

Implemented
))} {completedItems.length === 0 && (

No completed items yet.

)}
); }