feat(app): use components from nextjs branch

This commit is contained in:
Pihkaal
2024-05-30 15:16:52 +02:00
parent 4d1c3d958b
commit e21d337d53
24 changed files with 3078 additions and 2810 deletions

View File

@@ -1,54 +1,22 @@
/* 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";
import { type ReactNode, createContext, useContext, useState } from "react";
const AppContext = createContext<Manifest | null>(null);
export const AppContext = createContext<
{ activeKitty: string; setActiveKitty: (value: string) => void } | undefined
>(undefined);
export const AppContextProvider = (props: {
children: Array<ReactNode> | ReactNode;
}) => {
const [manifest, setManifest] = useState<Manifest | null>({
projects: [
{
name: "tlock",
files: ["README.md"],
},
{
name: "pihkaal",
files: ["README.md", "pubkey.asc"],
},
],
});
export const useApp = () => {
const app = useContext(AppContext);
if (!app) throw new Error("`useApp` used outside AppContext");
useEffect(() => {
return;
void axios
.get<Manifest>(
"https://raw.githubusercontent.com/pihkaal/pihkaal/main/manifest.json",
)
.then(x => {
setManifest(x.data);
console.log(x.data);
});
}, []);
return app;
};
export const AppProvider = (props: { children?: ReactNode }) => {
const [activeKitty, setActiveKitty] = useState(":r0:");
return (
<AppContext.Provider value={manifest}>
{manifest && props.children}
<AppContext.Provider value={{ activeKitty, setActiveKitty }}>
{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,20 @@
import { createContext, useContext } from "react";
export const KittyContext = createContext<KittyContextProps | undefined>(
undefined,
);
export const useKitty = () => useContext(KittyContext);
export type KittyContextProps = {
rows: number;
cols: number;
active: boolean;
};
type Prettify<T> = NonNullable<{ [K in keyof T]: T[K] }>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type InnerKittyProps<T extends (...args: any[]) => any> = Prettify<
Parameters<T>[0] & KittyContextProps
>;