diff --git a/components/HeaderMenu/index.tsx b/components/HeaderMenu/index.tsx index 389edfe0..00b87ae1 100644 --- a/components/HeaderMenu/index.tsx +++ b/components/HeaderMenu/index.tsx @@ -32,7 +32,7 @@ const HeaderMenu = (props: Props) => { {props.username}
  • - Saved + Saved
  • diff --git a/pages/saved.tsx b/pages/saved.tsx new file mode 100644 index 00000000..2b058ad0 --- /dev/null +++ b/pages/saved.tsx @@ -0,0 +1,111 @@ +import React, { useEffect, useState } from 'react' +import { useRouter } from 'next/router' +import { useCookies } from 'react-cookie' + +import api from '~utils/api' + +import GridRep from '~components/GridRep' +import GridRepCollection from '~components/GridRepCollection' +import FilterBar from '~components/FilterBar' + +const SavedRoute: React.FC = () => { + const router = useRouter() + + const [cookies, _] = useCookies(['user']) + const [found, setFound] = useState(false) + const [loading, setLoading] = useState(true) + const [scrolled, setScrolled] = useState(false) + const [parties, setParties] = useState([]) + + useEffect(() => { + console.log(`Fetching favorite 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 + }, + headers: { + 'Authorization': `Bearer ${cookies.user.access_token}` + } + } + + api.savedTeams(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 SavedRoute \ No newline at end of file