fix(frontend): redirect to local person page if already in DB
- PersonDetailsPage (TMDB mode) redirects to /people/:localId when local_id is present - "Add to Library" button only shown for people not in local DB - Shows skeleton during redirect to avoid flash of preview content Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
1 parent
507cdbcff7
commit
b3002a329d
2 files changed
+14
-1
No files matched your search
@@ -23,6 +23,7 @@ export interface TmdbFilmographyResponse {
|
|||||||
|
|
||||||
export interface TmdbPersonPreview {
|
export interface TmdbPersonPreview {
|
||||||
tmdb_id: number;
|
tmdb_id: number;
|
||||||
|
local_id: number | null;
|
||||||
name: string;
|
name: string;
|
||||||
biography: string | null;
|
biography: string | null;
|
||||||
birthday: string | null;
|
birthday: string | null;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useParams, useNavigate, useLocation } from 'react-router-dom';
|
import { useParams, useNavigate, useLocation } from 'react-router-dom';
|
||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
usePerson,
|
usePerson,
|
||||||
usePersonTmdbFilmography,
|
usePersonTmdbFilmography,
|
||||||
@@ -121,6 +121,13 @@ function TmdbPersonView({ tmdbId }: { tmdbId: number }) {
|
|||||||
const libraryMap = useLibraryStore((s) => s.entries);
|
const libraryMap = useLibraryStore((s) => s.entries);
|
||||||
const libraryLoaded = useLibraryStore((s) => s.isLoaded);
|
const libraryLoaded = useLibraryStore((s) => s.isLoaded);
|
||||||
|
|
||||||
|
// If person already exists in local DB, redirect to their local page
|
||||||
|
useEffect(() => {
|
||||||
|
if (preview?.local_id) {
|
||||||
|
navigate(`/people/${preview.local_id}`, { replace: true });
|
||||||
|
}
|
||||||
|
}, [preview?.local_id, navigate]);
|
||||||
|
|
||||||
if (isError) {
|
if (isError) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center justify-center gap-3 py-20">
|
<div className="flex flex-col items-center justify-center gap-3 py-20">
|
||||||
@@ -137,6 +144,11 @@ function TmdbPersonView({ tmdbId }: { tmdbId: number }) {
|
|||||||
return <PersonSkeleton />;
|
return <PersonSkeleton />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Redirecting to local page, show skeleton while navigating
|
||||||
|
if (preview.local_id) {
|
||||||
|
return <PersonSkeleton />;
|
||||||
|
}
|
||||||
|
|
||||||
const profileUrl = preview.profile_path
|
const profileUrl = preview.profile_path
|
||||||
? `${TMDB_IMG}/w300${preview.profile_path}`
|
? `${TMDB_IMG}/w300${preview.profile_path}`
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|||||||
Reference in new issue
Block a user