Implemented the new react version of the frontend

This commit is contained in:
Mohammed Abad committed 2026-03-31 01:56:38 +01:00
1 parent 236e6e06fb
commit ffe7e52527
65 files changed
+5228 -177

No files matched your search

+104
View File
@@ -0,0 +1,104 @@
/**
* Normalizers to transform backend Sequelize JSON responses
* into the shape our frontend TypeScript types expect.
*
* Backend quirks:
* - Entry relations use singular aliases: entryId, entryRating, entrySeen
* - Media model uses camelCase: isSelected, isLocal, isCustom, isFavorit, mediaableId
* - Collection model uses camelCase: isUserCollection, userRating, posterPath, backdropPath, isLocal, tmdbId
* - Credit → People alias is "person" (singular)
* - Genres come as string arrays from the backend mapper
*/
import type { Entry, Collection, Media, Credit, Genre } from '@/types';
/* ---------- Media ---------- */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function normalizeMedia(raw: any): Media {
return {
id: raw.id,
mediaable: raw.mediaable,
mediaable_id: raw.mediaableId ?? raw.mediaable_id,
type: raw.type,
path: raw.path,
is_local: raw.isLocal ?? raw.is_local ?? false,
is_selected: raw.isSelected ?? raw.is_selected ?? false,
is_custom: raw.isCustom ?? raw.is_custom ?? false,
is_favorit: raw.isFavorit ?? raw.is_favorit ?? false,
};
}
/* ---------- Credit ---------- */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function normalizeCredit(raw: any): Credit {
const people = raw.person ?? raw.people ?? undefined;
return {
id: raw.id,
entry_id: raw.entry_id,
people_id: raw.people_id,
character: raw.character,
cast_type: raw.cast_type,
department: raw.department,
job: raw.job,
order: raw.order,
people: people,
};
}
/* ---------- Genre ---------- */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function normalizeGenres(raw: any[]): Genre[] {
if (!Array.isArray(raw)) return [];
return raw.map((g, i) => {
if (typeof g === 'string') return { id: i, name: g };
return g as Genre;
});
}
/* ---------- Entry ---------- */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function normalizeEntry(raw: any): Entry {
return {
...raw,
// Singular → plural aliases (coerce tmdb_id to number for store comparisons)
entryIds: (() => {
const ids = raw.entryIds ?? raw.entryId;
if (!ids) return undefined;
return {
...ids,
tmdb_id: ids.tmdb_id != null ? Number(ids.tmdb_id) : null,
};
})(),
entryRatings: raw.entryRatings ?? raw.entryRating ?? undefined,
entrySeens: raw.entrySeens ?? raw.entrySeen ?? undefined,
// Normalize nested arrays
medias: raw.medias ? raw.medias.map(normalizeMedia) : undefined,
genres: raw.genres ? normalizeGenres(raw.genres) : undefined,
credits: raw.credits ? raw.credits.map(normalizeCredit) : undefined,
collections: raw.collections
? raw.collections.map(normalizeCollection)
: undefined,
// Mark as in library when loaded from the library endpoint
isInLibrary: raw.isInLibrary ?? true,
};
}
/* ---------- Collection ---------- */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function normalizeCollection(raw: any): Collection {
return {
id: raw.id,
tmdb_id: raw.tmdbId ?? raw.tmdb_id ?? null,
name: raw.name,
description: raw.description ?? raw.overview ?? null,
user_rating: raw.userRating ?? raw.user_rating ?? null,
poster_path: raw.posterPath ?? raw.poster_path ?? null,
backdrop_path: raw.backdropPath ?? raw.backdrop_path ?? null,
is_local: raw.isLocal ?? raw.is_local ?? false,
is_user_collection: raw.isUserCollection ?? raw.is_user_collection ?? false,
createdAt: raw.createdAt,
updatedAt: raw.updatedAt,
entries: raw.entries ? raw.entries.map(normalizeEntry) : undefined,
medias: raw.medias ? raw.medias.map(normalizeMedia) : undefined,
};
}