diff --git a/src/app/components/PlanetConfig/PlanetConfigDialog.tsx b/src/app/components/PlanetConfig/PlanetConfigDialog.tsx new file mode 100644 index 0000000..2fa313e --- /dev/null +++ b/src/app/components/PlanetConfig/PlanetConfigDialog.tsx @@ -0,0 +1,211 @@ +import { PI_TYPES_MAP } from "@/const"; +import { planetCalculations } from "@/planets"; +import { AccessToken, PlanetWithInfo } from "@/types"; +import { + Card, + Checkbox, + FormControlLabel, + Table, + TableBody, + TableCell, + TableRow, + Tooltip, + Typography, + useTheme, +} from "@mui/material"; +import { DateTime } from "luxon"; +import Countdown from "react-countdown"; +import { timeColor } from "../PlanetaryInteraction/timeColors"; +import Image from "next/image"; +import { ColorContext, SessionContext } from "@/app/context/Context"; +import { useContext } from "react"; + +export type PlanetConfig = { + characterId: number; + planetId: number; + excludeFromTotals: boolean; +}; + +export const PlanetConfigDialog = ({ + planet, + character, +}: { + planet: PlanetWithInfo; + character: AccessToken; +}) => { + const theme = useTheme(); + const { colors } = useContext(ColorContext); + const { piPrices, readPlanetConfig, updatePlanetConfig } = + useContext(SessionContext); + const { extractors, localProduction, localImports, localExports } = + planetCalculations(planet); + const planetConfig = readPlanetConfig({ + characterId: character.character.characterId, + planetId: planet.planet_id, + }); + + return ( + + + + + + +
+ + {planet.infoUniverse?.name} +
+
+
+ {planet.upgrade_level} + +
+ {extractors.map((e, idx) => { + return ( +
+ + {e ? ( + + ) : ( + "STOPPED" + )} + + + { + PI_TYPES_MAP[ + e.extractor_details?.product_type_id ?? 0 + ]?.name + } + +
+ ); + })} +
+
+ +
+ {Array.from(localProduction).map((schematic, idx) => { + return ( + + {schematic[1].name} + + ); + })} +
+
+ +
+ {localImports.map((i) => ( + + {PI_TYPES_MAP[i.type_id].name} + + ))} +
+
+ +
+ {localExports.map((exports) => ( + + {PI_TYPES_MAP[exports.typeId].name} + + ))} +
+
+ +
+ {localExports.map((exports) => ( + + {exports.amount} + + ))} +
+
+ +
+ {localExports.map((e) => { + const valueInMillions = + (((piPrices?.appraisal.items.find( + (a) => a.typeID === e.typeId, + )?.prices.sell.min ?? 0) * + e.amount) / + 1000000) * + 24 * + 30; + const displayValue = + valueInMillions >= 1000 + ? `${(valueInMillions / 1000).toFixed(2)} B` + : `${valueInMillions.toFixed(2)} M`; + + return ( + + {displayValue} + + ); + })} +
+
+
+
+
+ + Planet configuration + + updatePlanetConfig({ + ...planetConfig, + excludeFromTotals: !planetConfig.excludeFromTotals, + }) + } + /> + } + label="Consumed by production chain" + /> + +
+ ); +}; diff --git a/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx b/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx index 0c60f79..bbb0979 100644 --- a/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx +++ b/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx @@ -18,6 +18,7 @@ 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"; const Transition = forwardRef(function Transition( props: TransitionProps & { @@ -38,6 +39,7 @@ export const PlanetTableRow = ({ const theme = useTheme(); const [planetRenderOpen, setPlanetRenderOpen] = useState(false); + const [planetConfigOpen, setPlanetConfigOpen] = useState(false); const handle3DrenderOpen = () => { setPlanetRenderOpen(true); @@ -47,6 +49,14 @@ export const PlanetTableRow = ({ setPlanetRenderOpen(false); }; + const handlePlanetConfigOpen = () => { + setPlanetConfigOpen(true); + }; + + const handlePlanetConfigClose = () => { + setPlanetConfigOpen(false); + }; + const { piPrices, alertMode } = useContext(SessionContext); const planetInfo = planet.info; const planetInfoUniverse = planet.infoUniverse; @@ -194,6 +204,14 @@ export const PlanetTableRow = ({ })} + + + + + + + + + + ); }; diff --git a/src/app/context/Context.tsx b/src/app/context/Context.tsx index cf73fd9..f48ba77 100644 --- a/src/app/context/Context.tsx +++ b/src/app/context/Context.tsx @@ -1,6 +1,7 @@ import { EvePraisalResult } from "@/eve-praisal"; import { AccessToken, CharacterUpdate } from "@/types"; import { Dispatch, SetStateAction, createContext } from "react"; +import { PlanetConfig } from "../components/PlanetConfig/PlanetConfigDialog"; export const CharacterContext = createContext<{ characters: AccessToken[]; @@ -27,6 +28,14 @@ export const SessionContext = createContext<{ alertMode: boolean; toggleAlertMode: () => void; piPrices: EvePraisalResult | undefined; + updatePlanetConfig: (config: PlanetConfig) => void; + readPlanetConfig: ({ + characterId, + planetId, + }: { + characterId: number; + planetId: number; + }) => PlanetConfig; }>({ sessionReady: false, refreshSession: () => {}, @@ -40,6 +49,16 @@ export const SessionContext = createContext<{ alertMode: false, toggleAlertMode: () => {}, piPrices: undefined, + updatePlanetConfig: () => {}, + readPlanetConfig: ({ + planetId, + characterId, + }: { + planetId: number; + characterId: number; + }) => { + return { characterId, planetId, excludeFromTotals: true }; + }, }); export type ColorSelectionType = { defaultColor: string; diff --git a/src/app/page.tsx b/src/app/page.tsx index 1c8b4a0..3e08411 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -17,6 +17,7 @@ import { import { useSearchParams } from "next/navigation"; import { EvePraisalResult, fetchAllPrices } from "@/eve-praisal"; import { getPlanet, getPlanetUniverse, getPlanets } from "@/planets"; +import { PlanetConfig } from "./components/PlanetConfig/PlanetConfigDialog"; const Home = () => { const [characters, setCharacters] = useState([]); @@ -27,6 +28,7 @@ const Home = () => { const [piPrices, setPiPrices] = useState( undefined, ); + const [colors, setColors] = useState(defaultColors); const [alertMode, setAlertMode] = useState(false); const searchParams = useSearchParams(); @@ -126,6 +128,22 @@ const Home = () => { setAlertMode(!alertMode); }; + const updatePlanetConfig = (config: PlanetConfig) => { + console.log("poop"); + }; + + const readPlanetConfig = ({ + planetId, + characterId, + }: { + planetId: number; + characterId: number; + }): PlanetConfig => { + const defaultConfig = { planetId, characterId, excludeFromTotals: false }; + + return defaultConfig; + }; + useEffect(() => { const storedCompactMode = localStorage.getItem("compactMode"); if (!storedCompactMode) return; @@ -156,7 +174,6 @@ const Home = () => { localStorage.setItem("colors", JSON.stringify(colors)); }, [colors]); - // Initialize EVE PI useEffect(() => { fetch("api/env") .then((r) => r.json()) @@ -207,6 +224,8 @@ const Home = () => { piPrices, alertMode, toggleAlertMode, + updatePlanetConfig, + readPlanetConfig, }} >