Loads campaigns in the index.
This commit is contained in:
@@ -15,7 +15,6 @@ import { Route as LoginImport } from './routes/login'
|
||||
import { Route as AboutImport } from './routes/about'
|
||||
import { Route as AuthenticatedImport } from './routes/_authenticated'
|
||||
import { Route as IndexImport } from './routes/index'
|
||||
import { Route as AuthenticatedSessionsIndexImport } from './routes/_authenticated/sessions.index'
|
||||
import { Route as AuthenticatedCampaignsIndexImport } from './routes/_authenticated/campaigns.index'
|
||||
import { Route as AuthenticatedCampaignsCampaignIdImport } from './routes/_authenticated/campaigns.$campaignId'
|
||||
|
||||
@@ -44,14 +43,6 @@ const IndexRoute = IndexImport.update({
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any)
|
||||
|
||||
const AuthenticatedSessionsIndexRoute = AuthenticatedSessionsIndexImport.update(
|
||||
{
|
||||
id: '/sessions/',
|
||||
path: '/sessions/',
|
||||
getParentRoute: () => AuthenticatedRoute,
|
||||
} as any,
|
||||
)
|
||||
|
||||
const AuthenticatedCampaignsIndexRoute =
|
||||
AuthenticatedCampaignsIndexImport.update({
|
||||
id: '/campaigns/',
|
||||
@@ -112,13 +103,6 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof AuthenticatedCampaignsIndexImport
|
||||
parentRoute: typeof AuthenticatedImport
|
||||
}
|
||||
'/_authenticated/sessions/': {
|
||||
id: '/_authenticated/sessions/'
|
||||
path: '/sessions'
|
||||
fullPath: '/sessions'
|
||||
preLoaderRoute: typeof AuthenticatedSessionsIndexImport
|
||||
parentRoute: typeof AuthenticatedImport
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,13 +111,11 @@ declare module '@tanstack/react-router' {
|
||||
interface AuthenticatedRouteChildren {
|
||||
AuthenticatedCampaignsCampaignIdRoute: typeof AuthenticatedCampaignsCampaignIdRoute
|
||||
AuthenticatedCampaignsIndexRoute: typeof AuthenticatedCampaignsIndexRoute
|
||||
AuthenticatedSessionsIndexRoute: typeof AuthenticatedSessionsIndexRoute
|
||||
}
|
||||
|
||||
const AuthenticatedRouteChildren: AuthenticatedRouteChildren = {
|
||||
AuthenticatedCampaignsCampaignIdRoute: AuthenticatedCampaignsCampaignIdRoute,
|
||||
AuthenticatedCampaignsIndexRoute: AuthenticatedCampaignsIndexRoute,
|
||||
AuthenticatedSessionsIndexRoute: AuthenticatedSessionsIndexRoute,
|
||||
}
|
||||
|
||||
const AuthenticatedRouteWithChildren = AuthenticatedRoute._addFileChildren(
|
||||
@@ -147,7 +129,6 @@ export interface FileRoutesByFullPath {
|
||||
'/login': typeof LoginRoute
|
||||
'/campaigns/$campaignId': typeof AuthenticatedCampaignsCampaignIdRoute
|
||||
'/campaigns': typeof AuthenticatedCampaignsIndexRoute
|
||||
'/sessions': typeof AuthenticatedSessionsIndexRoute
|
||||
}
|
||||
|
||||
export interface FileRoutesByTo {
|
||||
@@ -157,7 +138,6 @@ export interface FileRoutesByTo {
|
||||
'/login': typeof LoginRoute
|
||||
'/campaigns/$campaignId': typeof AuthenticatedCampaignsCampaignIdRoute
|
||||
'/campaigns': typeof AuthenticatedCampaignsIndexRoute
|
||||
'/sessions': typeof AuthenticatedSessionsIndexRoute
|
||||
}
|
||||
|
||||
export interface FileRoutesById {
|
||||
@@ -168,7 +148,6 @@ export interface FileRoutesById {
|
||||
'/login': typeof LoginRoute
|
||||
'/_authenticated/campaigns/$campaignId': typeof AuthenticatedCampaignsCampaignIdRoute
|
||||
'/_authenticated/campaigns/': typeof AuthenticatedCampaignsIndexRoute
|
||||
'/_authenticated/sessions/': typeof AuthenticatedSessionsIndexRoute
|
||||
}
|
||||
|
||||
export interface FileRouteTypes {
|
||||
@@ -180,16 +159,8 @@ export interface FileRouteTypes {
|
||||
| '/login'
|
||||
| '/campaigns/$campaignId'
|
||||
| '/campaigns'
|
||||
| '/sessions'
|
||||
fileRoutesByTo: FileRoutesByTo
|
||||
to:
|
||||
| '/'
|
||||
| ''
|
||||
| '/about'
|
||||
| '/login'
|
||||
| '/campaigns/$campaignId'
|
||||
| '/campaigns'
|
||||
| '/sessions'
|
||||
to: '/' | '' | '/about' | '/login' | '/campaigns/$campaignId' | '/campaigns'
|
||||
id:
|
||||
| '__root__'
|
||||
| '/'
|
||||
@@ -198,7 +169,6 @@ export interface FileRouteTypes {
|
||||
| '/login'
|
||||
| '/_authenticated/campaigns/$campaignId'
|
||||
| '/_authenticated/campaigns/'
|
||||
| '/_authenticated/sessions/'
|
||||
fileRoutesById: FileRoutesById
|
||||
}
|
||||
|
||||
@@ -239,8 +209,7 @@ export const routeTree = rootRoute
|
||||
"filePath": "_authenticated.tsx",
|
||||
"children": [
|
||||
"/_authenticated/campaigns/$campaignId",
|
||||
"/_authenticated/campaigns/",
|
||||
"/_authenticated/sessions/"
|
||||
"/_authenticated/campaigns/"
|
||||
]
|
||||
},
|
||||
"/about": {
|
||||
@@ -256,10 +225,6 @@ export const routeTree = rootRoute
|
||||
"/_authenticated/campaigns/": {
|
||||
"filePath": "_authenticated/campaigns.index.tsx",
|
||||
"parent": "/_authenticated"
|
||||
},
|
||||
"/_authenticated/sessions/": {
|
||||
"filePath": "_authenticated/sessions.index.tsx",
|
||||
"parent": "/_authenticated"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,37 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { pb } from "@/lib/pocketbase";
|
||||
import type { Campaign } from "@/lib/types";
|
||||
import { Link } from "@tanstack/react-router";
|
||||
|
||||
export const Route = createFileRoute("/_authenticated/campaigns/")({
|
||||
loader: async () => {
|
||||
const records = await pb.collection("campaigns").getFullList();
|
||||
return { campaigns: records.map((rec: any) => ({ id: rec.id, name: rec.name })) as Campaign[] };
|
||||
},
|
||||
component: RouteComponent,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return <div>Hello "/campaigns/"!</div>;
|
||||
const { campaigns } = Route.useLoaderData();
|
||||
|
||||
if (!campaigns || campaigns.length === 0) return <div>No campaigns found.</div>;
|
||||
|
||||
return (
|
||||
<div className="max-w-xl mx-auto py-8">
|
||||
<h2 className="text-xl font-bold mb-4 text-slate-100">Your Campaigns</h2>
|
||||
<ul className="space-y-2">
|
||||
{campaigns.map((c) => (
|
||||
<li key={c.id}>
|
||||
<Link
|
||||
to="/campaigns/$campaignId"
|
||||
params={{ campaignId: c.id }}
|
||||
className="block px-4 py-2 rounded bg-slate-800 hover:bg-violet-700 text-slate-100 transition-colors"
|
||||
>
|
||||
{c.name}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
|
||||
export const Route = createFileRoute('/_authenticated/sessions/')({
|
||||
component: RouteComponent,
|
||||
})
|
||||
|
||||
function RouteComponent() {
|
||||
return <div>Hello "/sessions/"!</div>
|
||||
}
|
||||
Reference in New Issue
Block a user