Loading packages/client/src/components/Toolbar/CanvasMeta.tsx +3 −2 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ const getTimeLeft = (pixels: { available: number }, config: ClientConfig) => { }; const PlaceCountdown = () => { const { pixels, config } = useAppContext(); const { pixels, config } = useAppContext<true>(); const [timeLeft, setTimeLeft] = useState(getTimeLeft(pixels, config)); useEffect(() => { Loading Loading @@ -69,7 +69,8 @@ const OnlineCount = () => { }; export const CanvasMeta = () => { const { canvasPosition, cursorPosition, pixels, config } = useAppContext(); const { canvasPosition, cursorPosition, pixels, config } = useAppContext<true>(); const { isOpen, onOpen, onOpenChange } = useDisclosure(); return ( Loading packages/client/src/components/Toolbar/Palette.tsx +1 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ import { faXmark } from "@fortawesome/free-solid-svg-icons"; import { IPaletteContext } from "@sc07-canvas/lib/src/net"; export const Palette = () => { const { config, user } = useAppContext(); const { config, user } = useAppContext<true>(); const [pallete, setPallete] = useState<IPaletteContext>({}); useEffect(() => { Loading packages/client/src/components/Toolbar/UndoButton.tsx +1 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ import network from "../../lib/network"; import { useEffect, useState } from "react"; export const UndoButton = () => { const { undo, config } = useAppContext(); const { undo, config } = useAppContext<true>(); /** * percentage of time left (0 <= x <= 1) */ Loading packages/client/src/contexts/AppContext.tsx +16 −1 Original line number Diff line number Diff line Loading @@ -65,7 +65,22 @@ interface IMapOverlay { 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) => { const [config, setConfig] = useState<ClientConfig>(undefined as any); Loading Loading
packages/client/src/components/Toolbar/CanvasMeta.tsx +3 −2 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ const getTimeLeft = (pixels: { available: number }, config: ClientConfig) => { }; const PlaceCountdown = () => { const { pixels, config } = useAppContext(); const { pixels, config } = useAppContext<true>(); const [timeLeft, setTimeLeft] = useState(getTimeLeft(pixels, config)); useEffect(() => { Loading Loading @@ -69,7 +69,8 @@ const OnlineCount = () => { }; export const CanvasMeta = () => { const { canvasPosition, cursorPosition, pixels, config } = useAppContext(); const { canvasPosition, cursorPosition, pixels, config } = useAppContext<true>(); const { isOpen, onOpen, onOpenChange } = useDisclosure(); return ( Loading
packages/client/src/components/Toolbar/Palette.tsx +1 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ import { faXmark } from "@fortawesome/free-solid-svg-icons"; import { IPaletteContext } from "@sc07-canvas/lib/src/net"; export const Palette = () => { const { config, user } = useAppContext(); const { config, user } = useAppContext<true>(); const [pallete, setPallete] = useState<IPaletteContext>({}); useEffect(() => { Loading
packages/client/src/components/Toolbar/UndoButton.tsx +1 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ import network from "../../lib/network"; import { useEffect, useState } from "react"; export const UndoButton = () => { const { undo, config } = useAppContext(); const { undo, config } = useAppContext<true>(); /** * percentage of time left (0 <= x <= 1) */ Loading
packages/client/src/contexts/AppContext.tsx +16 −1 Original line number Diff line number Diff line Loading @@ -65,7 +65,22 @@ interface IMapOverlay { 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) => { const [config, setConfig] = useState<ClientConfig>(undefined as any); Loading