Files
movie-advisor/data/dto/Availability.ts
T
nerandClaude Opus 5 3dc2ebfe53 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>
2026-08-04 22:09:33 +03:00

41 lines
1.4 KiB
TypeScript

const STATE_BY_RELEASE_TYPE: Record<number, AvailabilityState> = {
1: 'theatre',
2: 'theatre',
3: 'theatre',
4: 'stream',
5: 'bluray'
};
const THEATRICAL_WINDOW = 120 * 24 * 60 * 60 * 1000;
export const mapReleaseDatesToAvailability = (results?: TMDBCountryReleaseDates[]): Availability | undefined => {
const availability = (results || []).reduce<Availability>((dates, { release_dates }) => {
(release_dates || []).forEach(({ type, release_date }) => {
const state = STATE_BY_RELEASE_TYPE[type];
const earliest = state && dates[state];
if (!state || !release_date) return;
if (!earliest || release_date < earliest) dates[state] = release_date;
});
return dates;
}, {});
return Object.keys(availability).length ? availability : undefined;
};
export const isUpcoming = (date?: string) => Boolean(date && Date.parse(date) > Date.now());
const isReleased = (date?: string) => Boolean(date && Date.parse(date) <= Date.now());
export const getAvailabilityState = ({ theatre, stream, bluray }: Availability): AvailabilityState | undefined => {
if (isReleased(bluray)) return 'bluray';
if (isReleased(stream)) return 'stream';
if (isUpcoming(theatre)) return 'theatre';
if (!theatre) return undefined;
const isRunning = Date.now() - Date.parse(theatre) < THEATRICAL_WINDOW;
return isRunning || isUpcoming(stream) || isUpcoming(bluray) ? 'theatre' : 'stream';
};