From c001ec3d706ad7ef126c65efc86fa93b24bb4871 Mon Sep 17 00:00:00 2001 From: Seroxdesign Date: Mon, 23 Oct 2023 08:37:38 -0400 Subject: [PATCH] make community page dynamic, reduce repitition --- packages/web/components/Landing/WhoAreWe.tsx | 9 +- packages/web/pages/community/index.tsx | 146 +++++++++++-------- 2 files changed, 88 insertions(+), 67 deletions(-) diff --git a/packages/web/components/Landing/WhoAreWe.tsx b/packages/web/components/Landing/WhoAreWe.tsx index 54273e509a..0b7dd7b88c 100644 --- a/packages/web/components/Landing/WhoAreWe.tsx +++ b/packages/web/components/Landing/WhoAreWe.tsx @@ -81,6 +81,7 @@ export const WhoAreWe: React.FC< const { players } = usePlayerFilter(); const topPlayers = useMemo(() => players.slice(0, 7), [players]); + const topPatrons = useMemo(() => patrons.slice(0, 7), [patrons]); return ( 01Players (Builders) {topPlayers && ( - + )} 02Patrons (Funders) - {patrons && } + {topPatrons && } 03Elders (Advisors) - {patrons && } + {players && } 04MetaAlliance (Member projects) - {guilds && } + {guilds && } diff --git a/packages/web/pages/community/index.tsx b/packages/web/pages/community/index.tsx index 3757e2c282..cf39ae950f 100644 --- a/packages/web/pages/community/index.tsx +++ b/packages/web/pages/community/index.tsx @@ -1,8 +1,5 @@ import { Box, - Button, - Flex, - HStack, MetaHeading, Tab, TabList, @@ -19,16 +16,19 @@ import GuildsPage from 'pages/guilds'; import PatronsPage from 'pages/patrons'; import Players from 'pages/players'; import React, { useEffect, useState } from 'react'; +import { useRouter } from 'next/router'; type Props = InferGetStaticPropsType; export const getStaticProps = async () => { const patronsLimit = 150; const patrons = await getPatrons(patronsLimit); + const pSeedPrice = await getPSeedPrice().catch((error) => { console.error('Error fetching pSeed price', error); return null; }); + return { props: { guilds: await getGuilds(), @@ -43,64 +43,84 @@ const UnifiedCommunityPage: React.FC = ({ guilds, patrons, pSeedPrice, -}) => ( - - - Community - - - - - Players - - - Guilds - - - Patrons - - {/* Elders */} - - - - - - - - - - - - {/* - Elders - */} - - - - - -); +}) => { + + const router = useRouter(); + const [activeTab, setActiveTab] = useState<{ link: string, index: number }>({ link: 'Players', index: 0 }); + + const communityTabs = [ + { link: 'Players', component: }, + { link: 'Guilds', component: }, + { link: 'Patrons', component: } + ] + + useEffect(() => { + const { query } = router; + if (query.tab) { + const index = communityTabs.findIndex(tab => tab.link === query.tab); + setActiveTab({ link: query.tab as string, index }); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [router.query]); + + const handleTabChange = (index: number) => { + const tab = communityTabs[index]; + setActiveTab({ link: tab.link, index }); + router.push(`/community/?tab=${tab.link}`, undefined, { shallow: true }); + }; + + return ( + + + Community + + + + <> + { + communityTabs.map(({ link }) => { + return( + + {link} + + ) + }) + } + + + + + { + communityTabs.map(({ link, component }) => { + return ( + + {component} + + ) + }) + } + + + + + + + ) + +}; + export default UnifiedCommunityPage;