2023-02-07 20:04:50 +00:00
|
|
|
import "./index.css";
|
|
|
|
import "@szhsin/react-menu/dist/index.css";
|
2024-01-04 14:47:33 +00:00
|
|
|
import "@/assets/fonts/inter.css";
|
2022-12-18 14:51:47 +00:00
|
|
|
|
2024-01-04 17:01:18 +00:00
|
|
|
import { SnortContext } from "@snort/system-react";
|
2023-02-07 20:04:50 +00:00
|
|
|
import { StrictMode } from "react";
|
|
|
|
import * as ReactDOM from "react-dom/client";
|
2023-10-17 09:54:34 +00:00
|
|
|
import { createBrowserRouter, RouteObject, RouterProvider } from "react-router-dom";
|
2022-12-18 14:51:47 +00:00
|
|
|
|
2024-02-22 11:12:26 +00:00
|
|
|
import { initRelayWorker, preload, UserCache } from "@/Cache";
|
2024-02-27 15:01:39 +00:00
|
|
|
import { ThreadRoute } from "@/Components/Event/Thread/ThreadRoute";
|
2024-01-10 15:25:28 +00:00
|
|
|
import { IntlProvider } from "@/Components/IntlProvider/IntlProvider";
|
2024-01-04 17:01:18 +00:00
|
|
|
import { db } from "@/Db";
|
2024-01-23 15:35:28 +00:00
|
|
|
import { addCachedMetadataToFuzzySearch } from "@/Db/FuzzySearch";
|
2024-01-04 17:01:18 +00:00
|
|
|
import { updateRelayConnections } from "@/Hooks/useLoginRelays";
|
|
|
|
import { AboutPage } from "@/Pages/About";
|
2024-02-29 13:29:47 +00:00
|
|
|
import { SnortDeckLayout } from "@/Pages/Deck/DeckLayout";
|
2024-02-29 09:52:26 +00:00
|
|
|
import DonatePage from "@/Pages/Donate/DonatePage";
|
2024-01-04 17:01:18 +00:00
|
|
|
import ErrorPage from "@/Pages/ErrorPage";
|
|
|
|
import FreeNostrAddressPage from "@/Pages/FreeNostrAddressPage";
|
|
|
|
import HelpPage from "@/Pages/HelpPage";
|
2023-11-17 11:52:10 +00:00
|
|
|
import Layout from "@/Pages/Layout";
|
2024-01-04 17:01:18 +00:00
|
|
|
import { ListFeedPage } from "@/Pages/ListFeedPage";
|
|
|
|
import MessagesPage from "@/Pages/Messages/MessagesPage";
|
2024-02-29 09:52:26 +00:00
|
|
|
import NetworkGraph from "@/Pages/NetworkGraph/NetworkGraph";
|
2024-01-04 17:01:18 +00:00
|
|
|
import NostrAddressPage from "@/Pages/NostrAddressPage";
|
|
|
|
import NostrLinkHandler from "@/Pages/NostrLinkHandler";
|
|
|
|
import NotificationsPage from "@/Pages/Notifications/Notifications";
|
|
|
|
import { OnboardingRoutes } from "@/Pages/onboarding";
|
2023-11-17 11:52:10 +00:00
|
|
|
import ProfilePage from "@/Pages/Profile/ProfilePage";
|
2024-01-10 18:16:30 +00:00
|
|
|
import { RootRoutes } from "@/Pages/Root/RootRoutes";
|
|
|
|
import { RootTabRoutes } from "@/Pages/Root/RootTabRoutes";
|
2023-11-17 11:52:10 +00:00
|
|
|
import SearchPage from "@/Pages/SearchPage";
|
2024-01-04 17:01:18 +00:00
|
|
|
import SettingsRoutes from "@/Pages/settings/Routes";
|
2023-11-17 11:52:10 +00:00
|
|
|
import { SubscribeRoutes } from "@/Pages/subscribe";
|
2024-01-22 16:41:40 +00:00
|
|
|
import WalletPage from "@/Pages/wallet";
|
|
|
|
import { WalletReceivePage } from "@/Pages/wallet/receive";
|
|
|
|
import { WalletSendPage } from "@/Pages/wallet/send";
|
2024-02-28 10:57:26 +00:00
|
|
|
import ZapPoolPage from "@/Pages/ZapPool/ZapPool";
|
2024-01-18 21:11:48 +00:00
|
|
|
import { System } from "@/system";
|
2024-01-17 15:47:01 +00:00
|
|
|
import { storeRefCode, unwrap } from "@/Utils";
|
2024-01-04 13:48:19 +00:00
|
|
|
import { LoginStore } from "@/Utils/Login";
|
2024-01-04 17:01:18 +00:00
|
|
|
import { hasWasm, wasmInit, WasmPath } from "@/Utils/wasm";
|
2023-11-17 11:52:10 +00:00
|
|
|
import { Wallets } from "@/Wallet";
|
2024-04-11 12:26:50 +00:00
|
|
|
import { setupWebLNWalletConfig } from "@/Wallet";
|
2024-01-04 17:01:18 +00:00
|
|
|
|
2023-09-05 13:57:50 +00:00
|
|
|
async function initSite() {
|
2023-12-02 21:27:46 +00:00
|
|
|
storeRefCode();
|
2023-10-12 14:12:06 +00:00
|
|
|
if (hasWasm) {
|
|
|
|
await wasmInit(WasmPath);
|
2024-01-17 15:47:01 +00:00
|
|
|
await initRelayWorker();
|
2023-10-12 14:12:06 +00:00
|
|
|
}
|
2023-09-05 13:57:50 +00:00
|
|
|
const login = LoginStore.takeSnapshot();
|
2023-10-31 15:40:57 +00:00
|
|
|
updateRelayConnections(System, login.relays.item).catch(console.error);
|
2023-11-10 10:13:41 +00:00
|
|
|
setupWebLNWalletConfig(Wallets);
|
2024-01-26 10:21:27 +00:00
|
|
|
|
|
|
|
db.ready = await db.isAvailable();
|
|
|
|
if (db.ready) {
|
2024-04-15 21:31:51 +00:00
|
|
|
const pTags = login.contacts.filter(a => a[0] === "p").map(a => a[1]);
|
|
|
|
await preload(pTags);
|
2024-02-22 11:12:26 +00:00
|
|
|
await System.PreloadSocialGraph();
|
2024-01-26 10:21:27 +00:00
|
|
|
}
|
|
|
|
|
2024-01-23 15:35:28 +00:00
|
|
|
queueMicrotask(() => {
|
|
|
|
for (const ev of UserCache.snapshot()) {
|
2024-01-19 22:01:13 +00:00
|
|
|
try {
|
2024-01-23 15:35:28 +00:00
|
|
|
addCachedMetadataToFuzzySearch(ev);
|
2024-01-19 22:01:13 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error("Failed to handle metadata event from sql db", e);
|
|
|
|
}
|
2024-01-18 22:39:18 +00:00
|
|
|
}
|
|
|
|
});
|
2024-01-23 15:35:28 +00:00
|
|
|
|
2023-09-05 13:57:50 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let didInit = false;
|
2023-10-17 09:54:34 +00:00
|
|
|
const mainRoutes = [
|
|
|
|
...RootRoutes,
|
|
|
|
{
|
|
|
|
path: "/help",
|
|
|
|
element: <HelpPage />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/e/:id",
|
|
|
|
element: <ThreadRoute />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/p/:id",
|
|
|
|
element: <ProfilePage />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/notifications",
|
|
|
|
element: <NotificationsPage />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/free-nostr-address",
|
|
|
|
element: <FreeNostrAddressPage />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/nostr-address",
|
|
|
|
element: <NostrAddressPage />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/messages/:id?",
|
|
|
|
element: <MessagesPage />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/donate",
|
|
|
|
element: <DonatePage />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/search/:keyword?",
|
|
|
|
element: <SearchPage />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/list-feed/:id",
|
|
|
|
element: <ListFeedPage />,
|
|
|
|
},
|
2023-11-02 17:39:42 +00:00
|
|
|
{
|
|
|
|
path: "/about",
|
|
|
|
element: <AboutPage />,
|
|
|
|
},
|
2023-11-16 12:37:48 +00:00
|
|
|
{
|
|
|
|
path: "/graph",
|
|
|
|
element: <NetworkGraph />,
|
|
|
|
},
|
2024-01-02 18:11:44 +00:00
|
|
|
{
|
|
|
|
path: "/wallet",
|
|
|
|
element: (
|
|
|
|
<div className="p">
|
|
|
|
<WalletPage showHistory={true} />
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
},
|
2024-01-04 16:10:40 +00:00
|
|
|
{
|
|
|
|
path: "/wallet/send",
|
2024-01-04 16:11:10 +00:00
|
|
|
element: <WalletSendPage />,
|
2024-01-04 16:10:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/wallet/receive",
|
2024-01-04 16:11:10 +00:00
|
|
|
element: <WalletReceivePage />,
|
2024-01-04 16:10:40 +00:00
|
|
|
},
|
2023-11-08 14:47:35 +00:00
|
|
|
...OnboardingRoutes,
|
2023-12-18 14:29:06 +00:00
|
|
|
...SettingsRoutes,
|
2023-10-17 09:54:34 +00:00
|
|
|
] as Array<RouteObject>;
|
|
|
|
|
|
|
|
if (CONFIG.features.zapPool) {
|
|
|
|
mainRoutes.push({
|
|
|
|
path: "/zap-pool",
|
|
|
|
element: <ZapPoolPage />,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CONFIG.features.subscriptions) {
|
|
|
|
mainRoutes.push(...SubscribeRoutes);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add catch all route
|
|
|
|
mainRoutes.push({
|
2023-12-27 12:43:17 +00:00
|
|
|
path: "/:link",
|
2023-10-17 09:54:34 +00:00
|
|
|
element: <NostrLinkHandler />,
|
|
|
|
});
|
|
|
|
|
|
|
|
const routes = [
|
2023-01-12 12:00:44 +00:00
|
|
|
{
|
|
|
|
element: <Layout />,
|
|
|
|
errorElement: <ErrorPage />,
|
2023-05-25 09:31:47 +00:00
|
|
|
loader: async () => {
|
2023-09-05 13:57:50 +00:00
|
|
|
if (!didInit) {
|
|
|
|
didInit = true;
|
2023-09-05 13:59:44 +00:00
|
|
|
return await initSite();
|
2023-05-25 09:31:47 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2023-10-17 09:54:34 +00:00
|
|
|
children: mainRoutes,
|
2023-02-07 20:04:50 +00:00
|
|
|
},
|
2023-10-17 09:54:34 +00:00
|
|
|
] as Array<RouteObject>;
|
|
|
|
|
|
|
|
if (CONFIG.features.deck) {
|
|
|
|
routes.push({
|
2023-09-07 14:54:25 +00:00
|
|
|
path: "/deck",
|
|
|
|
element: <SnortDeckLayout />,
|
|
|
|
loader: async () => {
|
|
|
|
if (!didInit) {
|
|
|
|
didInit = true;
|
|
|
|
return await initSite();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2023-09-14 18:45:29 +00:00
|
|
|
children: RootTabRoutes,
|
2023-10-17 09:54:34 +00:00
|
|
|
} as RouteObject);
|
|
|
|
}
|
|
|
|
|
2024-01-10 15:44:54 +00:00
|
|
|
const router = createBrowserRouter(routes);
|
2023-01-12 12:00:44 +00:00
|
|
|
|
2023-02-07 19:47:57 +00:00
|
|
|
const root = ReactDOM.createRoot(unwrap(document.getElementById("root")));
|
2022-12-18 14:51:47 +00:00
|
|
|
root.render(
|
2023-01-18 23:39:50 +00:00
|
|
|
<StrictMode>
|
2023-09-21 20:02:59 +00:00
|
|
|
<IntlProvider>
|
|
|
|
<SnortContext.Provider value={System}>
|
2023-11-26 09:17:59 +00:00
|
|
|
<RouterProvider router={router} />
|
2023-09-21 20:02:59 +00:00
|
|
|
</SnortContext.Provider>
|
|
|
|
</IntlProvider>
|
2023-09-12 21:58:37 +00:00
|
|
|
</StrictMode>,
|
2022-12-18 14:51:47 +00:00
|
|
|
);
|
2023-11-10 13:58:27 +00:00
|
|
|
|
2023-11-17 11:52:10 +00:00
|
|
|
// Use react-helmet instead?
|
|
|
|
document.title = CONFIG.appTitle;
|