From eb7aa9fb95e318c8ae4289d702883b95af6b4f6e Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Sat, 19 Dec 2020 19:28:43 +0200 Subject: [PATCH] weapon selector grizzco --- components/common/WeaponImage.tsx | 11 ++++++++++- components/common/WeaponSelector.tsx | 27 +++++++++++++++++++-------- components/sr/RotationSelector.tsx | 2 +- hooks/sr.ts | 2 -- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/components/common/WeaponImage.tsx b/components/common/WeaponImage.tsx index b076a16cb..8c889da28 100644 --- a/components/common/WeaponImage.tsx +++ b/components/common/WeaponImage.tsx @@ -1,3 +1,4 @@ +import { t } from "@lingui/macro"; import { useLingui } from "@lingui/react"; import Image from "next/image"; import React from "react"; @@ -15,11 +16,19 @@ const WeaponImage: React.FC = ({ name, size, noTitle }) => { {i18n._(name)} ); + + function getTitle() { + if (noTitle) return undefined; + if (name === "RANDOM") return t`Random`; + if (name === "RANDOM_GRIZZCO") return t`Random (Grizzco)`; + + return i18n._(name); + } }; export default WeaponImage; diff --git a/components/common/WeaponSelector.tsx b/components/common/WeaponSelector.tsx index 232d31fb5..213b50a7f 100644 --- a/components/common/WeaponSelector.tsx +++ b/components/common/WeaponSelector.tsx @@ -1,5 +1,5 @@ import { Box, Center, Flex } from "@chakra-ui/react"; -import { Trans } from "@lingui/macro"; +import { t, Trans } from "@lingui/macro"; import { useLingui } from "@lingui/react"; import { salmonRunWeapons, @@ -69,7 +69,7 @@ const WeaponSelector: React.FC = ( label: i18n._(category.name), options: category.weapons.map((weapon) => ({ value: weapon, - label: i18n._(weapon), + label: getLabel(weapon), })), }))} value={getValue()} @@ -99,27 +99,38 @@ const WeaponSelector: React.FC = ( function getValue() { if (typeof props.value === "string") { - return { value: props.value, label: i18n._(props.value) }; + return { value: props.value, label: getLabel(props.value) }; } if (Array.isArray(props.value)) { return props.value.map((singleValue) => ({ value: singleValue, - label: i18n._(singleValue), + label: getLabel(singleValue), })); } return undefined; } + function getLabel(value: string) { + if (value === "RANDOM") return t`Random`; + if (value === "RANDOM_GRIZZCO") return t`Random (Grizzco)`; + + return i18n._(value); + } + function getWeaponArray() { if (isTooManyItems()) return []; if (props.pool === "WITH_ALTS") return weaponsWithHeroCategorized; if (props.pool === "SALMON_RUN") - return weaponsWithHeroCategorized.map((category) => ({ - ...category, - weapons: category.weapons.filter((wpn) => salmonRunWeapons.has(wpn)), - })); + return [ + { name: t`Salmon Run`, weapons: ["RANDOM", "RANDOM_GRIZZCO"] }, + ].concat( + weaponsWithHeroCategorized.map((category) => ({ + ...category, + weapons: category.weapons.filter((wpn) => salmonRunWeapons.has(wpn)), + })) + ); return weaponsWithHeroCategorized.map((category) => ({ ...category, diff --git a/components/sr/RotationSelector.tsx b/components/sr/RotationSelector.tsx index e3cf95a3a..7ba2b99a1 100644 --- a/components/sr/RotationSelector.tsx +++ b/components/sr/RotationSelector.tsx @@ -10,7 +10,7 @@ import { GetAllSalmonRunRotationsData } from "prisma/queries/getAllSalmonRunRota import { useState } from "react"; import useSWR from "swr"; -const randomToNaturalName = { +export const randomToNaturalName = { RANDOM: t`Random`, RANDOM_GRIZZCO: t`Random (Grizzco)`, } as const; diff --git a/hooks/sr.ts b/hooks/sr.ts index dfdf5b676..8282d2448 100644 --- a/hooks/sr.ts +++ b/hooks/sr.ts @@ -4,8 +4,6 @@ import useSWR from "swr"; export function useSalmonRunRecords() { const { data = [] } = useSWR("/api/sr/records"); - console.log({ data }); - return { data: data.filter((record) => record.approved), pendingCount: data.reduce(