diff --git a/frontend/components/AttributeFlex.tsx b/frontend/components/AttributeFlex.tsx index 75c82f3c..4f6734b6 100644 --- a/frontend/components/AttributeFlex.tsx +++ b/frontend/components/AttributeFlex.tsx @@ -6,37 +6,50 @@ export interface Attribute { name: string value: number icon: string + onClick?: () => void } interface AttributeGridProps { attributes: Attribute[] } +const getAttributeItem = (item: Attribute, index?: number) => { + const titleCaseName = capitalize(item.name) + return ( + +
+ {`${titleCaseName} +
+ {item.value.toString()} +
+
+
+ ) +} + const AttributeFlex = ({ attributes }: AttributeGridProps) => { - // Get attribute items - const getAttributeItem = (item: Attribute, index: number) => { - const titleCaseName = capitalize(item.name) + const getButton = (item: Attribute, index: number) => { + if (item.onClick === undefined) return getAttributeItem(item, index) return ( - -
- {`${titleCaseName} -
- {item.value.toString()} -
-
-
+ ) } return (
{attributes.map((attribute: Attribute, index) => - getAttributeItem(attribute, index) + getButton(attribute, index) )}
) diff --git a/frontend/components/MetaSection.tsx b/frontend/components/MetaSection.tsx index c890cdad..59a5e3ac 100644 --- a/frontend/components/MetaSection.tsx +++ b/frontend/components/MetaSection.tsx @@ -1,6 +1,6 @@ import Link from "next/link" import Image from "next/image" -import React from "react" +import React, { useCallback } from "react" import Button from "@mui/material/Button" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" @@ -20,6 +20,7 @@ import VotesIcon from "@/images/icons/votes.svg" import SecretsIcon from "@/images/icons/secrets.svg" import AttributeFlex, { Attribute } from "@/components/AttributeFlex" import Collection from "@/classes/Collection" +import SelectedDetail from "@/types/selectedDetail" // Section showing meta info about the game const MetaSection = () => { @@ -33,6 +34,8 @@ const MetaSection = () => { allFactions, allSenators, allSecrets, + setSelectedDetail, + setFactionDetailTab, } = useGameContext() // Get data @@ -48,6 +51,15 @@ const MetaSection = () => { ? allFactions.asArray.find((f) => f.id == hrao.faction) ?? null : null + const handleSecretsClick = useCallback(() => { + if (faction?.id) + setSelectedDetail({ + type: "Faction", + id: faction.id, + } as SelectedDetail) + setFactionDetailTab(2) + }, []) + let attributeItems: Attribute[] = [] if (faction) { const senators = new Collection( @@ -64,7 +76,12 @@ const MetaSection = () => { const secrets = allSecrets.asArray.filter((s) => s.faction === faction.id) attributeItems = [ { name: "votes", value: totalVotes, icon: VotesIcon }, - { name: "secrets", value: secrets.length, icon: SecretsIcon }, + { + name: "secrets", + value: secrets.length, + icon: SecretsIcon, + onClick: handleSecretsClick, + }, ] }