feat: replace the starring page with a person page
A credit now opens /person/{id}: portrait, name, department, life dates and
birthplace, the biography, and the full filmography ranked by vote count.
One request carries all of it — combined_credits rides along on the person
call — so the discover based starring query and its with_people filter go.
The biography fills whatever height the portrait leaves and fades where it
is cut, with the whole text in a tooltip on hover; a phone has no height to
respect there, so it simply runs on.
Route level and query level skeletons stand in while it loads, built from
the shadcn primitive.
Development server side fetches go over the loopback rather than SITE_URL,
which is a LAN address meant for other devices: once that address moves the
fetch hangs until undici times out, ten seconds per navigation.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6fc41c0901
commit
3dc2ebfe53
22 files changed
+342
-108
No files matched your search
@@ -4,8 +4,10 @@ import { SITE_URL } from '@/env';
|
||||
|
||||
import Http from './Http';
|
||||
|
||||
const ROOT = isServer ? `${SITE_URL?.startsWith('http') ? SITE_URL : `https://${SITE_URL}`}` : '';
|
||||
const PUBLIC_ORIGIN = `${SITE_URL?.startsWith('http') ? SITE_URL : `https://${SITE_URL}`}`;
|
||||
|
||||
const movieAdvisor = new Http(`${ROOT}/api/tmdb`);
|
||||
const ROOT = process.env.NODE_ENV === 'development' ? `http://127.0.0.1:${process.env.PORT || 3000}` : PUBLIC_ORIGIN;
|
||||
|
||||
const movieAdvisor = new Http(`${isServer ? ROOT : ''}/api/tmdb`);
|
||||
|
||||
export default movieAdvisor;
|
||||
@@ -6,7 +6,6 @@ export const mapDetailsToAiring = ({
|
||||
number_of_seasons,
|
||||
status
|
||||
}: TMDBSeriesDetails): Airing | undefined => {
|
||||
// before a premiere there is nothing aired yet, the upcoming episode is the only position we have
|
||||
const current = last_episode_to_air || next_episode_to_air;
|
||||
|
||||
if (!current) return undefined;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// TMDB release types: 1 premiere, 2 limited theatrical, 3 theatrical, 4 digital, 5 physical, 6 TV
|
||||
const STATE_BY_RELEASE_TYPE: Record<number, AvailabilityState> = {
|
||||
1: 'theatre',
|
||||
2: 'theatre',
|
||||
@@ -7,11 +6,9 @@ const STATE_BY_RELEASE_TYPE: Record<number, AvailabilityState> = {
|
||||
5: 'bluray'
|
||||
};
|
||||
|
||||
/** How long a movie is assumed to still be running in theatres when TMDB has no digital/physical date yet */
|
||||
const THEATRICAL_WINDOW = 120 * 24 * 60 * 60 * 1000;
|
||||
|
||||
export const mapReleaseDatesToAvailability = (results?: TMDBCountryReleaseDates[]): Availability | undefined => {
|
||||
// TMDB reports dates per country, it doesn't matter where a window opened first — only when
|
||||
const availability = (results || []).reduce<Availability>((dates, { release_dates }) => {
|
||||
(release_dates || []).forEach(({ type, release_date }) => {
|
||||
const state = STATE_BY_RELEASE_TYPE[type];
|
||||
@@ -37,8 +34,6 @@ export const getAvailabilityState = ({ theatre, stream, bluray }: Availability):
|
||||
if (isUpcoming(theatre)) return 'theatre';
|
||||
if (!theatre) return undefined;
|
||||
|
||||
// Still in theatres only while the run lasts or while a digital/physical date is announced but not reached,
|
||||
// otherwise TMDB simply never got the digital entry and the movie is long out of cinemas
|
||||
const isRunning = Date.now() - Date.parse(theatre) < THEATRICAL_WINDOW;
|
||||
|
||||
return isRunning || isUpcoming(stream) || isUpcoming(bluray) ? 'theatre' : 'stream';
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { mapMovieSeriesToShow } from './Show';
|
||||
|
||||
const unique = (credits: TMDBPersonCredit[]) => {
|
||||
const titles = new Map<string, TMDBPersonCredit>();
|
||||
|
||||
credits.forEach((credit) => {
|
||||
const key = `${credit.media_type}-${credit.id}`;
|
||||
|
||||
if (credit.poster_path && ['movie', 'tv'].includes(credit.media_type) && !titles.has(key)) {
|
||||
titles.set(key, credit);
|
||||
}
|
||||
});
|
||||
|
||||
return Array.from(titles.values());
|
||||
};
|
||||
|
||||
const mapPersonToProfile = ({ combined_credits, ...person }: TMDBPersonDetails): Profile => ({
|
||||
id: person.id,
|
||||
name: person.name,
|
||||
photo: person.profile_path ? `https://image.tmdb.org/t/p/w500${person.profile_path}` : '',
|
||||
biography: person.biography || '',
|
||||
department: person.known_for_department || '',
|
||||
birthday: person.birthday || undefined,
|
||||
deathday: person.deathday || undefined,
|
||||
birthplace: person.place_of_birth || undefined,
|
||||
shows: unique([...(combined_credits?.cast || []), ...(combined_credits?.crew || [])])
|
||||
.sort((a, b) => b.vote_count - a.vote_count)
|
||||
.map((credit) => mapMovieSeriesToShow(credit, credit.media_type))
|
||||
});
|
||||
|
||||
export default mapPersonToProfile;
|
||||
@@ -7,7 +7,6 @@ export type CreditsQueryProps = {
|
||||
|
||||
const photo = (path: string) => `https://image.tmdb.org/t/p/w185${path}`;
|
||||
|
||||
// a series has no single director, so the one behind most episodes stands in for it
|
||||
const findDirector = (crew: Crew[] = []) =>
|
||||
crew
|
||||
.filter(
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import movieAdvisor from '../clients/movieAdvisor';
|
||||
import mapPersonToProfile from '../dto/Person';
|
||||
|
||||
export type PersonQueryProps = {
|
||||
personId?: string;
|
||||
};
|
||||
|
||||
const personQuery = ({ personId }: PersonQueryProps) => ({
|
||||
enabled: Boolean(personId),
|
||||
queryKey: ['person', personId],
|
||||
queryFn: () =>
|
||||
movieAdvisor
|
||||
.get<TMDBPersonDetails>(`/person/${personId}`, {
|
||||
params: { append_to_response: 'combined_credits' },
|
||||
preventCache: false
|
||||
})
|
||||
.then(mapPersonToProfile)
|
||||
.catch((error) => Promise.reject(error))
|
||||
});
|
||||
|
||||
export default personQuery;
|
||||
@@ -3,11 +3,10 @@ import mapMoviesSeriesResponseToShows from '../dto/Show';
|
||||
|
||||
export type PopularQueryProps = {
|
||||
sortBy?: string;
|
||||
starring?: string;
|
||||
};
|
||||
|
||||
const popularQuery = ({ sortBy = 'popularity.desc', starring }: PopularQueryProps = {}) => ({
|
||||
queryKey: ['popular', sortBy, starring],
|
||||
const popularQuery = ({ sortBy = 'popularity.desc' }: PopularQueryProps = {}) => ({
|
||||
queryKey: ['popular', sortBy],
|
||||
initialPageParam: '1',
|
||||
queryFn: ({ pageParam = '1' }: { pageParam?: string }) =>
|
||||
movieAdvisor
|
||||
@@ -15,8 +14,6 @@ const popularQuery = ({ sortBy = 'popularity.desc', starring }: PopularQueryProp
|
||||
params: {
|
||||
page: pageParam,
|
||||
sort_by: sortBy,
|
||||
// with_people covers cast and crew, with_cast on top of it would AND directors away
|
||||
with_people: starring,
|
||||
'vote_count.gte': 300,
|
||||
'vote_average.lte': 10,
|
||||
'vote_average.gte': 5
|
||||
|
||||
Reference in new issue
Block a user