This commit is contained in:
@@ -245,18 +245,34 @@ export const categories = action({
|
||||
return { categories: [] };
|
||||
}
|
||||
|
||||
// Klipy's actual shape (verified against /api/v1/.../gifs/categories):
|
||||
// { result: true, data: { locale: "en_US", categories: [
|
||||
// { category: "hello", query: "hello", preview_url: "..." },
|
||||
// ...
|
||||
// ]}}
|
||||
// Older / parallel paths (data.data[] from the search+trending
|
||||
// endpoints, or a flat data[] array) are accepted as fallbacks so
|
||||
// a future upstream change doesn't silently break the picker.
|
||||
const json = (await response.json()) as any;
|
||||
const items: any[] = Array.isArray(json?.data?.data)
|
||||
? json.data.data
|
||||
: Array.isArray(json?.data)
|
||||
? json.data
|
||||
: [];
|
||||
const items: any[] = Array.isArray(json?.data?.categories)
|
||||
? json.data.categories
|
||||
: Array.isArray(json?.data?.data)
|
||||
? json.data.data
|
||||
: Array.isArray(json?.data)
|
||||
? json.data
|
||||
: [];
|
||||
|
||||
const categories: NormalizedCategory[] = items
|
||||
.map((item) => ({
|
||||
name: String(item?.name ?? item?.title ?? ""),
|
||||
image: String(item?.image ?? item?.preview ?? ""),
|
||||
query: String(item?.query ?? item?.search_term ?? item?.name ?? ""),
|
||||
name: String(
|
||||
item?.category ?? item?.name ?? item?.title ?? item?.query ?? "",
|
||||
),
|
||||
image: String(
|
||||
item?.preview_url ?? item?.image ?? item?.preview ?? "",
|
||||
),
|
||||
query: String(
|
||||
item?.query ?? item?.search_term ?? item?.category ?? item?.name ?? "",
|
||||
),
|
||||
}))
|
||||
.filter((c) => !!c.query);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user