dtan/src/main.tsx

62 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-11-27 13:19:14 +00:00
import "./index.css";
import React from "react";
import ReactDOM from "react-dom/client";
import { RouteObject, RouterProvider, createBrowserRouter } from "react-router-dom";
import { Layout } from "./page/layout";
import { HomePage } from "./page/home";
import { NostrSystem } from "@snort/system";
import { SnortContext } from "@snort/system-react";
import { ProfilePage } from "./page/profile";
import { NewPage } from "./page/new";
import { TorrentPage } from "./page/torrent";
2023-11-27 14:32:39 +00:00
import { SnortSystemDb } from "@snort/system-web";
2023-11-27 15:12:45 +00:00
import { SearchPage } from "./page/search";
2023-11-27 13:19:14 +00:00
2023-11-27 14:32:39 +00:00
const db = new SnortSystemDb();
const System = new NostrSystem({
2023-11-27 15:12:45 +00:00
db,
2023-11-27 14:32:39 +00:00
});
2023-11-27 13:19:14 +00:00
const Routes = [
{
element: <Layout />,
loader: async () => {
await System.Init();
for (const r of ["wss://nos.lol", "wss://relay.damus.io"]) {
await System.ConnectToRelay(r, { read: true, write: true });
}
return null;
},
children: [
{
path: "/",
element: <HomePage />,
},
{
path: "/p/:id",
element: <ProfilePage />,
},
{
path: "/new",
element: <NewPage />,
},
{
path: "/e/:id",
element: <TorrentPage />,
},
2023-11-27 15:12:45 +00:00
{
path: "/search/:term?",
element: <SearchPage />,
},
2023-11-27 13:19:14 +00:00
],
},
] as Array<RouteObject>;
const Router = createBrowserRouter(Routes);
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<SnortContext.Provider value={System}>
<RouterProvider router={Router} />
</SnortContext.Provider>
</React.StrictMode>,
);