From 6a5de70fdbf4cbf706274e9f40278fc8dcbd5b25 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Mon, 1 Apr 2024 00:04:30 +0800 Subject: [PATCH] feat(v2): add website overview --- src/client/routeTree.gen.ts | 16 +++++- src/client/routes/website.tsx | 50 ++++++++++------- src/client/routes/website/overview.tsx | 77 ++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 21 deletions(-) create mode 100644 src/client/routes/website/overview.tsx diff --git a/src/client/routeTree.gen.ts b/src/client/routeTree.gen.ts index ad10fbf..cf63cc7 100644 --- a/src/client/routeTree.gen.ts +++ b/src/client/routeTree.gen.ts @@ -19,6 +19,7 @@ import { Route as MonitorImport } from './routes/monitor' import { Route as LoginImport } from './routes/login' import { Route as DashboardImport } from './routes/dashboard' import { Route as IndexImport } from './routes/index' +import { Route as WebsiteOverviewImport } from './routes/website/overview' import { Route as WebsiteAddImport } from './routes/website/add' import { Route as WebsiteWebsiteIdImport } from './routes/website/$websiteId' import { Route as TelemetryAddImport } from './routes/telemetry/add' @@ -70,6 +71,11 @@ const IndexRoute = IndexImport.update({ getParentRoute: () => rootRoute, } as any) +const WebsiteOverviewRoute = WebsiteOverviewImport.update({ + path: '/overview', + getParentRoute: () => WebsiteRoute, +} as any) + const WebsiteAddRoute = WebsiteAddImport.update({ path: '/add', getParentRoute: () => WebsiteRoute, @@ -178,6 +184,10 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof WebsiteAddImport parentRoute: typeof WebsiteImport } + '/website/overview': { + preLoaderRoute: typeof WebsiteOverviewImport + parentRoute: typeof WebsiteImport + } } } @@ -191,7 +201,11 @@ export const routeTree = rootRoute.addChildren([ PageRoute.addChildren([PageSlugRoute, PageAddRoute]), RegisterRoute, TelemetryRoute.addChildren([TelemetryTelemetryIdRoute, TelemetryAddRoute]), - WebsiteRoute.addChildren([WebsiteWebsiteIdRoute, WebsiteAddRoute]), + WebsiteRoute.addChildren([ + WebsiteWebsiteIdRoute, + WebsiteAddRoute, + WebsiteOverviewRoute, + ]), ]) /* prettier-ignore-end */ diff --git a/src/client/routes/website.tsx b/src/client/routes/website.tsx index 085ca66..b514974 100644 --- a/src/client/routes/website.tsx +++ b/src/client/routes/website.tsx @@ -14,7 +14,8 @@ import { useNavigate, useRouterState, } from '@tanstack/react-router'; -import { LuPlus } from 'react-icons/lu'; +import { useEffect } from 'react'; +import { LuEye, LuPlus } from 'react-icons/lu'; export const Route = createFileRoute('/website')({ beforeLoad: routeAuthBeforeLoad, @@ -39,19 +40,19 @@ function WebsiteComponent() { href: `/website/${item.id}`, })); - useDataReady( - () => data.length > 0, - () => { - if (pathname === Route.fullPath) { - navigate({ - to: '/website/$websiteId', - params: { - websiteId: data[0].id, - }, - }); - } + useEffect(() => { + if (pathname === Route.fullPath) { + navigate({ + to: '/website/overview', + }); } - ); + }, []); + + const handleClickOverview = useEvent(() => { + navigate({ + to: '/website/overview', + }); + }); const handleClickAdd = useEvent(() => { navigate({ @@ -67,13 +68,22 @@ function WebsiteComponent() { - {t('Add')} - +
+ + +
} /> } diff --git a/src/client/routes/website/overview.tsx b/src/client/routes/website/overview.tsx new file mode 100644 index 0000000..9f77097 --- /dev/null +++ b/src/client/routes/website/overview.tsx @@ -0,0 +1,77 @@ +import { routeAuthBeforeLoad } from '@/utils/route'; +import { createFileRoute, useNavigate } from '@tanstack/react-router'; +import { z } from 'zod'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useForm } from 'react-hook-form'; +import { useTranslation } from '@i18next-toolkit/react'; +import { Button } from '@/components/ui/button'; +import { + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, +} from '@/components/ui/form'; +import { useEvent } from '@/hooks/useEvent'; +import { Input } from '@/components/ui/input'; +import { useCurrentWorkspaceId } from '@/store/user'; +import { trpc } from '@/api/trpc'; +import { hostnameRegex } from '@tianji/shared'; +import { Card, CardContent, CardFooter } from '@/components/ui/card'; +import { CommonWrapper } from '@/components/CommonWrapper'; +import { WebsiteOverview } from '@/components/website/WebsiteOverview'; +import { Empty } from 'antd'; +import { LuPlus } from 'react-icons/lu'; +import { ScrollArea } from '@/components/ui/scroll-area'; + +export const Route = createFileRoute('/website/overview')({ + beforeLoad: routeAuthBeforeLoad, + component: WebsiteOverviewComponent, +}); + +function WebsiteOverviewComponent() { + const { t } = useTranslation(); + const workspaceId = useCurrentWorkspaceId(); + const { data: websites = [], isLoading } = trpc.website.all.useQuery({ + workspaceId, + }); + const navigate = useNavigate(); + + return ( + {t('Add Website')}} + > + + {websites.length === 0 && isLoading === false && ( + +
+ {t('Not any website has been exist')} +
+ + + } + /> + )} + +
+ {websites.map((website) => ( + + ))} +
+
+
+ ); +}