diff options
author | Anderson Shindy Oki <[email protected]> | 2024-09-25 11:20:30 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2024-09-25 11:20:30 +0900 |
commit | dd92f408b968dd7d241e262be78d5a4a84300bfc (patch) | |
tree | 640055c6fe36272b1ee44ecd19b1bd2ca7d17fb3 /frontend | |
parent | 5e08898de82d62ecaf782aa1bb2032ff6304841d (diff) | |
download | bazarr-dd92f408b968dd7d241e262be78d5a4a84300bfc.tar.gz bazarr-dd92f408b968dd7d241e262be78d5a4a84300bfc.zip |
Fixed duplicated search result name for series and movies (#2682)
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/src/components/Search.tsx | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/frontend/src/components/Search.tsx b/frontend/src/components/Search.tsx index b506afee3..c0dde3bef 100644 --- a/frontend/src/components/Search.tsx +++ b/frontend/src/components/Search.tsx @@ -3,6 +3,7 @@ import { useNavigate } from "react-router-dom"; import { Autocomplete, ComboboxItem, OptionsFilter, Text } from "@mantine/core"; import { faSearch } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { chain, includes } from "lodash"; import { useServerSearch } from "@/apis/hooks"; import { useDebouncedValue } from "@/utilities"; @@ -15,23 +16,45 @@ function useSearch(query: string) { const debouncedQuery = useDebouncedValue(query, 500); const { data } = useServerSearch(debouncedQuery, debouncedQuery.length >= 0); + const duplicates = chain(data) + .groupBy((item) => `${item.title} (${item.year})`) + .filter((group) => group.length > 1) + .map((group) => `${group[0].title} (${group[0].year})`) + .value(); + return useMemo<SearchResultItem[]>( () => data?.map((v) => { - let link: string; - if (v.sonarrSeriesId) { - link = `/series/${v.sonarrSeriesId}`; - } else if (v.radarrId) { - link = `/movies/${v.radarrId}`; - } else { + const { link, displayName } = (() => { + const hasDuplicate = includes(duplicates, `${v.title} (${v.year})`); + + if (v.sonarrSeriesId) { + return { + link: `/series/${v.sonarrSeriesId}`, + displayName: hasDuplicate + ? `${v.title} (${v.year}) (S)` + : `${v.title} (${v.year})`, + }; + } + + if (v.radarrId) { + return { + link: `/movies/${v.radarrId}`, + displayName: hasDuplicate + ? `${v.title} (${v.year}) (M)` + : `${v.title} (${v.year})`, + }; + } + throw new Error("Unknown search result"); - } + })(); + return { - value: `${v.title} (${v.year})`, + value: displayName, link, }; }) ?? [], - [data], + [data, duplicates], ); } |