From f3ebc21b97aa07b824caae12a0456340900937fe Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Sun, 17 Oct 2021 07:08:17 -0700 Subject: [PATCH] Fixed a bug where searching on localized name would fail to show on the search. Fixed a bug where extra spaces would cause the search results not to show properly. (#682) --- API/Controllers/LibraryController.cs | 2 +- UI/Web/src/app/_models/search-result.ts | 2 +- UI/Web/src/app/nav-header/nav-header.component.html | 3 ++- UI/Web/src/app/nav-header/nav-header.component.ts | 11 +++++++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/API/Controllers/LibraryController.cs b/API/Controllers/LibraryController.cs index 07a4a3f97..15a8d1166 100644 --- a/API/Controllers/LibraryController.cs +++ b/API/Controllers/LibraryController.cs @@ -226,7 +226,7 @@ namespace API.Controllers [HttpGet("search")] public async Task>> Search(string queryString) { - queryString = queryString.Trim().Replace(@"%", ""); + queryString = Uri.UnescapeDataString(queryString).Trim().Replace(@"%", string.Empty); var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername()); // Get libraries user has access to diff --git a/UI/Web/src/app/_models/search-result.ts b/UI/Web/src/app/_models/search-result.ts index 96619cc0f..3026c96c3 100644 --- a/UI/Web/src/app/_models/search-result.ts +++ b/UI/Web/src/app/_models/search-result.ts @@ -6,7 +6,7 @@ export interface SearchResult { libraryName: string; name: string; originalName: string; + localizedName: string; sortName: string; - coverImage: string; // byte64 encoded (not used) format: MangaFormat; } diff --git a/UI/Web/src/app/nav-header/nav-header.component.html b/UI/Web/src/app/nav-header/nav-header.component.html index 87bc92ec5..b96bd73f6 100644 --- a/UI/Web/src/app/nav-header/nav-header.component.html +++ b/UI/Web/src/app/nav-header/nav-header.component.html @@ -23,6 +23,7 @@ (selected)='clickSearchResult($event)' (inputChanged)='onChangeSearch($event)' [isLoading]="isLoading" + [customFilter]="customFilter" [debounceTime]="debounceTime" [itemTemplate]="itemTemplate" [notFoundTemplate]="notFoundTemplate"> @@ -35,7 +36,7 @@
- + diff --git a/UI/Web/src/app/nav-header/nav-header.component.ts b/UI/Web/src/app/nav-header/nav-header.component.ts index d9005bc10..b2f7896e1 100644 --- a/UI/Web/src/app/nav-header/nav-header.component.ts +++ b/UI/Web/src/app/nav-header/nav-header.component.ts @@ -3,6 +3,7 @@ import { Component, HostListener, Inject, OnDestroy, OnInit, ViewChild } from '@ import { Router } from '@angular/router'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; +import { isTemplateSpan } from 'typescript'; import { ScrollService } from '../scroll.service'; import { SearchResult } from '../_models/search-result'; import { AccountService } from '../_services/account.service'; @@ -24,6 +25,16 @@ export class NavHeaderComponent implements OnInit, OnDestroy { imageStyles = {width: '24px', 'margin-top': '5px'}; searchResults: SearchResult[] = []; searchTerm = ''; + customFilter: (items: SearchResult[], query: string) => SearchResult[] = (items: SearchResult[], query: string) => { + const normalizedQuery = query.trim().toLowerCase(); + const matches = items.filter(item => { + const normalizedSeriesName = item.name.toLowerCase().trim(); + const normalizedOriginalName = item.originalName.toLowerCase().trim(); + const normalizedLocalizedName = item.localizedName.toLowerCase().trim(); + return normalizedSeriesName.indexOf(normalizedQuery) >= 0 || normalizedOriginalName.indexOf(normalizedQuery) >= 0 || normalizedLocalizedName.indexOf(normalizedQuery) >= 0; + }); + return matches; + }; backToTopNeeded = false;