Fixed duplicated search result name for series and movies (#2682)

pull/2683/head
Anderson Shindy Oki 2 months ago committed by GitHub
parent 5e08898de8
commit dd92f408b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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;
const { link, displayName } = (() => {
const hasDuplicate = includes(duplicates, `${v.title} (${v.year})`);
if (v.sonarrSeriesId) {
link = `/series/${v.sonarrSeriesId}`;
} else if (v.radarrId) {
link = `/movies/${v.radarrId}`;
} else {
throw new Error("Unknown search result");
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],
);
}

Loading…
Cancel
Save