From e80d82408e3c3f96a3e02566db46ba6909f17d1f Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 7 Mar 2024 05:33:23 +0700 Subject: [PATCH] basic pages --- src/routes/$namespace/$chainId.tsx | 22 ++++++++++++++++++++++ src/routes/$namespace/index.tsx | 24 ++++++++++++++++++++++++ src/routes/__root.tsx | 12 +++++++++--- src/routes/index.tsx | 2 +- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/routes/$namespace/$chainId.tsx create mode 100644 src/routes/$namespace/index.tsx diff --git a/src/routes/$namespace/$chainId.tsx b/src/routes/$namespace/$chainId.tsx new file mode 100644 index 0000000..7c5be2e --- /dev/null +++ b/src/routes/$namespace/$chainId.tsx @@ -0,0 +1,22 @@ +import { redirect } from "@tanstack/react-router"; +import { requireChains } from "@/entities/chain/lib"; +import { useChainState } from "@/entities/chain/model"; +import { createFileRoute } from "@tanstack/react-router"; + +function ChainPage() { + return
Content
; +} + +export const Route = createFileRoute("/$namespace/$chainId")({ + component: ChainPage, + loader: async ({ params }) => { + await requireChains(); + const chains = useChainState.getState().chains; + + if (typeof chains === "undefined") + throw redirect({ to: "/$namespace", params }); + + const selectedChain = chains.find((value) => value._id === params.chainId); + if (!selectedChain) throw redirect({ to: "/$namespace", params }); + }, +}); diff --git a/src/routes/$namespace/index.tsx b/src/routes/$namespace/index.tsx new file mode 100644 index 0000000..c0756f5 --- /dev/null +++ b/src/routes/$namespace/index.tsx @@ -0,0 +1,24 @@ +import { redirect } from "@tanstack/react-router"; +import { requireChains } from "@/entities/chain/lib"; +import { useChainState } from "@/entities/chain/model"; +import { createFileRoute } from "@tanstack/react-router"; + +function IndexPage() { + return
content
; +} + +export const Route = createFileRoute("/$namespace/")({ + component: IndexPage, + loader: async ({ params }) => { + await requireChains(); + const chains = useChainState.getState().chains; + + if (typeof chains === "undefined") throw redirect({ to: "/" }); + + if (chains.length > 0) + throw redirect({ + to: `/$namespace/$chainId`, + params: { namespace: params.namespace, chainId: chains[0]._id }, + }); + }, +}); diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 43adf88..e3c66b1 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -1,9 +1,15 @@ +import { Header } from "@/widgets/header"; +import { Sidebar } from "@/widgets/sidebar"; import { createRootRoute, Outlet } from "@tanstack/react-router"; export const Route = createRootRoute({ component: () => ( - <> - - +
+
+
+ + +
+
), }); diff --git a/src/routes/index.tsx b/src/routes/index.tsx index add34f8..5b9eff0 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -1,7 +1,7 @@ import { createFileRoute } from "@tanstack/react-router"; function IndexPage() { - return
hi
; + return
Сервис недоступен
; } export const Route = createFileRoute("/")({