From 1443c7c92e9d7fab4927d5be26967a4420438b85 Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Fri, 29 Nov 2024 15:11:37 -0500 Subject: [PATCH] commit before moving to flexbox --- components/representatives.js | 35 +++++++++++++---------- pages/_app.js | 1 - pages/congress/index.js | 23 +++++++++++---- styles/congress.module.scss | 54 +++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 22 deletions(-) create mode 100644 styles/congress.module.scss diff --git a/components/representatives.js b/components/representatives.js index ff406c3..739e677 100644 --- a/components/representatives.js +++ b/components/representatives.js @@ -1,4 +1,18 @@ -import styles from '../styles/blog.module.scss'; +import styles from '../styles/congress.module.scss'; + +function Card({ individual }) { + return ( + <> +
+ +
+

{individual.type} {individual.bio.full_name} - {individual.bio.party}

+

{individual.typeSince} - Current

+
+
+ + ); +} export default function Representatives({ rep }) { try { @@ -7,21 +21,12 @@ export default function Representatives({ rep }) { return ( <>

{rep.house.state} {rep.name} Representatives:

-
-
- -

{rep.house.type} {rep.house.bio.full_name} - {rep.house.bio.party}

-
+
+ { hasSenators ?
-
- -

{rep.senate1.type} {rep.senate1.bio.full_name} - {rep.senate1.bio.party}

-
-
- -

{rep.senate2.type} {rep.senate2.bio.full_name} - {rep.senate2.bio.party}

-
+ +
: <> @@ -32,7 +37,7 @@ export default function Representatives({ rep }) { // return emptiness if no rep is passed through } catch(err) { return ( - <> + <> Sorry, try another address ); } } diff --git a/pages/_app.js b/pages/_app.js index e692617..cdda9cd 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -22,7 +22,6 @@ export default function MyApp({ Component, pageProps }) { -
); } diff --git a/pages/congress/index.js b/pages/congress/index.js index 4ad721d..2ee566c 100644 --- a/pages/congress/index.js +++ b/pages/congress/index.js @@ -1,15 +1,18 @@ import Link from 'next/link'; import dayjs from 'dayjs'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import Head from 'next/head'; +import { useRouter } from 'next/router'; -import styles from '../../styles/blog.module.scss'; +import styles from '../../styles/congress.module.scss'; import Representatives from '../../components/representatives.js'; export default function Congress() { const [address, setAddress] = useState(""); const [rep, setRep] = useState(""); + const router = useRouter(); + const { query } = router; // let rep; @@ -18,16 +21,23 @@ export default function Congress() { let res = await fetch(`https://api.ethancedwards.com/congress/v1/${address}`) let info = await res.json(); - setRep(info); - console.log('we are here'); + // puts the address parameter into the URL + const queryParams = new URLSearchParams(`address=${address}`).toString(); + router.push(`/congress?${queryParams}`); - // event.target.submit() + setRep(info); } + useEffect(() => { + if (query.address) { + setAddress(query.address); + } + }, [query]); + return ( <> - Congress Search + Congress @@ -40,6 +50,7 @@ export default function Congress() {
+
{ rep ? :
Please input an address...
}
diff --git a/styles/congress.module.scss b/styles/congress.module.scss new file mode 100644 index 0000000..62f6830 --- /dev/null +++ b/styles/congress.module.scss @@ -0,0 +1,54 @@ +.header { + // background: #363EEB; + // background: #363EEB; + margin: 20px; + padding: 10px; + border-radius: 50px; +} + +.text { + margin: 20px; + padding: 10px; +} + +.repInfo { + border-style: solid; + border-color: black; + padding: 5px; + margin: 5px; + display: grid; + // grid-template-columns: repeat(3, 1fr); + grid-template-columns: 1fr 4fr; + grid-auto-rows: 1; + + .photo { + grid-column: 1; + // width: 10%; + // height: auto; + border-style: solid; + border-color: black; + } + + .text { + // padding: 0; + margin: 0; + grid-column: 2 / 3; + } +} + +@media (width <= 800px) { + .repInfo { + padding: 5px; + // margin: 0; + + .photo { + // width: 80%; + // height: 80%; + padding: 0; + // margin: 0; + } + + .text { + } + } +}