From bf51be2f360f5f45937088d594fd4750afeaaa45 Mon Sep 17 00:00:00 2001 From: Bhanu Teja P Date: Sat, 1 Aug 2020 21:46:10 +0530 Subject: [PATCH] Add a tab to show the top contributions --- src/components/CrowdFund/donors.tsx | 65 +++++++++++++++++++---------- src/components/CrowdFund/list.tsx | 2 +- src/pages/crowdfund/[slug].tsx | 2 - 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/components/CrowdFund/donors.tsx b/src/components/CrowdFund/donors.tsx index cb94f3f..3d7824b 100644 --- a/src/components/CrowdFund/donors.tsx +++ b/src/components/CrowdFund/donors.tsx @@ -1,8 +1,8 @@ -import React, { FunctionComponent } from 'react'; +import React, { FunctionComponent, useState } from 'react'; import fromnow from 'fromnow'; import { AwardIcon } from '../Icons/common'; -import { CampaignWithFundings } from '../../services/airtable'; +import { CampaignWithFundings, Funding } from '../../services/airtable'; import { truncateString } from '../../utils'; interface Props { @@ -11,6 +11,12 @@ interface Props { export const DonorsList: FunctionComponent = ({ campaign }) => { const { fundings } = campaign; + const [showRecent, setShowRecent] = useState(true); + const sortedFundings = () => + showRecent + ? fundings.sort((a, b) => +new Date(b.created_at) - +new Date(a.created_at)) + : fundings.sort((a, b) => b.donated_amount - a.donated_amount); + if (fundings.length === 0) { return (
@@ -21,27 +27,42 @@ export const DonorsList: FunctionComponent = ({ campaign }) => {
); } + const tabCommonClass = 'bg-white inline-block py-2 px-4 hover:text-pink-800 font-semibold'; + const tabClass = `${tabCommonClass} text-pink-500`; + const tabActiveClass = `${tabCommonClass} text-pink-700 border-b border-pink-500`; return ( - + + ); }; diff --git a/src/components/CrowdFund/list.tsx b/src/components/CrowdFund/list.tsx index f0e841b..e259fc4 100644 --- a/src/components/CrowdFund/list.tsx +++ b/src/components/CrowdFund/list.tsx @@ -23,7 +23,7 @@ export const CampaignList: FunctionComponent = ({ inline = false }) => { if (error) { return (
-

{error.message || 'An error occured. Try again later'}

+

{'An error occured. Try again later'}

); } diff --git a/src/pages/crowdfund/[slug].tsx b/src/pages/crowdfund/[slug].tsx index 1b82595..ef10cd2 100644 --- a/src/pages/crowdfund/[slug].tsx +++ b/src/pages/crowdfund/[slug].tsx @@ -50,8 +50,6 @@ const CampaignPage: NextPage = ({ initialData, slug }) => {
-

Recent Contributions

-

A special thanks to all who raised the funds for this campaign.