refactor: moving from nextjs to vite+react
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
import {
|
||||
createContext,
|
||||
useEffect,
|
||||
useContext,
|
||||
useState,
|
||||
ReactNode,
|
||||
} from "react";
|
||||
import axios from "axios";
|
||||
import { Manifest } from "~/utils/types";
|
||||
|
||||
const AppContext = createContext<Manifest | undefined>(undefined);
|
||||
|
||||
export const AppContextProvider = (props: {
|
||||
children: Array<ReactNode> | ReactNode;
|
||||
}) => {
|
||||
const [manifest, setManifest] = useState<Manifest>();
|
||||
|
||||
useEffect(() => {
|
||||
axios
|
||||
.get<Manifest>(
|
||||
"https://raw.githubusercontent.com/pihkaal/pihkaal/main/manifest.json",
|
||||
)
|
||||
.then(x => {
|
||||
setManifest(x.data);
|
||||
console.log(x.data);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AppContext.Provider value={manifest}>{props.children}</AppContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useApp = () => {
|
||||
const context = useContext(AppContext);
|
||||
if (!context) throw new Error("useApp must be used inside the app lol");
|
||||
|
||||
return context;
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
import { createContext, useContext } from "react";
|
||||
import { type TerminalRenderer } from "~/utils/terminal/renderer";
|
||||
|
||||
const TerminalCanvasContext = createContext<TerminalRenderer | undefined>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
export const TerminalCanvasContextProvider = TerminalCanvasContext.Provider;
|
||||
|
||||
export const useTerminalCanvas = () => {
|
||||
const context = useContext(TerminalCanvasContext);
|
||||
if (!context)
|
||||
throw new Error(
|
||||
"useTerminalCanvas must be used inside a Terminal component",
|
||||
);
|
||||
|
||||
return context;
|
||||
};
|
||||
@@ -1,15 +0,0 @@
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
const TerminalContext = createContext<
|
||||
{ cols: number; rows: number } | undefined
|
||||
>(undefined);
|
||||
|
||||
export const TerminalContextProvider = TerminalContext.Provider;
|
||||
|
||||
export const useTerminal = () => {
|
||||
const context = useContext(TerminalContext);
|
||||
if (!context)
|
||||
throw new Error("useTerminal must be used inside a Terminal component");
|
||||
|
||||
return context;
|
||||
};
|
||||
Reference in New Issue
Block a user