weapon selector grizzco

This commit is contained in:
Kalle (Sendou)
2020-12-19 19:28:43 +02:00
parent 167ddc08a6
commit eb7aa9fb95
4 changed files with 30 additions and 12 deletions

View File

@@ -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<WeaponImageProps> = ({ name, size, noTitle }) => {
<Image
src={`/weapons/${name.replace(".", "").trim()}.png`}
alt={i18n._(name)}
title={noTitle ? undefined : i18n._(name)}
title={getTitle()}
width={size}
height={size}
/>
);
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;

View File

@@ -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<SingleSelectorProps | MultiSelectorProps> = (
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<SingleSelectorProps | MultiSelectorProps> = (
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,

View File

@@ -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;

View File

@@ -4,8 +4,6 @@ import useSWR from "swr";
export function useSalmonRunRecords() {
const { data = [] } = useSWR<GetAllSalmonRunRecordsData>("/api/sr/records");
console.log({ data });
return {
data: data.filter((record) => record.approved),
pendingCount: data.reduce(