diff --git a/src/App.tsx b/src/App.tsx index 24ce632278653305d1de2f750378cc1c6770d12c..1859c58608d6ea86059c8b7d9962b6c489885bc7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,6 +4,7 @@ import {useApiClient} from "./api/ApiClientContext"; import {Title} from "./api/models/Title"; import {Locale, LocalePriority, selectLocaleVersion} from "./locale/selectLocaleData"; import {usePlayabilityRating} from "./mime/usePlayabilityRating"; +import {sortLexicallyAsc} from "./util/sortLexically"; import {sortNumericallyDesc} from "./util/sortNumerically"; export default function App() { @@ -14,7 +15,7 @@ export default function App() { apiClient.listTitles().then(setData); }, [apiClient]); const locale: Locale = { - language: "de", + language: "en", region: "DE", }; @@ -22,9 +23,12 @@ export default function App() { return ( <div> - {data?.map((item: Title) => { + {data?.sort(sortLexicallyAsc(item => + selectLocaleVersion(locale, LocalePriority.REGION_BEFORE_LOCALE, item.titles)?.name || "")) + .map((item: Title) => { const title = selectLocaleVersion(locale, LocalePriority.REGION_BEFORE_LOCALE, item.titles); const description = selectLocaleVersion(locale, LocalePriority.LOCALE_BEFORE_REGION, item.descriptions); + const rating = selectLocaleVersion(locale, LocalePriority.REGION_ONLY, item.ratings); const poster = item.images.find(it => it.kind === "poster"); const backdrop = item.images.find(it => it.kind === "backdrop"); const mediaList = item.media.map(it => { @@ -38,8 +42,9 @@ export default function App() { return ( <div key={item.ids.uuid} className={classes.movie}> <h1>{title?.name}</h1> - <strong>{description?.tagline}</strong> + <p><strong>{description?.tagline}</strong></p> <p>{description?.overview}</p> + <p><strong>{rating?.certification}</strong></p> {poster && ( <img className={classes.poster} diff --git a/src/api/models/LocalizedData.ts b/src/api/models/LocalizedData.ts index 992a91e5ac62d417c16c6904c42d82d0def00dbc..71b27d2d971e3693b7e73bd530fcea00e7fdef32 100644 --- a/src/api/models/LocalizedData.ts +++ b/src/api/models/LocalizedData.ts @@ -1,5 +1,5 @@ export interface LocalizedData { region: string | null, - languages: string[], - kind: string, + languages?: string[], + kind?: string, } diff --git a/src/api/models/Rating.ts b/src/api/models/Rating.ts index 6cef8e954a9eeaa140fc1beb74ddc0996f82153c..e4b85e7e189fa7b31ba7e538f6bac6a23298c944 100644 --- a/src/api/models/Rating.ts +++ b/src/api/models/Rating.ts @@ -1,4 +1,6 @@ -export interface Rating { +import {LocalizedData} from "./LocalizedData"; + +export interface Rating extends LocalizedData { region: string | null, certification: string } diff --git a/src/api/models/TitleDescription.ts b/src/api/models/TitleDescription.ts index 980640da329fd2f8219b61d5d66884dd11dd0ea9..cc2b03a7f56d1aded258a58d45753e0eb35ca024 100644 --- a/src/api/models/TitleDescription.ts +++ b/src/api/models/TitleDescription.ts @@ -2,5 +2,7 @@ import {LocalizedData} from "./LocalizedData"; export interface TitleDescription extends LocalizedData { overview: string, - tagline: string | null + tagline: string | null, + languages: string[], + kind: string } diff --git a/src/api/models/TitleName.ts b/src/api/models/TitleName.ts index 914d7a42ad8b84db4700cbff1bf2fe8999450d19..b21be8e8e09d1a5534f0c21b67302fb68f4c8ba5 100644 --- a/src/api/models/TitleName.ts +++ b/src/api/models/TitleName.ts @@ -1,5 +1,7 @@ import {LocalizedData} from "./LocalizedData"; export interface TitleName extends LocalizedData { - name: string + name: string, + languages: string[], + kind: string } diff --git a/src/locale/selectLocaleData.ts b/src/locale/selectLocaleData.ts index b37640148c0c9e8ef116a7f71f816a7f22275884..f2d49a448f3788f84bcb8e0087ef6d0c837e69ed 100644 --- a/src/locale/selectLocaleData.ts +++ b/src/locale/selectLocaleData.ts @@ -11,24 +11,36 @@ export enum LocalePriority { LOCALE_BEFORE_REGION } -function filterVersions<T extends LocalizedData>(locale: Locale, method: LocalePriority, data: T[]): T | undefined { +function filterVersions<T extends LocalizedData>( + locale: Locale, + method: LocalePriority, + data: T[] +): T | undefined { switch (method) { case LocalePriority.REGION_ONLY: return data.find((el) => { return (el.region === locale.region); }); case LocalePriority.REGION_BEFORE_LOCALE: - return data.sort((a, b) => (+b.languages.includes(locale.language)) - (+a.languages.includes(locale.language))) - .find((el) => el.region === locale.region); + return data.sort((a, b) => + +(b.languages?.includes(locale.language) || false) - + +(a.languages?.includes(locale.language) || false) + ).find((el) => el.region === locale.region); case LocalePriority.LOCALE_BEFORE_REGION: - return data.sort((a, b) => (+(b.region === locale.region)) - (+(a.region === locale.region))) - .find((el) => el.languages.includes(locale.language)); + return data.sort((a, b) => + +(b.region === locale.region) - + +(a.region === locale.region) + ).find((el) => el.languages?.includes(locale.language)); } } -export function selectLocaleVersion<T extends LocalizedData>(locale: Locale, method: LocalePriority, data: T[]): T | null { - return filterVersions(locale, method, data.filter(it => it.kind === "localized")) +export function selectLocaleVersion<T extends LocalizedData>( + locale: Locale, + method: LocalePriority, + data: T[] +): T | null { + return filterVersions(locale, method, data.filter(it => it?.kind === undefined || it?.kind === "localized")) || data.find(it => it.kind === "primary") || data.find(it => it.kind === "original") || null;