diff --git a/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx b/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx index f756a5f..f3ef434 100644 --- a/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx +++ b/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx @@ -73,7 +73,7 @@ export const PlanetTableRow = ({ setPlanetConfigOpen(false); }; - const { piPrices, alertMode, updatePlanetConfig, readPlanetConfig } = useContext(SessionContext); + const { piPrices, alertMode, updatePlanetConfig, readPlanetConfig, balanceThreshold } = useContext(SessionContext); const planetInfo = planet.info; const planetInfoUniverse = planet.infoUniverse; const { expired, extractors, localProduction, localImports, localExports } = @@ -113,7 +113,7 @@ export const PlanetTableRow = ({ }); const hasLargeExtractorDifference = extractorAverages.length === 2 && - Math.abs(extractorAverages[0].averagePerHour - extractorAverages[1].averagePerHour) > 1000; + Math.abs(extractorAverages[0].averagePerHour - extractorAverages[1].averagePerHour) > balanceThreshold; const storageFacilities = planetInfo.pins.filter(pin => STORAGE_IDS().some(storage => storage.type_id === pin.type_id) diff --git a/src/app/components/Settings/SettingsButtons.tsx b/src/app/components/Settings/SettingsButtons.tsx index 2806106..881767d 100644 --- a/src/app/components/Settings/SettingsButtons.tsx +++ b/src/app/components/Settings/SettingsButtons.tsx @@ -1,6 +1,7 @@ import { ColorContext, ColorSelectionType, + SessionContext, } from "@/app/context/Context"; import { Button, @@ -10,14 +11,16 @@ import { DialogTitle, Tooltip, Typography, + TextField, + Box, } from "@mui/material"; import { ColorChangeHandler, ColorResult, CompactPicker } from "react-color"; -import React from "react"; -import { useContext } from "react"; +import React, { useState, useContext } from "react"; export const SettingsButton = () => { const { colors, setColors } = useContext(ColorContext); - const [open, setOpen] = React.useState(false); + const { balanceThreshold, setBalanceThreshold } = useContext(SessionContext); + const [open, setOpen] = useState(false); const handleClickOpen = () => { setOpen(true); @@ -26,6 +29,7 @@ export const SettingsButton = () => { const handleClose = () => { setOpen(false); }; + const handleColorSelection = (key: string, currentColors: ColorSelectionType) => (selection: ColorResult) => { console.log(key, selection.hex) setColors({ @@ -34,20 +38,44 @@ export const SettingsButton = () => { }) }; + const handleBalanceThresholdChange = (event: React.ChangeEvent) => { + const value = parseInt(event.target.value); + if (!isNaN(value) && value >= 0 && value <= 100000) { + setBalanceThreshold(value); + } + }; + return ( <> - + + - {"Override default timer colors"} + {"Settings"} + + + Balance Threshold + 100000} + /> + {Object.keys(colors).map((key) => { return (
@@ -59,6 +87,7 @@ export const SettingsButton = () => {
); })} +
diff --git a/src/app/context/Context.tsx b/src/app/context/Context.tsx index eeecac8..6105767 100644 --- a/src/app/context/Context.tsx +++ b/src/app/context/Context.tsx @@ -35,6 +35,8 @@ export const SessionContext = createContext<{ characterId: number; planetId: number; }) => PlanetConfig; + balanceThreshold: number; + setBalanceThreshold: Dispatch>; }>({ sessionReady: false, refreshSession: () => {}, @@ -58,6 +60,8 @@ export const SessionContext = createContext<{ }) => { return { characterId, planetId, excludeFromTotals: true }; }, + balanceThreshold: 1000, + setBalanceThreshold: () => {}, }); export type ColorSelectionType = { defaultColor: string; diff --git a/src/app/page.tsx b/src/app/page.tsx index 0da784d..314f2e1 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -29,6 +29,7 @@ const Home = () => { const [piPrices, setPiPrices] = useState( undefined, ); + const [balanceThreshold, setBalanceThreshold] = useState(1000); const [colors, setColors] = useState(defaultColors); const [alertMode, setAlertMode] = useState(false); @@ -199,6 +200,17 @@ const Home = () => { setAlertMode(JSON.parse(storedAlertMode)); }, []); + useEffect(() => { + const storedBalanceThreshold = localStorage.getItem("balanceThreshold"); + if (storedBalanceThreshold) { + setBalanceThreshold(parseInt(storedBalanceThreshold)); + } + }, []); + + useEffect(() => { + localStorage.setItem("balanceThreshold", balanceThreshold.toString()); + }, [balanceThreshold]); + useEffect(() => { localStorage.setItem("compactMode", compactMode ? "true" : "false"); }, [compactMode]); @@ -264,6 +276,8 @@ const Home = () => { toggleAlertMode, updatePlanetConfig, readPlanetConfig, + balanceThreshold, + setBalanceThreshold, }} >