From 9d07ea934c29482d618c55707fd7d229c96b9f61 Mon Sep 17 00:00:00 2001 From: Calli Date: Mon, 27 May 2024 09:36:28 +0300 Subject: [PATCH] Implement planet exclusion from totals calculations --- .env.example | 3 ++- .../PlanetaryInteraction/PlanetTableRow.tsx | 21 +++++++++++++++---- .../PlanetaryInteractionRow.tsx | 5 +++++ src/app/components/Summary/Summary.tsx | 5 +++-- src/app/page.tsx | 15 +++++++++++-- src/pages/api/refresh.ts | 2 +- src/pages/api/token.ts | 1 + src/types.ts | 2 ++ 8 files changed, 44 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 5ba24c0..431e99b 100644 --- a/.env.example +++ b/.env.example @@ -2,4 +2,5 @@ EVE_SSO_CLIENT_ID=Client ID EVE_SSO_SECRET=Secret Key EVE_SSO_CALLBACK_URL=Callback URL (This should be the domain you are hosting at or if run locally it should be http://localhost:3000) -NEXT_PUBLIC_PRAISAL_URL=https://praisal.avanto.tk/appraisal/structured.json?persist=no \ No newline at end of file +NEXT_PUBLIC_PRAISAL_URL=https://praisal.avanto.tk/appraisal/structured.json?persist=no +SENTRY_AUTH_TOKEN=Sentry token for error reporting. diff --git a/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx b/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx index bbb0979..be11917 100644 --- a/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx +++ b/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx @@ -1,7 +1,7 @@ -import { SessionContext, ColorContext } from "@/app/context/Context"; +import { ColorContext, SessionContext } from "@/app/context/Context"; import { PI_TYPES_MAP } from "@/const"; -import { AccessToken, PlanetWithInfo } from "@/types"; import { planetCalculations } from "@/planets"; +import { AccessToken, PlanetWithInfo } from "@/types"; import CloseIcon from "@mui/icons-material/Close"; import { Button, Tooltip, Typography, useTheme } from "@mui/material"; import AppBar from "@mui/material/AppBar"; @@ -16,9 +16,9 @@ import { DateTime } from "luxon"; import Image from "next/image"; import React, { forwardRef, useContext, useState } from "react"; import Countdown from "react-countdown"; -import PinsCanvas3D from "./PinsCanvas3D"; -import { timeColor, alertModeVisibility } from "./timeColors"; import { PlanetConfigDialog } from "../PlanetConfig/PlanetConfigDialog"; +import PinsCanvas3D from "./PinsCanvas3D"; +import { alertModeVisibility, timeColor } from "./timeColors"; const Transition = forwardRef(function Transition( props: TransitionProps & { @@ -62,6 +62,7 @@ export const PlanetTableRow = ({ const planetInfoUniverse = planet.infoUniverse; const { expired, extractors, localProduction, localImports, localExports } = planetCalculations(planet); + const planetConfig = character.planetConfig.find(p => p.planetId === planet.planet_id) const { colors } = useContext(ColorContext); return ( + +
+ {localExports.map((exports) => ( + + {planetConfig?.excludeFromTotals ? 'ex' : ''} + + ))} +
+
{localExports.map((exports) => ( diff --git a/src/app/components/PlanetaryInteraction/PlanetaryInteractionRow.tsx b/src/app/components/PlanetaryInteraction/PlanetaryInteractionRow.tsx index 4f3a01a..4fbe478 100644 --- a/src/app/components/PlanetaryInteraction/PlanetaryInteractionRow.tsx +++ b/src/app/components/PlanetaryInteraction/PlanetaryInteractionRow.tsx @@ -77,6 +77,11 @@ const PlanetaryIteractionTable = ({ + + + Excluded + + u/h diff --git a/src/app/components/Summary/Summary.tsx b/src/app/components/Summary/Summary.tsx index 63760f7..f68bd3a 100644 --- a/src/app/components/Summary/Summary.tsx +++ b/src/app/components/Summary/Summary.tsx @@ -40,9 +40,10 @@ const displayValue = (valueInMillions: number): string => : `${valueInMillions.toFixed(2)} M`; export const Summary = ({ characters }: { characters: AccessToken[] }) => { - const { piPrices, alertMode } = useContext(SessionContext); + const { piPrices } = useContext(SessionContext); const exports = characters.flatMap((char) => { - return char.planets.flatMap((planet) => { + return char.planets.filter(p => !char.planetConfig.some(c => c.planetId == p.planet_id && c.excludeFromTotals)) + .flatMap((planet) => { const { localExports } = planetCalculations(planet); return localExports; }); diff --git a/src/app/page.tsx b/src/app/page.tsx index 51c49ea..3900e0f 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -145,7 +145,18 @@ const Home = () => { }; const updatePlanetConfig = (config: PlanetConfig) => { - console.log("poop"); + const charactersToSave = characters.map((c) => { + if (c.character.characterId === config.characterId) { + return { + ...c, + planetConfig: [...c.planetConfig.filter(p => p.planetId !== config.planetId), config] + } + } + + return c; + }); + setCharacters(charactersToSave); + saveCharacters(charactersToSave); }; const readPlanetConfig = ({ @@ -157,7 +168,7 @@ const Home = () => { }): PlanetConfig => { const defaultConfig = { planetId, characterId, excludeFromTotals: false }; - return defaultConfig; + return characters.find(c => c.character.characterId === characterId)?.planetConfig.find(p => p.planetId === planetId) ?? defaultConfig }; useEffect(() => { diff --git a/src/pages/api/refresh.ts b/src/pages/api/refresh.ts index d1ad953..ae916bd 100644 --- a/src/pages/api/refresh.ts +++ b/src/pages/api/refresh.ts @@ -34,7 +34,6 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { headers, }).then((res) => res.json()); const character = extractCharacterFromToken(response); - const token: AccessToken = { access_token: response.access_token, token_type: response.token_type, @@ -49,6 +48,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { comment: accessToken.comment, system: accessToken.system, planets: [], + planetConfig: accessToken.planetConfig ?? [], }; console.log("Refresh", character.name, character.characterId); diff --git a/src/pages/api/token.ts b/src/pages/api/token.ts index 713b56e..4bf1d1d 100644 --- a/src/pages/api/token.ts +++ b/src/pages/api/token.ts @@ -50,6 +50,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { comment: "", system: "", planets: [], + planetConfig: [], }; res.json(token); } else { diff --git a/src/types.ts b/src/types.ts index f359f6f..dc1a7a6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,4 @@ +import { PlanetConfig } from "./app/components/PlanetConfig/PlanetConfigDialog"; import { Api } from "./esi-api"; export interface AccessToken { @@ -11,6 +12,7 @@ export interface AccessToken { comment: string; system: string; planets: PlanetWithInfo[]; + planetConfig: PlanetConfig[]; } export interface Character {