Skip to content

Commit

Permalink
Fetch funding based on quetion title constant
Browse files Browse the repository at this point in the history
  • Loading branch information
camilovegag committed May 21, 2024
1 parent 6c38be1 commit 5726e9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/berlin/src/pages/Results.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchCycle, fetchForumQuestionStatistics } from 'api';
import { fetchCycle, fetchForumQuestionFunding, fetchForumQuestionStatistics } from 'api';
import { FlexColumn } from '../components/containers/FlexColumn.styled';
import { Subtitle } from '../components/typography/Subtitle.styled';
import { useParams } from 'react-router-dom';
Expand All @@ -9,6 +9,7 @@ import ResultsColumns from '../components/columns/results-columns';
import ResultsTable from '../components/tables/results-table';
import StatsTable from '../components/tables/stats-table';
import StatsColumns from '../components/columns/stats-columns';
import { FINAL_QUESTION_TITLE } from '../utils/constants';

function Results() {
const [expandedIndex, setExpandedIndex] = useState<number | null>(null);
Expand All @@ -29,6 +30,12 @@ function Results() {
retry: false,
});

const { data: funding } = useQuery({
queryKey: ['funding', cycle?.forumQuestions[0].id],
queryFn: () => fetchForumQuestionFunding(cycle?.forumQuestions[0].id || ''),
enabled: !!cycle?.id && cycle?.forumQuestions?.[0].questionTitle === FINAL_QUESTION_TITLE,
});

const overallStatistics = [
{
id: 0,
Expand Down Expand Up @@ -56,15 +63,18 @@ function Results() {
.map(([id, stats]) => ({
id,
...stats,
allocatedFunding: funding?.allocated_funding[id] || null,
}))
.sort((a, b) => parseFloat(b.pluralityScore) - parseFloat(a.pluralityScore));

console.log('optionStatsArray:', optionStatsArray);

return (
<FlexColumn $gap="2rem">
<BackButton />
<Subtitle>Results for: {cycle?.forumQuestions?.[0].questionTitle}</Subtitle>
<FlexColumn $gap="0">
<ResultsColumns />
<ResultsColumns $showFunding={!!funding} />
{optionStatsArray.map((option, index) => (
<ResultsTable
key={option.id}
Expand Down
1 change: 1 addition & 0 deletions packages/berlin/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const INITIAL_HEARTS = 80;
export const FIVE_MINUTES_IN_SECONDS = 300;
export const FINAL_QUESTION_TITLE = 'Which research should receive a share of 100,000 ARB?';

0 comments on commit 5726e9a

Please sign in to comment.