From 69091f6ea440154d8faef26ec24f1ca35f2bd18e Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Thu, 30 May 2024 23:55:08 +0200 Subject: [PATCH] feat(app): fetch root manifest --- src/App.tsx | 41 +++++++++++++++++++---------------- src/context/AppContext.tsx | 8 ++++++- src/providers/AppProvider.tsx | 23 +++++++++++++++++--- src/utils/types.ts | 10 ++++----- 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8282ba2..04d1714 100644 --- a/src/App.tsx +++ b/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 ( -
- {loggedIn ? ( -
- - - + +
+ {loggedIn ? ( +
+ + + - -
- ) : ( -
- -
- )} -
+ +
+ ) : ( +
+ +
+ )} +
+
); } diff --git a/src/context/AppContext.tsx b/src/context/AppContext.tsx index b46f45e..8b08632 100644 --- a/src/context/AppContext.tsx +++ b/src/context/AppContext.tsx @@ -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); diff --git a/src/providers/AppProvider.tsx b/src/providers/AppProvider.tsx index 796624e..c86c98e 100644 --- a/src/providers/AppProvider.tsx +++ b/src/providers/AppProvider.tsx @@ -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({ + files: ["README.md", "pubkey.asc"], + projects: ["me", "tlock"], + }); + + useEffect(() => { + return; + void axios + .get( + "https://raw.githubusercontent.com/pihkaal/pihkaal/main/manifest.json", + ) + .then((x) => setRootManifest(x.data)); + }, []); + + if (!rootManifest) return null; return ( - - {props.children} + + {rootManifest && props.children} ); }; diff --git a/src/utils/types.ts b/src/utils/types.ts index 86dbfeb..494de6a 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -1,4 +1,4 @@ -import { KittyContextProps } from "~/context/KittyContext"; +import { type KittyContextProps } from "~/context/KittyContext"; export type Prettify = NonNullable<{ [K in keyof T]: T[K] }>; @@ -7,9 +7,7 @@ export type InnerKittyProps any> = Prettify< Parameters[0] & KittyContextProps >; -export type Manifest = { - projects: Array<{ - name: string; - files: Array; - }>; +export type RootManifest = { + files: Array; + projects: Array; };