mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-02-10 22:32:22 +00:00
refactor(item): improves top people display logic
Improves the logic for displaying the top people in the item sections. The previous implementation simply sliced the people array which could result in duplicate people being displayed. This change ensures that the top people displayed are unique by filtering duplicates based on their id, limiting the number of displayed people to three.
This commit is contained in:
@@ -37,7 +37,18 @@ export const ItemPeopleSections: React.FC<Props> = ({ item, ...props }) => {
|
||||
return { ...item, People: people } as BaseItemDto;
|
||||
}, [item, people]);
|
||||
|
||||
const topPeople = useMemo(() => people.slice(0, 3), [people]);
|
||||
const topPeople = useMemo(() => {
|
||||
const seen = new Set<string>();
|
||||
const unique: BaseItemPerson[] = [];
|
||||
for (const person of people) {
|
||||
if (person.Id && !seen.has(person.Id)) {
|
||||
seen.add(person.Id);
|
||||
unique.push(person);
|
||||
}
|
||||
if (unique.length >= 3) break;
|
||||
}
|
||||
return unique;
|
||||
}, [people]);
|
||||
|
||||
const renderActorSection = useCallback(
|
||||
(person: BaseItemPerson, idx: number, total: number) => {
|
||||
|
||||
Reference in New Issue
Block a user