refactor: rework assets fetching

This commit is contained in:
Pihkaal
2024-07-25 10:02:15 +02:00
parent a0be097c34
commit f8e3e20d9d
15 changed files with 239 additions and 281 deletions

View File

@@ -1,50 +1,11 @@
import axios from "axios";
import { type ReactNode, useState, useEffect } from "react";
import { type ReactNode, useState } 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: [
{
name: "me",
icon: "ts",
},
{
name: "tlock",
icon: "rs",
},
],
links: [
{
name: "github",
url: "https://github.com/pihkaal",
icon: "github",
},
{
name: "instagram",
url: "https://instagram.com/pihkaal",
icon: "instagram",
},
],
});
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={{ rootManifest, activeKitty, setActiveKitty }}>
{rootManifest && props.children}
<AppContext.Provider value={{ activeKitty, setActiveKitty }}>
{props.children}
</AppContext.Provider>
);
};