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,12 +3,14 @@ import { Kitty } from "./components/Kitty";
import { AppProvider } from "./providers/AppProvider";
import { Music } from "./components/Music";
import { Nvim } from "./components/Nvim";
import { BrowserRouter } from "react-router-dom";
export default function App() {
const [loggedIn, setLoggedIn] = useState(false);
return (
<AppProvider>
<BrowserRouter>
<main className="h-screen w-screen overflow-hidden bg-[url(/wallpaper.jpg)] bg-cover">
{loggedIn ? (
<div className="flex h-full w-full flex-col">
@@ -29,6 +31,7 @@ export default function App() {
</div>
)}
</main>
</BrowserRouter>
</AppProvider>
);
}

View File

@@ -1,5 +1,11 @@
import { createContext } from "react";
import { type RootManifest } from "~/utils/types";
export const AppContext = createContext<
{ activeKitty: string; setActiveKitty: (value: string) => void } | undefined
| {
rootManifest: RootManifest;
activeKitty: string;
setActiveKitty: (value: string) => void;
}
| 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 { type RootManifest } from "~/utils/types";
export const AppProvider = (props: { children?: ReactNode }) => {
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 (
<AppContext.Provider value={{ activeKitty, setActiveKitty }}>
{props.children}
<AppContext.Provider value={{ rootManifest, activeKitty, setActiveKitty }}>
{rootManifest && props.children}
</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] }>;
@@ -7,9 +7,7 @@ export type InnerKittyProps<T extends (...args: any[]) => any> = Prettify<
Parameters<T>[0] & KittyContextProps
>;
export type Manifest = {
projects: Array<{
name: string;
export type RootManifest = {
files: Array<string>;
}>;
projects: Array<string>;
};