Add color selection and save it to localStorage

This commit is contained in:
Calli
2023-10-06 19:40:54 +03:00
parent 5a34784c9c
commit e69e65059e
9 changed files with 236 additions and 94 deletions

View File

@@ -31,7 +31,7 @@ const Transition = forwardRef(function Transition(
props: TransitionProps & {
children: React.ReactElement;
},
ref: React.Ref<unknown>
ref: React.Ref<unknown>,
) {
return <Slide direction="up" ref={ref} {...props} />;
});
@@ -44,7 +44,7 @@ export const PlanetCard = ({
character: AccessToken;
}) => {
const [planetInfo, setPlanetInfo] = useState<PlanetInfo | undefined>(
undefined
undefined,
);
const [planetInfoUniverse, setPlanetInfoUniverse] = useState<
@@ -71,7 +71,7 @@ export const PlanetCard = ({
[];
const getPlanet = async (
character: AccessToken,
planet: Planet
planet: Planet,
): Promise<PlanetInfo> => {
const api = new Api();
const planetInfo = (
@@ -80,14 +80,14 @@ export const PlanetCard = ({
planet.planet_id,
{
token: character.access_token,
}
},
)
).data;
return planetInfo;
};
const getPlanetUniverse = async (
planet: Planet
planet: Planet,
): Promise<PlanetInfoUniverse> => {
const api = new Api();
const planetInfo = (
@@ -96,7 +96,7 @@ export const PlanetCard = ({
return planetInfo;
};
const colorContext = useContext(ColorContext)
const { colors } = useContext(ColorContext);
useEffect(() => {
getPlanet(character, planet).then(setPlanetInfo);
@@ -144,7 +144,7 @@ export const PlanetCard = ({
return (
<Typography
key={`${e}-${idx}-${character.character.characterId}`}
color={timeColor(e, colorContext)}
color={timeColor(e, colors)}
fontSize={theme.custom.smallText}
>
{e ? (

View File

@@ -1,8 +1,4 @@
import {
SessionContext,
ColorContext,
ColorContextType,
} from "@/app/context/Context";
import { SessionContext, ColorContext } from "@/app/context/Context";
import {
EXTRACTOR_TYPE_IDS,
FACTORY_IDS,
@@ -178,7 +174,7 @@ export const PlanetTableRow = ({
getPlanetUniverse(planet).then(setPlanetInfoUniverse);
}, [planet, character]);
const colorContext = useContext(ColorContext);
const { colors } = useContext(ColorContext);
return (
<TableRow sx={{ "&:last-child td, &:last-child th": { border: 0 } }}>
<TableCell component="th" scope="row">
@@ -210,7 +206,7 @@ export const PlanetTableRow = ({
style={{ display: "flex" }}
>
<Typography
color={timeColor(e.expiry_time, colorContext)}
color={timeColor(e.expiry_time, colors)}
fontSize={theme.custom.smallText}
paddingRight={1}
>

View File

@@ -1,9 +1,9 @@
import { ColorContextType } from "@/app/context/Context";
import { ColorSelectionType } from "@/app/context/Context";
import { DateTime } from "luxon";
export const timeColor = (
extractorDate: string | undefined,
colors: ColorContextType,
colors: ColorSelectionType,
): string => {
if (!extractorDate) return colors.expiredColor;
const dateExtractor = DateTime.fromISO(extractorDate);