search
This commit is contained in:
50
utils/searchMapping.ts
Normal file
50
utils/searchMapping.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { AutoCompleteItem } from "@/apis/autoCompleteApi";
|
||||
|
||||
export const getIconName = (type: AutoCompleteItem["type"]) => {
|
||||
switch (type) {
|
||||
case "PERSON":
|
||||
return "user";
|
||||
case "SHOW":
|
||||
return "television";
|
||||
case "YEAR":
|
||||
case "CUSTOM":
|
||||
return "calendar";
|
||||
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,
|
||||
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) {
|
||||
return {
|
||||
showId: data?.showId ?? data?.id,
|
||||
title: data?.title ?? data?.name ?? `Show #${data?.showId ?? data?.id ?? "?"}`,
|
||||
description: data?.description ?? "",
|
||||
genre: data?.genre ?? "",
|
||||
thumbnailUrl: data?.thumbnailUrl ?? data?.imageUrl ?? "",
|
||||
running: data?.running ?? false,
|
||||
} as any;
|
||||
}
|
||||
Reference in New Issue
Block a user