import { Box, Flex, Menu, MenuButton, MenuGroup, MenuItem, MenuList, } from "@chakra-ui/core"; import { useTranslation } from "lib/useMockT"; import { useMyTheme } from "lib/useMyTheme"; import { useRouter } from "next/dist/client/router"; import Image from "next/image"; import Link from "next/link"; // FIXME: " Warning: Text content did not match. Server: ": Nov 6" Client: ": 6 Nov" " const getFirstFridayDate = () => { const today = new Date(); const month = today.getDate() - ((1 + today.getDay()) % 7) <= 0 ? today.getMonth() : today.getMonth() + 1; let day = 1; while (day <= 7) { const dateOfVoting = new Date( Date.UTC(today.getFullYear(), month, day, 15, 0, 0) ); if (dateOfVoting.getDay() === 5) return dateOfVoting; day++; } console.error("Couldn't resolve first friday of the month for voting"); return new Date(2000, 1, 1); }; export const navIcons: { code: string; displayName: string; menuItems: { code: string; displayName: string; toAppend?: string; }[]; }[] = [ { code: "xsearch", displayName: "Top 500", menuItems: [ { code: "xsearch", displayName: "Browser" }, { code: "xtrends", displayName: "Trends" }, { code: "xleaderboards", displayName: "Leaderboards" }, ], }, //{ code: "sr", displayName: "Salmon Run", menuItems: [] }, { code: "builds", displayName: "Builds", menuItems: [ { code: "builds", displayName: "Browser" }, { code: "analyzer", displayName: "Analyzer" }, ], }, { code: "calendar", displayName: "Calendar", menuItems: [] }, { code: "freeagents", displayName: "Free Agents", menuItems: [] }, //{ name: "teams", displayName: "Teams" }, { code: "plans", displayName: "Map Planner", menuItems: [] }, { code: "tournaments", displayName: "Tournaments", menuItems: [] }, { code: "plus", displayName: "Plus Server", menuItems: [ { code: "plus/voting", displayName: "Voting", toAppend: ": " + getFirstFridayDate().toLocaleString("default", { month: "short", day: "numeric", }), }, { code: "plus", displayName: "Suggested and vouched players" }, { code: "plus/history", displayName: "Voting history" }, { code: "draft", displayName: "Draft Cup" }, { code: "plus/faq", displayName: "FAQ" }, ], }, ]; const IconNavBar = () => { const { t } = useTranslation(); const { secondaryBgColor, textColor, themeColor, gray } = useMyTheme(); const pathname = useRouter().pathname; // FIXME //const isVoting = !!plusInfoData?.plusInfo?.voting_ends; const isVoting = false; return ( {navIcons.map(({ displayName, code, menuItems }) => { const codesTogether = "/" + code + menuItems.reduce((acc, { code }) => acc + "/" + code, ""); const isActive = pathname !== "/" && codesTogether.includes(pathname); const MenuNavIcon = () => ( {t(`navigation;${displayName}`)} {/* FIXME: same width for each */} {code} {menuItems.length > 0 && ( )} ); if (!menuItems.length) { return ( ); } return ( {menuItems.map((item) => ( {pathname === "/" + item.code ? ( ) : ( )} {t( `navigation;${ item.displayName !== "Voting" ? item.displayName : isVoting ? "Voting" : "Next voting" }` )} {!isVoting && item.toAppend} ))} ); })} ); }; export default IconNavBar;