feat(app): fetch root manifest

This commit is contained in:
Pihkaal
2024-05-30 23:55:08 +02:00
parent 186580cccb
commit 69091f6ea4
4 changed files with 53 additions and 29 deletions

View File

@@ -3,32 +3,35 @@ import { Kitty } from "./components/Kitty";
import { AppProvider } from "./providers/AppProvider"; import { AppProvider } from "./providers/AppProvider";
import { Music } from "./components/Music"; import { Music } from "./components/Music";
import { Nvim } from "./components/Nvim"; import { Nvim } from "./components/Nvim";
import { BrowserRouter } from "react-router-dom";
export default function App() { export default function App() {
const [loggedIn, setLoggedIn] = useState(false); const [loggedIn, setLoggedIn] = useState(false);
return ( return (
<AppProvider> <AppProvider>
<main className="h-screen w-screen overflow-hidden bg-[url(/wallpaper.jpg)] bg-cover"> <BrowserRouter>
{loggedIn ? ( <main className="h-screen w-screen overflow-hidden bg-[url(/wallpaper.jpg)] bg-cover">
<div className="flex h-full w-full flex-col"> {loggedIn ? (
<Kitty className="w-full flex-1 pb-1 pl-2 pr-2 pt-2"> <div className="flex h-full w-full flex-col">
<Nvim /> <Kitty className="w-full flex-1 pb-1 pl-2 pr-2 pt-2">
</Kitty> <Nvim />
</Kitty>
<Music /> <Music />
</div> </div>
) : ( ) : (
<div className="flex h-full items-center justify-center"> <div className="flex h-full items-center justify-center">
<button <button
className="rounded-md border border-black px-2 py-1 hover:border-2 hover:font-bold" className="rounded-md border border-black px-2 py-1 hover:border-2 hover:font-bold"
onClick={() => setLoggedIn(true)} onClick={() => setLoggedIn(true)}
> >
Log in Log in
</button> </button>
</div> </div>
)} )}
</main> </main>
</BrowserRouter>
</AppProvider> </AppProvider>
); );
} }

View File

@@ -1,5 +1,11 @@
import { createContext } from "react"; import { createContext } from "react";
import { type RootManifest } from "~/utils/types";
export const AppContext = createContext< export const AppContext = createContext<
{ activeKitty: string; setActiveKitty: (value: string) => void } | undefined | {
rootManifest: RootManifest;
activeKitty: string;
setActiveKitty: (value: string) => void;
}
| undefined
>(undefined); >(undefined);

View File

@@ -1,12 +1,29 @@
import { type ReactNode, useState } from "react"; import axios from "axios";
import { type ReactNode, useState, useEffect } from "react";
import { AppContext } from "~/context/AppContext"; import { AppContext } from "~/context/AppContext";
import { type RootManifest } from "~/utils/types";
export const AppProvider = (props: { children?: ReactNode }) => { export const AppProvider = (props: { children?: ReactNode }) => {
const [activeKitty, setActiveKitty] = useState(":r0:"); const [activeKitty, setActiveKitty] = useState(":r0:");
const [rootManifest, setRootManifest] = useState<RootManifest>({
files: ["README.md", "pubkey.asc"],
projects: ["me", "tlock"],
});
useEffect(() => {
return;
void axios
.get<RootManifest>(
"https://raw.githubusercontent.com/pihkaal/pihkaal/main/manifest.json",
)
.then((x) => setRootManifest(x.data));
}, []);
if (!rootManifest) return null;
return ( return (
<AppContext.Provider value={{ activeKitty, setActiveKitty }}> <AppContext.Provider value={{ rootManifest, activeKitty, setActiveKitty }}>
{props.children} {rootManifest && props.children}
</AppContext.Provider> </AppContext.Provider>
); );
}; };

View File

@@ -1,4 +1,4 @@
import { KittyContextProps } from "~/context/KittyContext"; import { type KittyContextProps } from "~/context/KittyContext";
export type Prettify<T> = NonNullable<{ [K in keyof T]: T[K] }>; export type Prettify<T> = NonNullable<{ [K in keyof T]: T[K] }>;
@@ -7,9 +7,7 @@ export type InnerKittyProps<T extends (...args: any[]) => any> = Prettify<
Parameters<T>[0] & KittyContextProps Parameters<T>[0] & KittyContextProps
>; >;
export type Manifest = { export type RootManifest = {
projects: Array<{ files: Array<string>;
name: string; projects: Array<string>;
files: Array<string>;
}>;
}; };