diff options
author | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-10-29 01:21:05 +0300 |
---|---|---|
committer | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-10-29 01:21:05 +0300 |
commit | fd4e0c3112d69061d495dfcf79f6ef62e3c6d5e6 (patch) | |
tree | fa55d6e879e3c6d85601d5c2486837f323ffd81d /web/src/index.js | |
parent | b26bd10926447ed59cbf263aef087bb7c04f35eb (diff) |
Diffstat (limited to 'web/src/index.js')
-rw-r--r-- | web/src/index.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/web/src/index.js b/web/src/index.js new file mode 100644 index 0000000..a43ed75 --- /dev/null +++ b/web/src/index.js @@ -0,0 +1,49 @@ +import React from "react"; +import { createRoot } from "react-dom/client"; +import { createHashRouter, RouterProvider } from "react-router-dom"; +import Root from "./root"; +import List from "./pages/list"; +import Echo from "./pages/echo"; + +const router = createHashRouter([ + { + path: "/", + element: <Root />, + // loader: rootLoader, + children: [ + { + path: "", + element: <List />, + loader: () => { + return fetch("/api/list").then((x) => x.json()); + }, + }, + { + path: "e/:echoID", + element: <Echo />, + loader: async ({ params }) => { + const echoData = await fetch( + `/api/e?e=${params.echoID}&limit=10` + ).then((x) => x.json()); + let echo = []; + if (echoData[params.echoID]) { + echo = echoData[params.echoID]; + } + const messages = await fetch( + `/api/m?e=${params.echoID}` + ).then((x) => x.json()); + + return { echo, messages: messages.reverse() }; + }, + }, + ], + }, +]); + +const root = createRoot(document.getElementById("app")); +root.render( + <RouterProvider + router={router} + fallbackElement={<article aria-busy="true">Загрузка</article>} + /> +); |