refactor: reached same app state using vite

This commit is contained in:
Pihkaal
2024-01-28 15:56:19 +01:00
parent 8446ee6c65
commit 5542dce881
27 changed files with 805 additions and 207 deletions

View File

@@ -0,0 +1,42 @@
/* eslint-disable react-refresh/only-export-components */
import {
createContext,
useEffect,
useContext,
useState,
type ReactNode,
} from "react";
import axios from "axios";
import { type Manifest } from "~/utils/types";
const AppContext = createContext<Manifest | null>(null);
export const AppContextProvider = (props: {
children: Array<ReactNode> | ReactNode;
}) => {
const [manifest, setManifest] = useState<Manifest | null>(null);
useEffect(() => {
void 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}>
{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;
};

View File

@@ -0,0 +1,16 @@
/* eslint-disable react-refresh/only-export-components */
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;
};