Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add funding request to vote page #554

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/api/src/types/CycleType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type GetCycleResponse = {
optionTitle: string;
optionSubTitle?: string;
accepted: boolean;
fundingRequest: string;
user: {
group: {
id: string;
Expand Down
21 changes: 15 additions & 6 deletions packages/berlin/src/components/option-card/OptionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@ import { Body } from '../typography/Body.styled';
import { Bold } from '../typography/Bold.styled';
import { FlexColumn } from '../containers/FlexColumn.styled';
import { FlexRow } from '../containers/FlexRow.styled';
import { QuestionOption, fetchOptionUsers } from 'api';
import { fetchOptionUsers, GetCycleResponse } from 'api';
import { useAppStore } from '../../store';
import { useNavigate, useParams } from 'react-router-dom';
import { useQuery } from '@tanstack/react-query';
import { useMemo, useState } from 'react';
import IconButton from '../icon-button';

type OptionCardProps = {
option: QuestionOption;
option: GetCycleResponse['forumQuestions'][number]['questionOptions'][number];
showFundingRequest?: boolean;
numOfVotes: number;
onVote: () => void;
onUnVote: () => void;
};
function OptionCard({ option, numOfVotes, onVote, onUnVote }: OptionCardProps) {
function OptionCard({
option,
numOfVotes,
onVote,
onUnVote,
showFundingRequest = false,
}: OptionCardProps) {
const { eventId, cycleId } = useParams();
const theme = useAppStore((state) => state.theme);
const navigate = useNavigate();
Expand Down Expand Up @@ -87,9 +94,6 @@ function OptionCard({ option, numOfVotes, onVote, onUnVote }: OptionCardProps) {
</FlexColumn>
<Body>{numOfVotes}</Body>
</Votes>
{/* <Plurality>
<Body>{formattedPluralityScore}</Body>
</Plurality> */}
</FlexRow>
<FlexColumn className="description" $gap="1.5rem">
{coauthors && coauthors.length > 0 && (
Expand All @@ -98,6 +102,11 @@ function OptionCard({ option, numOfVotes, onVote, onUnVote }: OptionCardProps) {
{coauthors.map((coauthor) => `${coauthor.firstName} ${coauthor.lastName}`).join(', ')}
</Body>
)}
{showFundingRequest && option.fundingRequest && (
<Body>
<Bold>Funding request:</Bold> {option.fundingRequest}
</Body>
)}
{option.optionSubTitle && <Body>{option.optionSubTitle}</Body>}
<IconButton
$padding={0}
Expand Down
7 changes: 5 additions & 2 deletions packages/berlin/src/pages/Cycle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useParams } from 'react-router-dom';
import toast from 'react-hot-toast';

// API
import { GetUserVotesResponse, QuestionOption, fetchCycle, fetchUserVotes, postVotes } from 'api';
import { GetCycleResponse, GetUserVotesResponse, fetchCycle, fetchUserVotes, postVotes } from 'api';

// Hooks
import useCountdown from '../hooks/useCountdown';
Expand All @@ -32,10 +32,11 @@ import BackButton from '../components/back-button';
import Button from '../components/button';
import CycleColumns from '../components/columns/cycle-columns';
import OptionCard from '../components/option-card';
import { FIVE_MINUTES_IN_SECONDS, INITIAL_HEARTS } from '../utils/constants';
import { FINAL_QUESTION_TITLE, FIVE_MINUTES_IN_SECONDS, INITIAL_HEARTS } from '../utils/constants';

type Order = 'asc' | 'desc';
type LocalUserVotes = { optionId: string; numOfVotes: number }[];
type QuestionOption = GetCycleResponse['forumQuestions'][number]['questionOptions'][number];

function Cycle() {
const queryClient = useQueryClient();
Expand All @@ -53,6 +54,7 @@ function Cycle() {
enabled: !!user?.id && !!cycleId,
retry: false,
});

const availableHearts =
useAppStore((state) => state.availableHearts[cycle?.forumQuestions[0].id || '']) ??
INITIAL_HEARTS;
Expand Down Expand Up @@ -300,6 +302,7 @@ function Cycle() {
key={option.id}
option={option}
numOfVotes={numOfVotes}
showFundingRequest={currentCycle.questionTitle === FINAL_QUESTION_TITLE}
onVote={() => handleVoteWrapper(option.id)}
onUnVote={() => handleUnVoteWrapper(option.id)}
/>
Expand Down
Loading