Files
Showy/react_frontend/src/router.tsx
T
Mohammed AbadandCopilot 02cdcf733d feat(frontend): navigate non-library entries to TMDB preview page
- Add TmdbPreviewPage showing TMDB details without adding to library
- Display backdrop, poster, title, tagline, genres, rating, storyline
- Show season/episode count for TV series
- Add "Add to Library" button that creates entry then redirects to details page
- Show "Already in Library — View" if entry exists in DB
- Add /entry/tmdb/:type/:tmdbId route in router.tsx
- Add TmdbPreview type, entriesApi.previewTmdb(), and useTmdbPreview() hook
- Update EntryCard to navigate to preview page instead of auto-adding

Co-authored-by: Copilot <copilot@github.com>
2026-04-27 04:03:21 +01:00

244 lines
6.3 KiB
TypeScript

import { createBrowserRouter } from 'react-router-dom';
import { lazy, Suspense, type ReactNode } from 'react';
import { AppLayout } from '@/components/layout/AppLayout';
import {
DashboardSkeleton,
HomeSkeleton,
LibrarySkeleton,
WatchlistSkeleton,
CollectionsSkeleton,
CollectionDetailsSkeleton,
EntryDetailsSkeleton,
SeasonSkeleton,
EpisodeSkeleton,
PeopleSkeleton,
PersonDetailsSkeleton,
MediaSkeleton,
CalendarSkeleton,
SettingsSkeleton,
} from '@/components/skeletons/PageSkeletons';
// Lazy-loaded pages
const HomePage = lazy(() =>
import('@/pages/HomePage').then((m) => ({ default: m.HomePage }))
);
const DashboardPage = lazy(() =>
import('@/pages/DashboardPage').then((m) => ({ default: m.DashboardPage }))
);
const LibraryPage = lazy(() =>
import('@/pages/LibraryPage').then((m) => ({ default: m.LibraryPage }))
);
const WatchlistPage = lazy(() =>
import('@/pages/WatchlistPage').then((m) => ({ default: m.WatchlistPage }))
);
const CollectionsPage = lazy(() =>
import('@/pages/CollectionsPage').then((m) => ({
default: m.CollectionsPage,
}))
);
const CollectionDetailsPage = lazy(() =>
import('@/pages/CollectionDetailsPage').then((m) => ({
default: m.CollectionDetailsPage,
}))
);
const MediaPage = lazy(() =>
import('@/pages/MediaPage').then((m) => ({ default: m.MediaPage }))
);
const CalendarPage = lazy(() =>
import('@/pages/CalendarPage').then((m) => ({ default: m.CalendarPage }))
);
const EntryDetailsPage = lazy(() =>
import('@/pages/EntryDetailsPage').then((m) => ({
default: m.EntryDetailsPage,
}))
);
const TmdbPreviewPage = lazy(() =>
import('@/pages/TmdbPreviewPage').then((m) => ({
default: m.TmdbPreviewPage,
}))
);
const SeasonPage = lazy(() =>
import('@/pages/SeasonPage').then((m) => ({ default: m.SeasonPage }))
);
const EpisodePage = lazy(() =>
import('@/pages/EpisodePage').then((m) => ({ default: m.EpisodePage }))
);
const PeoplePage = lazy(() =>
import('@/pages/PeoplePage').then((m) => ({ default: m.PeoplePage }))
);
const PersonDetailsPage = lazy(() =>
import('@/pages/PersonDetailsPage').then((m) => ({
default: m.PersonDetailsPage,
}))
);
const PersonTmdbRedirectPage = lazy(() =>
import('@/pages/PersonTmdbRedirectPage').then((m) => ({
default: m.PersonTmdbRedirectPage,
}))
);
const SettingsPage = lazy(() =>
import('@/pages/SettingsPage').then((m) => ({ default: m.SettingsPage }))
);
const DiscoverPage = lazy(() =>
import('@/pages/DiscoverPage').then((m) => ({ default: m.DiscoverPage }))
);
const SearchPage = lazy(() =>
import('@/pages/SearchPage').then((m) => ({ default: m.SearchPage }))
);
function SuspensePage({ children, fallback }: { children: ReactNode; fallback?: ReactNode }) {
return <Suspense fallback={fallback ?? <HomeSkeleton />}>{children}</Suspense>;
}
export const router = createBrowserRouter([
{
element: <AppLayout />,
children: [
{
path: '/',
element: (
<SuspensePage fallback={<HomeSkeleton />}>
<HomePage />
</SuspensePage>
),
},
{
path: '/search',
element: (
<SuspensePage fallback={<HomeSkeleton />}>
<SearchPage />
</SuspensePage>
),
},
{
path: '/dashboard',
element: (
<SuspensePage fallback={<DashboardSkeleton />}>
<DashboardPage />
</SuspensePage>
),
},
{
path: '/library',
element: (
<SuspensePage fallback={<LibrarySkeleton />}>
<LibraryPage />
</SuspensePage>
),
},
{
path: '/discover/:category',
element: (
<SuspensePage fallback={<HomeSkeleton />}>
<DiscoverPage />
</SuspensePage>
),
},
{
path: '/watchlist',
element: (
<SuspensePage fallback={<WatchlistSkeleton />}>
<WatchlistPage />
</SuspensePage>
),
},
{
path: '/collections',
element: (
<SuspensePage fallback={<CollectionsSkeleton />}>
<CollectionsPage />
</SuspensePage>
),
},
{
path: '/collections/:id',
element: (
<SuspensePage fallback={<CollectionDetailsSkeleton />}>
<CollectionDetailsPage />
</SuspensePage>
),
},
{
path: '/media',
element: (
<SuspensePage fallback={<MediaSkeleton />}>
<MediaPage />
</SuspensePage>
),
},
{
path: '/calendar',
element: (
<SuspensePage fallback={<CalendarSkeleton />}>
<CalendarPage />
</SuspensePage>
),
},
{
path: '/entry/tmdb/:type/:tmdbId',
element: (
<SuspensePage fallback={<EntryDetailsSkeleton />}>
<TmdbPreviewPage />
</SuspensePage>
),
},
{
path: '/entry/:id',
element: (
<SuspensePage fallback={<EntryDetailsSkeleton />}>
<EntryDetailsPage />
</SuspensePage>
),
},
{
path: '/entry/:entryId/season/:seasonId',
element: (
<SuspensePage fallback={<SeasonSkeleton />}>
<SeasonPage />
</SuspensePage>
),
},
{
path: '/entry/:entryId/season/:seasonId/episode/:episodeId',
element: (
<SuspensePage fallback={<EpisodeSkeleton />}>
<EpisodePage />
</SuspensePage>
),
},
{
path: '/people',
element: (
<SuspensePage fallback={<PeopleSkeleton />}>
<PeoplePage />
</SuspensePage>
),
},
{
path: '/people/tmdb/:tmdbId',
element: (
<SuspensePage fallback={<PersonDetailsSkeleton />}>
<PersonTmdbRedirectPage />
</SuspensePage>
),
},
{
path: '/people/:id',
element: (
<SuspensePage fallback={<PersonDetailsSkeleton />}>
<PersonDetailsPage />
</SuspensePage>
),
},
{
path: '/settings',
element: (
<SuspensePage fallback={<SettingsSkeleton />}>
<SettingsPage />
</SuspensePage>
),
},
],
},
]);