From 4a2c57ee47d8432d995f4f6d59cd0a239df0b94c Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 27 Feb 2022 00:39:45 -0800 Subject: [PATCH] Implement Teams page --- pages/teams.tsx | 106 ++++++++++++++++++++++++++++++++++++++++++++ styles/globals.scss | 22 +++++++++ 2 files changed, 128 insertions(+) create mode 100644 pages/teams.tsx diff --git a/pages/teams.tsx b/pages/teams.tsx new file mode 100644 index 00000000..b512aacc --- /dev/null +++ b/pages/teams.tsx @@ -0,0 +1,106 @@ +import React, { useEffect, useState } from 'react' +import { useRouter } from 'next/router' + +import api from '~utils/api' + +import GridRep from '~components/GridRep' +import GridRepCollection from '~components/GridRepCollection' +import FilterBar from '~components/FilterBar' + +const TeamsRoute: React.FC = () => { + const router = useRouter() + + const [found, setFound] = useState(false) + const [loading, setLoading] = useState(true) + const [scrolled, setScrolled] = useState(false) + const [parties, setParties] = useState([]) + + useEffect(() => { + console.log(`Fetching teams...`) + fetchTeams() + }, []) + + useEffect(() => { + window.addEventListener("scroll", handleScroll) + return () => window.removeEventListener("scroll", handleScroll); + }, []) + + async function fetchTeams(element?: number, raid?: string, recency?: number) { + const params = { + params: { + element: (element && element >= 0) ? element : undefined, + raid: (raid && raid != '0') ? raid : undefined, + recency: (recency && recency > 0) ? recency : undefined + } + } + + api.endpoints.parties.getAll(params) + .then(response => { + const parties: Party[] = response.data + setParties(parties.map((p: any) => p.party).sort((a, b) => (a.created_at > b.created_at) ? -1 : 1)) + }) + .then(() => { + setFound(true) + setLoading(false) + }) + .catch(error => { + if (error.response != null) { + if (error.response.status == 404) { + setFound(false) + } + } else { + console.error(error) + } + }) + } + + function handleScroll() { + if (window.pageYOffset > 90) + setScrolled(true) + else + setScrolled(false) + } + + function goTo(shortcode: string) { + router.push(`/p/${shortcode}`) + } + + function renderGrids() { + return ( + + { + parties.map((party, i) => { + return + }) + } + + ) + } + + function renderNoGrids() { + return ( +
+

No grids found

+
+ ) + } + + return ( +
+ + { (parties.length > 0) ? renderGrids() : renderNoGrids() } +
+ ) +} + +export default TeamsRoute \ No newline at end of file diff --git a/styles/globals.scss b/styles/globals.scss index 2e705125..2a49d5a9 100644 --- a/styles/globals.scss +++ b/styles/globals.scss @@ -144,6 +144,28 @@ select { } } +#Teams { + display: flex; + height: 100%; + flex-direction: column; + gap: $unit * 4; +} + +#NotFound { + height: 200px; + width: 400px; + margin: auto; + display: flex; + justify-content: center; + align-items: center;; + + h2 { + color: $grey-60; + font-size: $font-regular; + text-align: center; + } +} + @keyframes openModal { 0% { opacity: 0;