fix some types being incorrect
This commit is contained in:
parent
4ef7eaf33f
commit
602767889b
|
@ -27,7 +27,7 @@ const getTimeLeft = (pixels: { available: number }, config: ClientConfig) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const PlaceCountdown = () => {
|
const PlaceCountdown = () => {
|
||||||
const { pixels, config } = useAppContext();
|
const { pixels, config } = useAppContext<true>();
|
||||||
const [timeLeft, setTimeLeft] = useState(getTimeLeft(pixels, config));
|
const [timeLeft, setTimeLeft] = useState(getTimeLeft(pixels, config));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -69,7 +69,8 @@ const OnlineCount = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CanvasMeta = () => {
|
export const CanvasMeta = () => {
|
||||||
const { canvasPosition, cursorPosition, pixels, config } = useAppContext();
|
const { canvasPosition, cursorPosition, pixels, config } =
|
||||||
|
useAppContext<true>();
|
||||||
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { IPaletteContext } from "@sc07-canvas/lib/src/net";
|
import { IPaletteContext } from "@sc07-canvas/lib/src/net";
|
||||||
|
|
||||||
export const Palette = () => {
|
export const Palette = () => {
|
||||||
const { config, user } = useAppContext();
|
const { config, user } = useAppContext<true>();
|
||||||
const [pallete, setPallete] = useState<IPaletteContext>({});
|
const [pallete, setPallete] = useState<IPaletteContext>({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import network from "../../lib/network";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export const UndoButton = () => {
|
export const UndoButton = () => {
|
||||||
const { undo, config } = useAppContext();
|
const { undo, config } = useAppContext<true>();
|
||||||
/**
|
/**
|
||||||
* percentage of time left (0 <= x <= 1)
|
* percentage of time left (0 <= x <= 1)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -65,7 +65,22 @@ interface IMapOverlay {
|
||||||
|
|
||||||
const appContext = createContext<IAppContext>({} as any);
|
const appContext = createContext<IAppContext>({} as any);
|
||||||
|
|
||||||
export const useAppContext = () => useContext(appContext);
|
type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
|
||||||
|
[Property in Key]-?: Type[Property];
|
||||||
|
};
|
||||||
|
|
||||||
|
type AppContext<ConfigExists extends boolean> = ConfigExists extends true
|
||||||
|
? WithRequiredProperty<IAppContext, "config">
|
||||||
|
: IAppContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get app context
|
||||||
|
*
|
||||||
|
* @template ConfigExists If the config is already known to be available in this context
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const useAppContext = <ConfigExists extends boolean = false>() =>
|
||||||
|
useContext<AppContext<ConfigExists>>(appContext as any);
|
||||||
|
|
||||||
export const AppContext = ({ children }: PropsWithChildren) => {
|
export const AppContext = ({ children }: PropsWithChildren) => {
|
||||||
const [config, setConfig] = useState<ClientConfig>(undefined as any);
|
const [config, setConfig] = useState<ClientConfig>(undefined as any);
|
||||||
|
|
Loading…
Reference in New Issue