Alert mode to filter only planets that need an action
This commit is contained in:
21
src/app/components/AlertModeButton/AlertModeButton.tsx
Normal file
21
src/app/components/AlertModeButton/AlertModeButton.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { SessionContext } from "@/app/context/Context";
|
||||||
|
import { Button, Tooltip } from "@mui/material";
|
||||||
|
import { useContext } from "react";
|
||||||
|
|
||||||
|
export const AlertModeButton = () => {
|
||||||
|
const { alertMode, toggleAlertMode } = useContext(SessionContext);
|
||||||
|
return (
|
||||||
|
<Tooltip title="Toggle alert mode to show only accounts and planets that need action.">
|
||||||
|
<Button
|
||||||
|
style={{
|
||||||
|
backgroundColor: alertMode
|
||||||
|
? "rgba(144, 202, 249, 0.08)"
|
||||||
|
: "inherit",
|
||||||
|
}}
|
||||||
|
onClick={toggleAlertMode}
|
||||||
|
>
|
||||||
|
Alert mode
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
};
|
@@ -18,6 +18,7 @@ import { GitHubButton } from "../Github/GitHubButton";
|
|||||||
import { LoginButton } from "../Login/LoginButton";
|
import { LoginButton } from "../Login/LoginButton";
|
||||||
import { PlanModeButton } from "../PlanModeButton/PlanModeButton";
|
import { PlanModeButton } from "../PlanModeButton/PlanModeButton";
|
||||||
import { SettingsButton } from "../Settings/SettingsButtons";
|
import { SettingsButton } from "../Settings/SettingsButtons";
|
||||||
|
import { AlertModeButton } from "../AlertModeButton/AlertModeButton";
|
||||||
|
|
||||||
function ResponsiveAppBar() {
|
function ResponsiveAppBar() {
|
||||||
const [anchorElNav, setAnchorElNav] = React.useState<null | HTMLElement>(
|
const [anchorElNav, setAnchorElNav] = React.useState<null | HTMLElement>(
|
||||||
@@ -111,6 +112,9 @@ function ResponsiveAppBar() {
|
|||||||
<MenuItem onClick={handleCloseNavMenu}>
|
<MenuItem onClick={handleCloseNavMenu}>
|
||||||
<PlanModeButton />
|
<PlanModeButton />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
<MenuItem onClick={handleCloseNavMenu}>
|
||||||
|
<AlertModeButton />
|
||||||
|
</MenuItem>
|
||||||
</Menu>
|
</Menu>
|
||||||
</Box>
|
</Box>
|
||||||
<PublicIcon sx={{ display: { xs: "flex", md: "none" }, mr: 1 }} />
|
<PublicIcon sx={{ display: { xs: "flex", md: "none" }, mr: 1 }} />
|
||||||
@@ -149,6 +153,7 @@ function ResponsiveAppBar() {
|
|||||||
<SettingsButton />
|
<SettingsButton />
|
||||||
<CompactModeButton />
|
<CompactModeButton />
|
||||||
<PlanModeButton />
|
<PlanModeButton />
|
||||||
|
<AlertModeButton />
|
||||||
</Box>
|
</Box>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</Container>
|
</Container>
|
||||||
|
@@ -15,8 +15,8 @@ import Toolbar from "@mui/material/Toolbar";
|
|||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
import CloseIcon from "@mui/icons-material/Close";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import { timeColor } from "./timeColors";
|
import { alertModeVisibility, extractorsHaveExpired, timeColor } from "./timeColors";
|
||||||
import { ColorContext } from "@/app/context/Context";
|
import { ColorContext, SessionContext, } from "@/app/context/Context";
|
||||||
|
|
||||||
const StackItem = styled(Stack)(({ theme }) => ({
|
const StackItem = styled(Stack)(({ theme }) => ({
|
||||||
...theme.typography.body2,
|
...theme.typography.body2,
|
||||||
@@ -43,6 +43,8 @@ export const PlanetCard = ({
|
|||||||
planet: Planet;
|
planet: Planet;
|
||||||
character: AccessToken;
|
character: AccessToken;
|
||||||
}) => {
|
}) => {
|
||||||
|
const { alertMode } = useContext(SessionContext);
|
||||||
|
|
||||||
const [planetInfo, setPlanetInfo] = useState<PlanetInfo | undefined>(
|
const [planetInfo, setPlanetInfo] = useState<PlanetInfo | undefined>(
|
||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
@@ -63,7 +65,7 @@ export const PlanetCard = ({
|
|||||||
setPlanetRenderOpen(false);
|
setPlanetRenderOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const extractors =
|
const extractorsExpiryTime =
|
||||||
(planetInfo &&
|
(planetInfo &&
|
||||||
planetInfo.pins
|
planetInfo.pins
|
||||||
.filter((p) => EXTRACTOR_TYPE_IDS.some((e) => e === p.type_id))
|
.filter((p) => EXTRACTOR_TYPE_IDS.some((e) => e === p.type_id))
|
||||||
@@ -97,6 +99,7 @@ export const PlanetCard = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { colors } = useContext(ColorContext);
|
const { colors } = useContext(ColorContext);
|
||||||
|
const expired = extractorsHaveExpired(extractorsExpiryTime)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getPlanet(character, planet).then(setPlanetInfo);
|
getPlanet(character, planet).then(setPlanetInfo);
|
||||||
@@ -108,6 +111,7 @@ export const PlanetCard = ({
|
|||||||
height="100%"
|
height="100%"
|
||||||
position="relative"
|
position="relative"
|
||||||
minHeight={theme.custom.cardMinHeight}
|
minHeight={theme.custom.cardMinHeight}
|
||||||
|
visibility={alertModeVisibility(alertMode, expired)}
|
||||||
>
|
>
|
||||||
<Image
|
<Image
|
||||||
src={`/${planet.planet_type}.png`}
|
src={`/${planet.planet_type}.png`}
|
||||||
@@ -117,12 +121,7 @@ export const PlanetCard = ({
|
|||||||
style={{ borderRadius: 8, marginRight: 4 }}
|
style={{ borderRadius: 8, marginRight: 4 }}
|
||||||
onClick={handle3DrenderOpen}
|
onClick={handle3DrenderOpen}
|
||||||
/>
|
/>
|
||||||
{extractors.some((e) => {
|
{expired && (
|
||||||
if (!e) return true;
|
|
||||||
const dateExtractor = DateTime.fromISO(e);
|
|
||||||
const dateNow = DateTime.now();
|
|
||||||
return dateExtractor < dateNow;
|
|
||||||
}) && (
|
|
||||||
<Image
|
<Image
|
||||||
width={32}
|
width={32}
|
||||||
height={32}
|
height={32}
|
||||||
@@ -140,7 +139,7 @@ export const PlanetCard = ({
|
|||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{extractors.map((e, idx) => {
|
{extractorsExpiryTime.map((e, idx) => {
|
||||||
return (
|
return (
|
||||||
<Typography
|
<Typography
|
||||||
key={`${e}-${idx}-${character.character.characterId}`}
|
key={`${e}-${idx}-${character.character.characterId}`}
|
||||||
|
@@ -22,7 +22,7 @@ import Image from "next/image";
|
|||||||
import React, { forwardRef, useContext, useEffect, useState } from "react";
|
import React, { forwardRef, useContext, useEffect, useState } from "react";
|
||||||
import Countdown from "react-countdown";
|
import Countdown from "react-countdown";
|
||||||
import PinsCanvas3D from "./PinsCanvas3D";
|
import PinsCanvas3D from "./PinsCanvas3D";
|
||||||
import { timeColor } from "./timeColors";
|
import { timeColor, extractorsHaveExpired, alertModeVisibility } from "./timeColors";
|
||||||
|
|
||||||
const Transition = forwardRef(function Transition(
|
const Transition = forwardRef(function Transition(
|
||||||
props: TransitionProps & {
|
props: TransitionProps & {
|
||||||
@@ -52,7 +52,7 @@ export const PlanetTableRow = ({
|
|||||||
setPlanetRenderOpen(false);
|
setPlanetRenderOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const { piPrices } = useContext(SessionContext);
|
const { piPrices, alertMode } = useContext(SessionContext);
|
||||||
const [planetInfo, setPlanetInfo] = useState<PlanetInfo | undefined>(
|
const [planetInfo, setPlanetInfo] = useState<PlanetInfo | undefined>(
|
||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
@@ -174,9 +174,10 @@ export const PlanetTableRow = ({
|
|||||||
getPlanetUniverse(planet).then(setPlanetInfoUniverse);
|
getPlanetUniverse(planet).then(setPlanetInfoUniverse);
|
||||||
}, [planet, character]);
|
}, [planet, character]);
|
||||||
|
|
||||||
|
const expired = extractorsHaveExpired(extractors.map(e => e.expiry_time))
|
||||||
const { colors } = useContext(ColorContext);
|
const { colors } = useContext(ColorContext);
|
||||||
return (
|
return (
|
||||||
<TableRow sx={{ "&:last-child td, &:last-child th": { border: 0 } }}>
|
<TableRow style={{ visibility: alertModeVisibility(alertMode, expired) }} sx={{ "&:last-child td, &:last-child th": { border: 0 } }}>
|
||||||
<TableCell component="th" scope="row">
|
<TableCell component="th" scope="row">
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={`${
|
title={`${
|
||||||
|
@@ -19,3 +19,17 @@ export const timeColor = (
|
|||||||
if (dateExtractor.minus({ hours: 48 }) < dateNow) return colors.twoDaysColor;
|
if (dateExtractor.minus({ hours: 48 }) < dateNow) return colors.twoDaysColor;
|
||||||
return colors.defaultColor;
|
return colors.defaultColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const extractorsHaveExpired = (extractorsExpiryTime: (string | undefined)[]) =>
|
||||||
|
extractorsExpiryTime.some((e) => {
|
||||||
|
if (!e) return true;
|
||||||
|
const dateExtractor = DateTime.fromISO(e);
|
||||||
|
const dateNow = DateTime.now();
|
||||||
|
return dateExtractor < dateNow;
|
||||||
|
});
|
||||||
|
|
||||||
|
export const alertModeVisibility = (alertMode: boolean, expired: boolean) => {
|
||||||
|
if(alertMode && expired) return 'visible'
|
||||||
|
if(alertMode && !expired) return 'collapse'
|
||||||
|
return 'visible'
|
||||||
|
}
|
||||||
|
@@ -24,6 +24,8 @@ export const SessionContext = createContext<{
|
|||||||
toggleCompactMode: () => void;
|
toggleCompactMode: () => void;
|
||||||
planMode: boolean;
|
planMode: boolean;
|
||||||
togglePlanMode: () => void;
|
togglePlanMode: () => void;
|
||||||
|
alertMode: boolean;
|
||||||
|
toggleAlertMode: () => void;
|
||||||
piPrices: EvePraisalResult | undefined;
|
piPrices: EvePraisalResult | undefined;
|
||||||
}>({
|
}>({
|
||||||
sessionReady: false,
|
sessionReady: false,
|
||||||
@@ -35,6 +37,8 @@ export const SessionContext = createContext<{
|
|||||||
toggleCompactMode: () => {},
|
toggleCompactMode: () => {},
|
||||||
planMode: false,
|
planMode: false,
|
||||||
togglePlanMode: () => {},
|
togglePlanMode: () => {},
|
||||||
|
alertMode: false,
|
||||||
|
toggleAlertMode: () => {},
|
||||||
piPrices: undefined,
|
piPrices: undefined,
|
||||||
});
|
});
|
||||||
export type ColorSelectionType = {
|
export type ColorSelectionType = {
|
||||||
|
@@ -27,6 +27,7 @@ const Home = () => {
|
|||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
const [colors, setColors] = useState<ColorSelectionType>(defaultColors);
|
const [colors, setColors] = useState<ColorSelectionType>(defaultColors);
|
||||||
|
const [alertMode, setAlertMode] = useState(false);
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const code = searchParams && searchParams.get("code");
|
const code = searchParams && searchParams.get("code");
|
||||||
|
|
||||||
@@ -98,15 +99,26 @@ const Home = () => {
|
|||||||
setPlanMode(!planMode);
|
setPlanMode(!planMode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleAlertMode = () => {
|
||||||
|
setAlertMode(!alertMode);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const storedCompactMode = localStorage.getItem("compactMode");
|
const storedCompactMode = localStorage.getItem("compactMode");
|
||||||
if (!storedCompactMode) return;
|
if (!storedCompactMode) return;
|
||||||
storedCompactMode === "true" ? setCompactMode(true) : false;
|
storedCompactMode === "true" ? setCompactMode(true) : false;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const storedColors = localStorage.getItem("colors");
|
const storedColors = localStorage.getItem("colors");
|
||||||
if (!storedColors) return;
|
if (!storedColors) return;
|
||||||
setColors(JSON.parse(storedColors))
|
setColors(JSON.parse(storedColors));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const storedAlertMode = localStorage.getItem("alertMode");
|
||||||
|
if (!storedAlertMode) return;
|
||||||
|
setAlertMode(JSON.parse(storedAlertMode));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -114,7 +126,11 @@ const Home = () => {
|
|||||||
}, [compactMode]);
|
}, [compactMode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
localStorage.setItem("colors", JSON.stringify(colors))
|
localStorage.setItem("alertMode", alertMode ? "true" : "false");
|
||||||
|
}, [alertMode]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem("colors", JSON.stringify(colors));
|
||||||
}, [colors]);
|
}, [colors]);
|
||||||
|
|
||||||
// Initialize EVE PI
|
// Initialize EVE PI
|
||||||
@@ -162,6 +178,8 @@ const Home = () => {
|
|||||||
planMode,
|
planMode,
|
||||||
togglePlanMode,
|
togglePlanMode,
|
||||||
piPrices,
|
piPrices,
|
||||||
|
alertMode,
|
||||||
|
toggleAlertMode,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CharacterContext.Provider
|
<CharacterContext.Provider
|
||||||
|
Reference in New Issue
Block a user