import "./index.css"; import "@szhsin/react-menu/dist/index.css"; import "@/assets/fonts/inter.css"; import { SnortContext } from "@snort/system-react"; import { StrictMode } from "react"; import * as ReactDOM from "react-dom/client"; import { createBrowserRouter, RouteObject, RouterProvider } from "react-router-dom"; import { initRelayWorker, preload, UserCache } from "@/Cache"; import { ThreadRoute } from "@/Components/Event/Thread/ThreadRoute"; import { IntlProvider } from "@/Components/IntlProvider/IntlProvider"; import { db } from "@/Db"; import { addCachedMetadataToFuzzySearch } from "@/Db/FuzzySearch"; import { AboutPage } from "@/Pages/About"; import { SnortDeckLayout } from "@/Pages/Deck/DeckLayout"; import DonatePage from "@/Pages/Donate/DonatePage"; import ErrorPage from "@/Pages/ErrorPage"; import FreeNostrAddressPage from "@/Pages/FreeNostrAddressPage"; import HelpPage from "@/Pages/HelpPage"; import Layout from "@/Pages/Layout"; import { ListFeedPage } from "@/Pages/ListFeedPage"; import MessagesPage from "@/Pages/Messages/MessagesPage"; import NetworkGraph from "@/Pages/NetworkGraph/NetworkGraph"; import NostrAddressPage from "@/Pages/NostrAddressPage"; import NostrLinkHandler from "@/Pages/NostrLinkHandler"; import NotificationsPage from "@/Pages/Notifications/Notifications"; import { OnboardingRoutes } from "@/Pages/onboarding"; import ProfilePage from "@/Pages/Profile/ProfilePage"; import { RootRoutes } from "@/Pages/Root/RootRoutes"; import { RootTabRoutes } from "@/Pages/Root/RootTabRoutes"; import SearchPage from "@/Pages/SearchPage"; import SettingsRoutes from "@/Pages/settings/Routes"; import { SubscribeRoutes } from "@/Pages/subscribe"; import WalletPage from "@/Pages/wallet"; import { WalletReceivePage } from "@/Pages/wallet/receive"; import { WalletSendPage } from "@/Pages/wallet/send"; import ZapPoolPage from "@/Pages/ZapPool/ZapPool"; import { System } from "@/system"; import { storeRefCode, unwrap } from "@/Utils"; import { hasWasm, wasmInit, WasmPath } from "@/Utils/wasm"; import { Wallets } from "@/Wallet"; import { setupWebLNWalletConfig } from "@/Wallet"; import { LoginStore } from "./Utils/Login"; async function initSite() { storeRefCode(); if (hasWasm) { await wasmInit(WasmPath); await initRelayWorker(); } setupWebLNWalletConfig(Wallets); db.ready = await db.isAvailable(); if (db.ready) { const login = LoginStore.snapshot(); preload(login.state.follows); // dont await this System.PreloadSocialGraph(); // dont await this } queueMicrotask(() => { for (const ev of UserCache.snapshot()) { try { addCachedMetadataToFuzzySearch(ev); } catch (e) { console.error("Failed to handle metadata event from sql db", e); } } }); return null; } let didInit = false; const mainRoutes = [ ...RootRoutes, { path: "/help", element: , }, { path: "/e/:id", element: , }, { path: "/p/:id", element: , }, { path: "/notifications", element: , }, { path: "/free-nostr-address", element: , }, { path: "/nostr-address", element: , }, { path: "/messages/:id?", element: , }, { path: "/donate", element: , }, { path: "/search/:keyword?", element: , }, { path: "/list-feed/:id", element: , }, { path: "/about", element: , }, { path: "/graph", element: , }, { path: "/wallet", element: (
), }, { path: "/wallet/send", element: , }, { path: "/wallet/receive", element: , }, ...OnboardingRoutes, ...SettingsRoutes, ] as Array; if (CONFIG.features.zapPool) { mainRoutes.push({ path: "/zap-pool", element: , }); } if (CONFIG.features.subscriptions) { mainRoutes.push(...SubscribeRoutes); } // add catch all route mainRoutes.push({ path: "/:link", element: , }); const routes = [ { element: , errorElement: , loader: async () => { if (!didInit) { didInit = true; return await initSite(); } return null; }, children: mainRoutes, }, ] as Array; if (CONFIG.features.deck) { routes.push({ path: "/deck", element: , loader: async () => { if (!didInit) { didInit = true; return await initSite(); } return null; }, children: RootTabRoutes, } as RouteObject); } const router = createBrowserRouter(routes); const root = ReactDOM.createRoot(unwrap(document.getElementById("root"))); root.render( , ); // Use react-helmet instead? document.title = CONFIG.appTitle;