import { useEffect, useState } from "react"; import { About } from "./About"; import { CatalogUpdate } from "./CatalogStatus"; import { Collection } from "./collection/Collection"; import { useCollection } from "./collection/cards"; import { useContainers } from "./collection/containers"; import { Owning } from "./collection/context"; import { Destination } from "./collection/Destination"; import { CATALOG } from "./config"; import { EXPORT, Export } from "./export/Export"; import { IMPORT, Import, ImportStatus } from "./import/Import"; import { attach, useWaiting } from "./import/runner"; import { Menu } from "./Menu"; import { Nav } from "./Nav"; import { useSession } from "./oauth/useSession"; import { HOME, known, Link, replace, tab, usePath } from "./router"; import { Search } from "./Search"; import { SETS, SetView } from "./Sets"; import { Soon } from "./Soon"; import { Review } from "./scan/Review"; import { REVIEW, SCAN, Scan } from "./scan/Scan"; import { useScratch } from "./scan/store"; import { useCatalog } from "./useCatalog"; export function App() { const status = useCatalog(); const { load } = status; const account = useSession(); const signedIn = account.state.status === "in" ? account.state.session : null; const containers = useContainers(signedIn); const [chosen, choose] = useState(null); const waiting = useWaiting(); const scratch = useScratch(); const collection = useCollection(signedIn, chosen, waiting); const path = usePath(); const here = tab(path); // An import outlives the page that started it, so what picks it back up is // the app opening rather than that page being visited. useEffect(() => { void attach(signedIn, collection.snapshot, collection.landed); }, [signedIn, collection.snapshot, collection.landed]); // A bare `/` and the OAuth callback both land somewhere the bar can't mark, // and the callback has to be read out of the address before it is rewritten. useEffect(() => { if (account.state.status !== "restoring" && !known(path)) replace(HOME); }, [account.state.status, path]); const destination = signedIn && ( <> {collection.error && {collection.error}} ); return (

Manaweb

{/* todo(settings): profile, settings, about and sign out as one menu off the picture; sign in stays a button, there being none. */}
{/* Signed out leaves this null, which is what hides every add button. */}
{here === "/cards" && (load.status === "ready" ? ( path === SETS ? ( ) : ( ) ) : load.status === "loading" ? (

{load.step}…

) : (

No catalog at {CATALOG}: {load.error}

))} {here === SCAN && (path === REVIEW ? ( load.status === "ready" ? ( ) : (

The catalog is still loading.

) ) : ( ))} {here === "/collection" && (path === IMPORT ? ( ) : path === EXPORT ? ( ) : signedIn ? ( ) : (

Sign in to see what you own.

))} {here === "/decks" && } {here === "/lists" && }
); }