add off-balance alert treshold to settings
This commit is contained in:
@@ -73,7 +73,7 @@ export const PlanetTableRow = ({
|
|||||||
setPlanetConfigOpen(false);
|
setPlanetConfigOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const { piPrices, alertMode, updatePlanetConfig, readPlanetConfig } = useContext(SessionContext);
|
const { piPrices, alertMode, updatePlanetConfig, readPlanetConfig, balanceThreshold } = useContext(SessionContext);
|
||||||
const planetInfo = planet.info;
|
const planetInfo = planet.info;
|
||||||
const planetInfoUniverse = planet.infoUniverse;
|
const planetInfoUniverse = planet.infoUniverse;
|
||||||
const { expired, extractors, localProduction, localImports, localExports } =
|
const { expired, extractors, localProduction, localImports, localExports } =
|
||||||
@@ -113,7 +113,7 @@ export const PlanetTableRow = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const hasLargeExtractorDifference = extractorAverages.length === 2 &&
|
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 =>
|
const storageFacilities = planetInfo.pins.filter(pin =>
|
||||||
STORAGE_IDS().some(storage => storage.type_id === pin.type_id)
|
STORAGE_IDS().some(storage => storage.type_id === pin.type_id)
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
ColorContext,
|
ColorContext,
|
||||||
ColorSelectionType,
|
ColorSelectionType,
|
||||||
|
SessionContext,
|
||||||
} from "@/app/context/Context";
|
} from "@/app/context/Context";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -10,14 +11,16 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Typography,
|
Typography,
|
||||||
|
TextField,
|
||||||
|
Box,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { ColorChangeHandler, ColorResult, CompactPicker } from "react-color";
|
import { ColorChangeHandler, ColorResult, CompactPicker } from "react-color";
|
||||||
import React from "react";
|
import React, { useState, useContext } from "react";
|
||||||
import { useContext } from "react";
|
|
||||||
|
|
||||||
export const SettingsButton = () => {
|
export const SettingsButton = () => {
|
||||||
const { colors, setColors } = useContext(ColorContext);
|
const { colors, setColors } = useContext(ColorContext);
|
||||||
const [open, setOpen] = React.useState(false);
|
const { balanceThreshold, setBalanceThreshold } = useContext(SessionContext);
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
const handleClickOpen = () => {
|
const handleClickOpen = () => {
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
@@ -26,6 +29,7 @@ export const SettingsButton = () => {
|
|||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleColorSelection = (key: string, currentColors: ColorSelectionType) => (selection: ColorResult) => {
|
const handleColorSelection = (key: string, currentColors: ColorSelectionType) => (selection: ColorResult) => {
|
||||||
console.log(key, selection.hex)
|
console.log(key, selection.hex)
|
||||||
setColors({
|
setColors({
|
||||||
@@ -34,20 +38,44 @@ export const SettingsButton = () => {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleBalanceThresholdChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const value = parseInt(event.target.value);
|
||||||
|
if (!isNaN(value) && value >= 0 && value <= 100000) {
|
||||||
|
setBalanceThreshold(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip title="Toggle settings dialog">
|
<Tooltip title="Toggle settings dialog">
|
||||||
<>
|
<>
|
||||||
<Button onClick={handleClickOpen}>Settings</Button>
|
<Button onClick={handleClickOpen} color="inherit">
|
||||||
|
Settings
|
||||||
|
</Button>
|
||||||
<Dialog
|
<Dialog
|
||||||
open={open}
|
open={open}
|
||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
aria-labelledby="alert-dialog-title"
|
aria-labelledby="alert-dialog-title"
|
||||||
aria-describedby="alert-dialog-description"
|
aria-describedby="alert-dialog-description"
|
||||||
>
|
>
|
||||||
|
|
||||||
<DialogTitle id="alert-dialog-title">
|
<DialogTitle id="alert-dialog-title">
|
||||||
{"Override default timer colors"}
|
{"Settings"}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
|
|
||||||
<DialogContent style={{ paddingTop: "1rem" }}>
|
<DialogContent style={{ paddingTop: "1rem" }}>
|
||||||
|
<Box sx={{ mt: 2 }}>
|
||||||
|
<Typography variant="subtitle1">Balance Threshold</Typography>
|
||||||
|
<TextField
|
||||||
|
type="number"
|
||||||
|
value={balanceThreshold}
|
||||||
|
onChange={handleBalanceThresholdChange}
|
||||||
|
fullWidth
|
||||||
|
margin="normal"
|
||||||
|
inputProps={{ min: 0, max: 100000 }}
|
||||||
|
helperText="Set the threshold for balance alerts (0-100,000)"
|
||||||
|
error={balanceThreshold < 0 || balanceThreshold > 100000}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
{Object.keys(colors).map((key) => {
|
{Object.keys(colors).map((key) => {
|
||||||
return (
|
return (
|
||||||
<div key={`color-row-${key}`}>
|
<div key={`color-row-${key}`}>
|
||||||
@@ -59,6 +87,7 @@ export const SettingsButton = () => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={handleClose}>Close</Button>
|
<Button onClick={handleClose}>Close</Button>
|
||||||
|
@@ -35,6 +35,8 @@ export const SessionContext = createContext<{
|
|||||||
characterId: number;
|
characterId: number;
|
||||||
planetId: number;
|
planetId: number;
|
||||||
}) => PlanetConfig;
|
}) => PlanetConfig;
|
||||||
|
balanceThreshold: number;
|
||||||
|
setBalanceThreshold: Dispatch<SetStateAction<number>>;
|
||||||
}>({
|
}>({
|
||||||
sessionReady: false,
|
sessionReady: false,
|
||||||
refreshSession: () => {},
|
refreshSession: () => {},
|
||||||
@@ -58,6 +60,8 @@ export const SessionContext = createContext<{
|
|||||||
}) => {
|
}) => {
|
||||||
return { characterId, planetId, excludeFromTotals: true };
|
return { characterId, planetId, excludeFromTotals: true };
|
||||||
},
|
},
|
||||||
|
balanceThreshold: 1000,
|
||||||
|
setBalanceThreshold: () => {},
|
||||||
});
|
});
|
||||||
export type ColorSelectionType = {
|
export type ColorSelectionType = {
|
||||||
defaultColor: string;
|
defaultColor: string;
|
||||||
|
@@ -29,6 +29,7 @@ const Home = () => {
|
|||||||
const [piPrices, setPiPrices] = useState<EvePraisalResult | undefined>(
|
const [piPrices, setPiPrices] = useState<EvePraisalResult | undefined>(
|
||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
|
const [balanceThreshold, setBalanceThreshold] = useState(1000);
|
||||||
|
|
||||||
const [colors, setColors] = useState<ColorSelectionType>(defaultColors);
|
const [colors, setColors] = useState<ColorSelectionType>(defaultColors);
|
||||||
const [alertMode, setAlertMode] = useState(false);
|
const [alertMode, setAlertMode] = useState(false);
|
||||||
@@ -199,6 +200,17 @@ const Home = () => {
|
|||||||
setAlertMode(JSON.parse(storedAlertMode));
|
setAlertMode(JSON.parse(storedAlertMode));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const storedBalanceThreshold = localStorage.getItem("balanceThreshold");
|
||||||
|
if (storedBalanceThreshold) {
|
||||||
|
setBalanceThreshold(parseInt(storedBalanceThreshold));
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem("balanceThreshold", balanceThreshold.toString());
|
||||||
|
}, [balanceThreshold]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
localStorage.setItem("compactMode", compactMode ? "true" : "false");
|
localStorage.setItem("compactMode", compactMode ? "true" : "false");
|
||||||
}, [compactMode]);
|
}, [compactMode]);
|
||||||
@@ -264,6 +276,8 @@ const Home = () => {
|
|||||||
toggleAlertMode,
|
toggleAlertMode,
|
||||||
updatePlanetConfig,
|
updatePlanetConfig,
|
||||||
readPlanetConfig,
|
readPlanetConfig,
|
||||||
|
balanceThreshold,
|
||||||
|
setBalanceThreshold,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CharacterContext.Provider
|
<CharacterContext.Provider
|
||||||
|
Reference in New Issue
Block a user