Files
Showy/react_frontend/src/lib/media-utils.ts
T
Mohammed Abad 3ca24434d7 feat(frontend): Entry details redesign, people filmography, calendar improvements
- EntryDetailsPage: sticky poster layout, centered max-w-4xl, director by-line
  with link, rating pills (IMDb/TMDB/You), quick actions under poster, RatingDialog
  with star UI, In Collections section using backdrops, EntrySettingsDialog with
  show_in_calendar / auto_sync / rating options
- RatingDialog: new component with 10-star interactive rating
- AddEntryToCollectionDialog: optimistic cache updates so checkbox state reflects
  immediately and In Collections section on entry details page refreshes
- PersonDetailsPage: filmography section showing library vs. non-library entries
  via person.roles, TMDB combined credits for non-library titles
- PersonTmdbRedirectPage: new redirect page for TMDB person IDs to local person ID
- PeoplePage: fix person card links to use /people/tmdb/:tmdbId
- CalendarPage: full-height layout, larger episode thumbnails, episode items
  clickable, improved tooltip, show_in_calendar backend filter
- Fix useUpdateEntry to also invalidate entryKeys.all (favorite button reactivity)
- Fix updateRatings API body wrapping
- Add useUpdateEntryRatings, usePersonCredits, useFetchPersonByTmdbId hooks
- Add getCollectionBackdropUrl to media-utils
- Types: show_in_calendar, auto_sync on Entry; id on EntryRatings; roles on People
- Backend: fix fetchPersonData alias in peopleService; remove duplicate
  getPersonCredits; add show_in_calendar filter to episodeService
2026-04-01 00:25:30 +01:00

119 lines
3.1 KiB
TypeScript

import { getMediaUrl, getTmdbImageUrl } from '@/lib/api';
import type { Entry, Collection, Media } from '@/types';
const DEFAULT_POSTER = '/images/default-poster.png';
export function getPosterUrl(entry: Entry): string {
// Not in library, use TMDB poster
if (!entry.isInLibrary) {
return entry.poster_path
? getTmdbImageUrl(entry.poster_path, 'w342')
: DEFAULT_POSTER;
}
// In library: try local selected poster
if (entry.medias) {
const selectedPoster = entry.medias.find(
(m: Media) => m.type === 'poster' && m.is_selected
);
if (selectedPoster?.path) {
return getMediaUrl('entries', 'posters', 'preview', selectedPoster.path);
}
}
// Fallback to TMDB poster
if (entry.poster_path) {
return getTmdbImageUrl(entry.poster_path, 'w300');
}
return DEFAULT_POSTER;
}
export function getBackdropUrl(entry: Entry): string {
if (entry.medias) {
const selectedBackdrop = entry.medias.find(
(m: Media) => m.type === 'backdrop' && m.is_selected
);
if (selectedBackdrop?.path) {
return getMediaUrl(
'entries',
'backdrops',
'full',
selectedBackdrop.path
);
}
}
if (entry.banner_path) {
return getTmdbImageUrl(entry.banner_path, 'w1280');
}
return '';
}
export function getTmdbPosterUrl(
posterPath: string | null,
size = 'w342'
): string {
if (!posterPath) return DEFAULT_POSTER;
return getTmdbImageUrl(posterPath, size);
}
export function getCollectionBackdropUrl(collection: Collection): string {
if (collection.medias) {
const selectedBackdrop = collection.medias.find(
(m: Media) => m.type === 'backdrop' && m.is_selected
);
if (selectedBackdrop?.path) {
return getMediaUrl('collections', 'backdrops', 'full', selectedBackdrop.path);
}
}
if (collection.backdrop_path) {
return getTmdbImageUrl(collection.backdrop_path, 'w780');
}
return getCollectionPosterUrl(collection);
}
export function getCollectionPosterUrl(collection: Collection): string {
if (collection.medias) {
const selectedPoster = collection.medias.find(
(m: Media) => m.type === 'poster' && m.is_selected
);
if (selectedPoster?.path) {
return getMediaUrl('collections', 'posters', 'preview', selectedPoster.path);
}
}
if (collection.poster_path) {
return getTmdbImageUrl(collection.poster_path, 'w342');
}
return DEFAULT_POSTER;
}
export function getProfileUrl(profilePath: string | null): string {
if (!profilePath) return '/images/default-profile.png';
return getTmdbImageUrl(profilePath, 'w185');
}
export function formatRuntime(minutes: number | null): string {
if (!minutes) return '';
const h = Math.floor(minutes / 60);
const m = minutes % 60;
return h > 0 ? `${h}h ${m}m` : `${m}m`;
}
export function formatDate(dateStr: string | null): string {
if (!dateStr) return '';
return new Date(dateStr).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
});
}
export function getYear(dateStr: string | null): string {
if (!dateStr) return '';
return new Date(dateStr).getFullYear().toString();
}