feat(app): fetch root manifest
This commit is contained in:
41
src/App.tsx
41
src/App.tsx
@@ -3,32 +3,35 @@ 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>
|
||||
<main className="h-screen w-screen overflow-hidden bg-[url(/wallpaper.jpg)] bg-cover">
|
||||
{loggedIn ? (
|
||||
<div className="flex h-full w-full flex-col">
|
||||
<Kitty className="w-full flex-1 pb-1 pl-2 pr-2 pt-2">
|
||||
<Nvim />
|
||||
</Kitty>
|
||||
<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">
|
||||
<Kitty className="w-full flex-1 pb-1 pl-2 pr-2 pt-2">
|
||||
<Nvim />
|
||||
</Kitty>
|
||||
|
||||
<Music />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex h-full items-center justify-center">
|
||||
<button
|
||||
className="rounded-md border border-black px-2 py-1 hover:border-2 hover:font-bold"
|
||||
onClick={() => setLoggedIn(true)}
|
||||
>
|
||||
Log in
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
<Music />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex h-full items-center justify-center">
|
||||
<button
|
||||
className="rounded-md border border-black px-2 py-1 hover:border-2 hover:font-bold"
|
||||
onClick={() => setLoggedIn(true)}
|
||||
>
|
||||
Log in
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
</BrowserRouter>
|
||||
</AppProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
files: Array<string>;
|
||||
}>;
|
||||
export type RootManifest = {
|
||||
files: Array<string>;
|
||||
projects: Array<string>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user