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

@@ -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>
);
};