diff --git a/src/components/ProposalVoteCard.tsx b/src/components/ProposalVoteCard.tsx index 06a1d7e0..e555d7f5 100644 --- a/src/components/ProposalVoteCard.tsx +++ b/src/components/ProposalVoteCard.tsx @@ -1,19 +1,26 @@ import { Avatar, AvatarImage, AvatarFallback } from '@radix-ui/react-avatar'; import { Label } from '@radix-ui/react-label'; -import { RadioGroup, RadioGroupItem } from '@radix-ui/react-radio-group'; import { ThumbsUpIcon, ThumbsDownIcon, MinusIcon } from 'lucide-react'; import { CardHeader, CardContent, Card } from './ui/card.tsx'; import { Button } from './ui/button.tsx'; +import { RadioGroup, RadioGroupItem } from './ui/radio-group.tsx'; import type { Proposal } from './ProposalsPagenatedList.tsx'; +import { cn } from '../utils.ts'; export type ProposalVoteCardProps = { proposal: Proposal; - author?: string; }; +export type Vote = + | '-2' // Strongly Disinterested + | '-1' // Slightly Disinterested + | '0' // Neutral + | '1' // Slightly Interested + | '2'; // Strongly Interested + export type VotePayload = { initiativeId: string; - vote: number; + vote: Vote; comment: string; authorId: string; authorName: string; @@ -37,36 +44,43 @@ export function ProposalVoteCard(props: ProposalVoteCardProps) { hour12: true, }, ); - const numUpvotes = 72; // TODO: Replace with actual data - const numDownvotes = 18; // TODO: Replace with actual data + const numberUpvotes = 72; // TODO: Replace with actual data + const numberDownvotes = 18; // TODO: Replace with actual data - const handleVote = async (type: 'up' | 'down') => { + const handleInterestVote = (value: Vote) => { const votePayload: VotePayload = { initiativeId: props.proposal.id, - vote: type === 'up' ? 1 : -1, + vote: value, comment: '', authorId: '1234', // TODO: Replace with auth data - authorName: props.author ?? '', + authorName: props.proposal.author ?? '', authorEmail: '', // TODO: Replace with auth data }; - const url = `https://api.tulsawebdevs.org/proposals/${props.proposal.id}/vote`; - - try { - const response = await fetch(url, { - credentials: 'include', - headers: { - Authorization: '3fa85f64-5717-4562-b3fc-2c963f66afa6', // TODO: Add auth token - 'Content-Type': 'application/json', - }, - method: 'POST', - body: JSON.stringify(votePayload), + console.log('cast vote', votePayload); + + fetch(`https://api.tulsawebdevs.org/proposals/${props.proposal.id}/vote`, { + credentials: 'include', + headers: { + Authorization: '3fa85f64-5717-4562-b3fc-2c963f66afa6', // TODO: Add auth token + 'Content-Type': 'application/json', + }, + method: 'POST', + body: JSON.stringify(votePayload), + }) + .then((res) => res.json()) + .then((data) => { + console.log('do something with data', data); + }) + .catch((error) => { + // TODO: Handle inability to cast vote + console.error(error); }); + }; - console.log('response', response); - } catch (error) { - console.error(error); - } + // TODO: Implement like vote functionality. What API to call? + const handleLikeVote = (type: 'up' | 'down') => { + console.log('handle like vote', type); }; return ( @@ -82,25 +96,11 @@ export function ProposalVoteCard(props: ProposalVoteCardProps) {

-
- - - -
+ @@ -113,100 +113,114 @@ export function ProposalVoteCard(props: ProposalVoteCardProps) {
{`Proposed ${proposedDate} at ${proposedTime} by `} - {props.author ?? 'Anonymous'} + {props.proposal.author ?? 'Anonymous'}
- - - - - - - +
); } + +const voteOptions = [ + { + label: 'Strongly Disinterested', + value: '-2', + id: 'vote-strongly-disinterested', + }, + { + label: 'Slightly Disinterested', + value: '-1', + id: 'vote-slightly-disinterested', + }, + { label: 'Neutral', value: '0', id: 'vote-neutral' }, + { label: 'Slightly Interested', value: '1', id: 'vote-slightly-interested' }, + { label: 'Strongly Interested', value: '2', id: 'vote-strongly-interested' }, +]; + +function ProposalInterestVote({ + onVoteSelect, +}: { + onVoteSelect: (vote: Vote) => void; +}) { + return ( + + {voteOptions.map((option) => { + const value = parseInt(option.value, 10); + + return ( + + ); + })} + + ); +} + +type ProposalLikeButtonsProps = { + handleLikeVote: (type: 'up' | 'down') => void; + numberUpvotes: number; + numberDownvotes: number; +}; + +function ProposalLikeButtons({ + handleLikeVote, + numberUpvotes, + numberDownvotes, +}: ProposalLikeButtonsProps) { + return ( +
+ + + +
+ ); +}