Download code/web/src/App.tsx from MiniMaxAI/oss-ecosystem-data: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/main/code/web/src/App.tsx
- Command line
-
hf download hf://datasets/MiniMaxAI/oss-ecosystem-data/code/web/src/App.tsx
-
curl -L -o App.tsx https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/main/code/web/src/App.tsx
1.16 kB
| import { Fragment, useEffect, useState } from "react" | |
| import type { Site } from "@/lib/types" | |
| import { useRoute } from "@/lib/route" | |
| import { T, useLang } from "@/lib/i18n" | |
| import { Home } from "@/pages/home" | |
| import { CategoryPage } from "@/pages/category" | |
| export default function App() { | |
| const [site, setSite] = useState<Site | null>(null) | |
| const [failed, setFailed] = useState(false) | |
| const route = useRoute() | |
| const lang = useLang() | |
| useEffect(() => { | |
| fetch("data/site.json") | |
| .then((r) => (r.ok ? r.json() : Promise.reject(r.status))) | |
| .then(setSite) | |
| .catch(() => setFailed(true)) | |
| }, []) | |
| useEffect(() => { | |
| if (!route.cat) document.title = T.site | |
| }, [route.cat, lang]) | |
| if (failed) return <p className="p-10 text-lg">{T.noData}</p> | |
| if (!site) return <div className="brand-backdrop startup-screen" aria-busy="true" aria-label={T.site} /> | |
| // A new language draws the page afresh, so nothing keeps copy from the old one. | |
| return ( | |
| <Fragment key={lang}> | |
| {route.cat | |
| ? <CategoryPage key={route.cat} site={site} cat={route.cat} rel={route.rel} /> | |
| : <Home site={site} />} | |
| </Fragment> | |
| ) | |
| } | |