From 0fc12227cf4d1b76cc30848158a5f39fce0bcfc2 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Sat, 28 Nov 2020 13:02:40 +0200 Subject: [PATCH] mode icons in description --- TODO.md | 12 +++++-- components/builds/BuildCard.tsx | 60 +++++++++++++++++++++------------ components/common/ModeImage.tsx | 4 +-- pages/api/builds/index.ts | 8 +++++ pages/u/[identifier].tsx | 2 -- 5 files changed, 58 insertions(+), 28 deletions(-) diff --git a/TODO.md b/TODO.md index 21456456a..511ddbacb 100644 --- a/TODO.md +++ b/TODO.md @@ -5,8 +5,8 @@ - [x] Build Analyzer - [x] Import /analyzer - [x] Builds link to /analyzer -- [ ] Check that user page fallback / redirect works -- [ ] Builds mode icons +- [x] Check that user page fallback / redirect works +- [x] Builds mode icons - [ ] Script to parse data from Top 500 .json to the DB - [ ] Top 500 Leaderboards - [ ] Localization @@ -28,5 +28,13 @@ ### Future - [ ] Salmon Run Leaderboards + - [ ] As a user... + - [ ] View leaderboards of different categories + - [ ] Submit a new result + - [ ] As an admin... + - [ ] Submit a new result without the need for approval + - [ ] Approve or delete submitted results + - [ ] Edit existing result by any user + - [ ] Delete existing result of any user - [ ] Team pages - [ ] Ladder diff --git a/components/builds/BuildCard.tsx b/components/builds/BuildCard.tsx index 6784d67cf..6fd1c3390 100644 --- a/components/builds/BuildCard.tsx +++ b/components/builds/BuildCard.tsx @@ -10,6 +10,7 @@ import { } from "@chakra-ui/react"; import { Plural, t, Trans } from "@lingui/macro"; import { Ability, Prisma } from "@prisma/client"; +import ModeImage from "components/common/ModeImage"; import UserAvatar from "components/common/UserAvatar"; import WeaponImage from "components/common/WeaponImage"; import { getEmojiFlag } from "countries-list"; @@ -138,28 +139,7 @@ const BuildCard: React.FC = ({ /> - {build.description && ( - - - } - /> - - - - {build.description} - - - - )} + {onEdit && ( = ({ ); + + function Description() { + if (build.modes.length === 0 && !build.description) return null; + + return ( + + + } + /> + + + + + + {build.modes.map((mode) => ( + + + + ))} + + {build.description} + + + + + ); + } }; export default BuildCard; diff --git a/components/common/ModeImage.tsx b/components/common/ModeImage.tsx index 9a79887fc..730122695 100644 --- a/components/common/ModeImage.tsx +++ b/components/common/ModeImage.tsx @@ -2,8 +2,8 @@ import Image from "next/image"; import { CSSProperties } from "react"; interface ModeImageProps { - mode: "SZ" | "TC" | "RM" | "CB"; - size: 32 | 64 | 128; + mode: "TW" | "SZ" | "TC" | "RM" | "CB"; + size: 24 | 32 | 64 | 128; onClick?: () => void; style?: CSSProperties; } diff --git a/pages/api/builds/index.ts b/pages/api/builds/index.ts index cd35fa9f6..998617614 100644 --- a/pages/api/builds/index.ts +++ b/pages/api/builds/index.ts @@ -8,6 +8,8 @@ import DBClient from "prisma/client"; const prisma = DBClient.getInstance().prisma; +const modes = ["TW", "SZ", "TC", "RM", "CB"]; + const postHandler = async (req: NextApiRequest, res: NextApiResponse) => { const user = await getMySession(req); if (!user) return res.status(401).end(); @@ -49,6 +51,9 @@ const postHandler = async (req: NextApiRequest, res: NextApiResponse) => { await prisma.build.create({ data: { ...parsed.data, + modes: parsed.data.modes.sort( + (a, b) => modes.indexOf(a) - modes.indexOf(b) + ), abilityPoints: getAbilityPoints( parsed.data.headAbilities, parsed.data.clothingAbilities, @@ -97,6 +102,9 @@ const updateHandler = async (req: NextApiRequest, res: NextApiResponse) => { where: { id }, data: { ...parsed.data, + modes: parsed.data.modes.sort( + (a, b) => modes.indexOf(a) - modes.indexOf(b) + ), abilityPoints: getAbilityPoints( parsed.data.headAbilities, parsed.data.clothingAbilities, diff --git a/pages/u/[identifier].tsx b/pages/u/[identifier].tsx index 7e31545eb..29cc680fa 100644 --- a/pages/u/[identifier].tsx +++ b/pages/u/[identifier].tsx @@ -31,8 +31,6 @@ interface Props { peakXPowers: Partial>; } -// TODO: when fallback in production seems like the site will never load till F5 - const ProfilePage = (props: Props) => { const [showProfileModal, setShowProfileModal] = useState(false); const [buildToEdit, setBuildToEdit] = useState(false);