fix: surface search failures
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
|||||||
setClearButtonState,
|
setClearButtonState,
|
||||||
clearResults,
|
clearResults,
|
||||||
renderEmptyState,
|
renderEmptyState,
|
||||||
|
renderSearchErrorState,
|
||||||
renderItems,
|
renderItems,
|
||||||
appendItems,
|
appendItems,
|
||||||
} from "./render";
|
} from "./render";
|
||||||
@@ -117,14 +118,13 @@ export const fetchSearchItems = (query: string): void => {
|
|||||||
responseCache.set(query, response);
|
responseCache.set(query, response);
|
||||||
renderItems(visibleItems);
|
renderItems(visibleItems);
|
||||||
})
|
})
|
||||||
.catch((err: unknown) => {
|
.catch(() => {
|
||||||
if (controller.signal.aborted) {
|
if (controller.signal.aborted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setActiveRequestController(undefined);
|
setActiveRequestController(undefined);
|
||||||
console.error("Search overlay error:", err);
|
renderSearchErrorState(query);
|
||||||
renderItems([]);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -168,8 +168,8 @@ export const fetchNextSearchPage = (): void => {
|
|||||||
setSearchPagination(response.nextPage, response.hasNextPage);
|
setSearchPagination(response.nextPage, response.hasNextPage);
|
||||||
appendItems(visibleItems);
|
appendItems(visibleItems);
|
||||||
})
|
})
|
||||||
.catch((err: unknown) => {
|
.catch(() => {
|
||||||
console.error("Search overlay pagination error:", err);
|
window.showToast?.({ message: "Failed to load more search results." });
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setFetchingNextPage(false);
|
setFetchingNextPage(false);
|
||||||
|
|||||||
@@ -160,8 +160,8 @@ export const removeContinueWatchingItem = (item: CommandPaletteItem): void => {
|
|||||||
removeContinueWatchingCard(animeID);
|
removeContinueWatchingCard(animeID);
|
||||||
renderItems(getResultItems().filter((candidate) => candidate.id !== item.id));
|
renderItems(getResultItems().filter((candidate) => candidate.id !== item.id));
|
||||||
})
|
})
|
||||||
.catch((err: unknown) => {
|
.catch(() => {
|
||||||
console.error("Continue watching remove error:", err);
|
window.showToast?.({ message: "Failed to remove from Continue Watching." });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -316,6 +316,30 @@ export const renderEmptyState = (query: string): void => {
|
|||||||
searchResults.replaceChildren(empty);
|
searchResults.replaceChildren(empty);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const renderSearchErrorState = (query: string): void => {
|
||||||
|
if (!searchResults) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const empty = document.createElement("div");
|
||||||
|
empty.className =
|
||||||
|
"mx-auto flex min-h-80 w-full max-w-5xl flex-col justify-center px-5 py-14 text-center md:px-8";
|
||||||
|
|
||||||
|
const title = document.createElement("div");
|
||||||
|
title.className = "text-2xl font-semibold text-foreground";
|
||||||
|
title.textContent = "Search is unavailable right now";
|
||||||
|
empty.appendChild(title);
|
||||||
|
|
||||||
|
const subtitle = document.createElement("p");
|
||||||
|
subtitle.className = "mx-auto mt-3 max-w-lg text-sm leading-6 text-foreground-muted";
|
||||||
|
subtitle.textContent = query
|
||||||
|
? "Try again in a moment or narrow the search query."
|
||||||
|
: "Try again in a moment.";
|
||||||
|
empty.appendChild(subtitle);
|
||||||
|
|
||||||
|
searchResults.replaceChildren(empty);
|
||||||
|
};
|
||||||
|
|
||||||
const groupedItems = (items: CommandPaletteItem[]): Map<string, CommandPaletteItem[]> => {
|
const groupedItems = (items: CommandPaletteItem[]): Map<string, CommandPaletteItem[]> => {
|
||||||
const groups = new Map<string, CommandPaletteItem[]>();
|
const groups = new Map<string, CommandPaletteItem[]>();
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user