Separated display and room characteristics: updated context, created default value

This commit is contained in:
Dmitriy Shishkov 2021-09-04 03:49:49 +03:00
parent 8560d3c0ce
commit 8b7f83a14a
No known key found for this signature in database
GPG Key ID: 14358F96FCDD8060
4 changed files with 29 additions and 9 deletions

View File

@ -1,3 +1,4 @@
import { ContextData } from "./types/context";
import { PeriodFormat } from "./types/time";
export const lessonPeriods: readonly PeriodFormat[] = [
@ -18,3 +19,18 @@ export const WeekDays = [
"Saturday",
"Sunday",
] as const;
// It will look like Windows 11 logo, lol
export const defaultState: ContextData = {
map: [
{ x: 5, y: 5 },
{ x: 110, y: 5 },
{ x: 5, y: 110 },
{ x: 110, y: 110 },
].map((coordinates) => ({ coordinates, size: { w: 100, h: 100 } })),
char: Array(4)
.fill(0)
.map(() => ({
free: true,
})),
};

View File

@ -1,12 +1,11 @@
import { createContext, FC, useContext, useState } from "react";
import { ContextData, ContextValue } from "./types";
const defaultState: ContextData = { x: 0 };
import { defaultState } from "./constants";
import { ContextData, ContextValue } from "./types/context";
const Context = createContext<ContextValue | undefined>(undefined);
export const RoomContextProvider: FC = ({ children }) => {
const [state, setState] = useState(defaultState);
const [state, setState] = useState<ContextData>(defaultState);
return (
<Context.Provider value={{ state, setState }}>{children}</Context.Provider>

View File

@ -1,10 +1,12 @@
import { Dispatch, SetStateAction } from "react";
import { RoomDisplay, RoomState } from "./room";
export interface ContextData {
// TODO: describe state
map: RoomDisplay[];
char: RoomState[];
}
export interface ContextValue {
export type ContextValue = {
state: ContextData;
setState: Dispatch<SetStateAction<ContextData>>;
}
};

View File

@ -1,5 +1,8 @@
export type RoomT = {
export interface RoomDisplay {
coordinates: { x: number; y: number };
size: { w: number; h: number };
}
export interface RoomState {
free: boolean;
};
}