fix: surface search failures
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
setClearButtonState,
|
||||
clearResults,
|
||||
renderEmptyState,
|
||||
renderSearchErrorState,
|
||||
renderItems,
|
||||
appendItems,
|
||||
} from "./render";
|
||||
@@ -117,14 +118,13 @@ export const fetchSearchItems = (query: string): void => {
|
||||
responseCache.set(query, response);
|
||||
renderItems(visibleItems);
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
.catch(() => {
|
||||
if (controller.signal.aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setActiveRequestController(undefined);
|
||||
console.error("Search overlay error:", err);
|
||||
renderItems([]);
|
||||
renderSearchErrorState(query);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -168,8 +168,8 @@ export const fetchNextSearchPage = (): void => {
|
||||
setSearchPagination(response.nextPage, response.hasNextPage);
|
||||
appendItems(visibleItems);
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
console.error("Search overlay pagination error:", err);
|
||||
.catch(() => {
|
||||
window.showToast?.({ message: "Failed to load more search results." });
|
||||
})
|
||||
.finally(() => {
|
||||
setFetchingNextPage(false);
|
||||
|
||||
@@ -160,8 +160,8 @@ export const removeContinueWatchingItem = (item: CommandPaletteItem): void => {
|
||||
removeContinueWatchingCard(animeID);
|
||||
renderItems(getResultItems().filter((candidate) => candidate.id !== item.id));
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
console.error("Continue watching remove error:", err);
|
||||
.catch(() => {
|
||||
window.showToast?.({ message: "Failed to remove from Continue Watching." });
|
||||
});
|
||||
};
|
||||
|
||||
@@ -316,6 +316,30 @@ export const renderEmptyState = (query: string): void => {
|
||||
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 groups = new Map<string, CommandPaletteItem[]>();
|
||||
items.forEach((item) => {
|
||||
|
||||
Reference in New Issue
Block a user