|
| 1 | +import { useRouter } from 'next/router'; |
| 2 | +import { useState, useEffect } from 'react'; |
| 3 | +import Head from 'next/head'; |
| 4 | +import styles from '../../styles/congress.module.scss'; |
| 5 | + |
| 6 | +export default function LearnMore({ repInfo }) { |
| 7 | + let billArray = repInfo.sponsoredLegislation.recent.concat(repInfo.cosponsoredLegislation.recent); |
| 8 | + billArray = billArray.sort((a, b) => b.introducedDate - a.introducedDate) |
| 9 | + billArray.length = 6; |
| 10 | + |
| 11 | + return ( |
| 12 | + <> |
| 13 | + <Head> |
| 14 | + <title>{repInfo.type} {repInfo.directOrderName}</title> |
| 15 | + </Head> |
| 16 | + <div className={styles.infoPage}> |
| 17 | + <img src={repInfo.depiction.imageUrl} alt="" className={styles.photo} /> |
| 18 | + <div className={styles.infoCentral}> |
| 19 | + <h1>{repInfo.type} {repInfo.directOrderName}</h1> |
| 20 | + <p>{repInfo.partyHistory[0].partyName} Party - {repInfo.state}</p> |
| 21 | + <h2>Lawmaking Information:</h2> |
| 22 | + <div> |
| 23 | + <p>Bills Sponsored: {repInfo.sponsoredLegislation.count}</p> |
| 24 | + <p>Bills Co-Sponsored: {repInfo.cosponsoredLegislation.count}</p> |
| 25 | + </div> |
| 26 | + </div> |
| 27 | + <div className={styles.servingSince}> |
| 28 | + <div className={styles.box}> |
| 29 | + <h2>Office Term:</h2> |
| 30 | + <p>{repInfo.state} {repInfo.type} since {repInfo.typeSince}</p> |
| 31 | + </div> |
| 32 | + </div> |
| 33 | + |
| 34 | + <h3>Recent Bills:</h3> |
| 35 | + <div className={styles.recentLegislation}> |
| 36 | + {billArray.map((bill) => ( |
| 37 | + <div><b>{bill.type} {bill.number}</b> {bill.title}</div> |
| 38 | + ))} |
| 39 | + </div> |
| 40 | + </div> |
| 41 | + </> |
| 42 | + ); |
| 43 | +} |
| 44 | + |
| 45 | +export async function getServerSideProps({ params: { repID } }) { |
| 46 | + const res = await fetch(`https://api.ethancedwards.com/congress/v1/member/${repID}`); |
| 47 | + const repInfo = await res.json(); |
| 48 | + |
| 49 | + return { |
| 50 | + props: { |
| 51 | + repInfo |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments