60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { AutoCompleteItem } from "@/apis/autoCompleteApi";
|
|
|
|
export const getIconName = (type: AutoCompleteItem["type"]) => {
|
|
switch (type) {
|
|
case "PERSON":
|
|
return "user";
|
|
case "SHOW":
|
|
return "television";
|
|
case "YEAR":
|
|
return "calendar";
|
|
case "CUSTOM":
|
|
return "tag";
|
|
default:
|
|
return "tag";
|
|
}
|
|
};
|
|
|
|
// Helpers that adapt backend searchApi payloads (as in the prompt) to UI types used in our components
|
|
export function mapApiPersonToUI(data: any) {
|
|
return {
|
|
id: data?.id ?? data?.personId,
|
|
personId: data?.personId ?? data?.id,
|
|
name: data?.name ?? "",
|
|
birthDate: data?.birthDate ?? null,
|
|
imageUrl: data?.imageUrl ?? null,
|
|
};
|
|
}
|
|
|
|
export function mapApiSeasonToUI(data: any) {
|
|
return {
|
|
seasonId: data?.seasonId ?? data?.id,
|
|
showId: data?.showId ?? data?.show,
|
|
startDate: data?.startDate ?? null,
|
|
endDate: data?.endDate ?? null,
|
|
seasonNumber: data?.seasonNumber ?? null,
|
|
participants: data?.seasonParticipants ?? data?.participants ?? [],
|
|
moderators: data?.moderators ?? [],
|
|
teams: data?.teams ?? [],
|
|
} as any;
|
|
}
|
|
|
|
export function mapApiShowToUI(data: any) {
|
|
const id = data?.showId ?? data?.id;
|
|
const genre = data?.genre ?? "";
|
|
return {
|
|
id,
|
|
showId: id,
|
|
title: data?.title ?? data?.name ?? `Show #${id ?? "?"}`,
|
|
description: data?.description ?? "",
|
|
genres: genre ? genre.split(",").map((g: string) => g.trim()) : [],
|
|
genre,
|
|
thumbnailUri: data?.thumbnailUrl ?? data?.imageUrl ?? "",
|
|
bannerUri: data?.bannerUrl ?? "",
|
|
streamingService: data?.streamingServices ?? "",
|
|
concept: data?.concept ?? "",
|
|
running: data?.running ?? false,
|
|
logoUrl: data?.logoUrl ?? "",
|
|
} as any;
|
|
}
|