Skip to content

Commit

Permalink
fix: use optional chaining If the author name is not in the data
Browse files Browse the repository at this point in the history
  • Loading branch information
anpigon committed Aug 14, 2022
1 parent 5b5fa7d commit 8ed5b0a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/book_suggest_modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export class BookSuggestModal extends SuggestModal<Book> {
// Returns all available suggestions.
getSuggestions(query: string): Book[] {
return this.suggestion.filter(book => {
const searchQuery = query.toLowerCase();
const searchQuery = query?.toLowerCase();
return (
book.title.toLowerCase().includes(searchQuery) ||
book.author.toLowerCase().includes(searchQuery) ||
book.publisher.toLowerCase().includes(searchQuery)
book.title?.toLowerCase().includes(searchQuery) ||
book.author?.toLowerCase().includes(searchQuery) ||
book.publisher?.toLowerCase().includes(searchQuery)
);
});
}
Expand Down

0 comments on commit 8ed5b0a

Please sign in to comment.