Skip to content

Commit d02f41e

Browse files
committed
fix(quote search): uncaught errors when closing modal right after search input
!nuf
1 parent 5ba39c6 commit d02f41e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

frontend/src/ts/modals/quote-search.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function highlightMatches(text: string, matchedText: string[]): string {
6262
}
6363

6464
function applyQuoteLengthFilter(quotes: Quote[]): Quote[] {
65+
if (!modal.isOpen()) return [];
6566
const quoteLengthFilterValue = $(
6667
"#quoteSearchModal .quoteLengthFilter"
6768
).val() as string[];
@@ -80,6 +81,7 @@ function applyQuoteLengthFilter(quotes: Quote[]): Quote[] {
8081
}
8182

8283
function applyQuoteFavFilter(quotes: Quote[]): Quote[] {
84+
if (!modal.isOpen()) return [];
8385
const showFavOnly = (
8486
document.querySelector(".toggleFavorites") as HTMLDivElement
8587
).classList.contains("active");
@@ -154,6 +156,8 @@ function buildQuoteSearchResult(
154156
}
155157

156158
async function updateResults(searchText: string): Promise<void> {
159+
if (!modal.isOpen()) return;
160+
157161
const { quotes } = await QuotesController.getQuotes(Config.language);
158162

159163
const quoteSearchService = getSearchService<Quote>(
@@ -334,6 +338,7 @@ function apply(val: number): void {
334338
}
335339

336340
const searchForQuotes = debounce(250, (): void => {
341+
if (!modal.isOpen()) return;
337342
const searchText = (document.getElementById("searchBox") as HTMLInputElement)
338343
.value;
339344
currentPageNumber = 1;

0 commit comments

Comments
 (0)