Implemented the new react version of the frontend
This commit is contained in:
1 parent
236e6e06fb
commit
ffe7e52527
65 files changed
+5228
-177
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import axios from 'axios';
|
||||
|
||||
// const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:4000/api/v1';
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL || '/api/v1';
|
||||
|
||||
export const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
export const getMediaUrl = (
|
||||
category: string,
|
||||
type: string,
|
||||
size: 'preview' | 'full',
|
||||
file: string
|
||||
) => `${API_BASE_URL}/media/${category}/${type}/${size}/${file}`;
|
||||
|
||||
export const getTmdbImageUrl = (path: string, size = 'w342') =>
|
||||
`https://image.tmdb.org/t/p/${size}${path}`;
|
||||
@@ -0,0 +1,103 @@
|
||||
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 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();
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
Reference in new issue
Block a user