Skip to content

Commit 801153d

Browse files
committed
fix: FilteredAuthors 3중 map 구조 개선
1 parent 86445b7 commit 801153d

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

packages/view/src/components/FilteredAuthors/FilteredAuthors.tsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,23 @@ const FilteredAuthors = () => {
1010
const authSrcMap = usePreLoadAuthorImg();
1111
const selectedClusters = getInitData(selectedData);
1212

13-
// 이미 선택된 사용자를 관리
14-
const addedAuthors = new Set();
13+
// 2차원 authorNames를 평탄화하고 중복 제거
14+
const uniqueAuthorNames = Array.from(
15+
new Set(selectedClusters.flatMap((cluster) => cluster.summary.authorNames.flat()))
16+
);
1517

1618
return (
1719
<div className="filtered-authors">
1820
<p className="filtered-authors__label">Authors:</p>
1921
<div className="filtered-authors__author">
2022
{authSrcMap &&
21-
selectedClusters.map((selectedCluster) => {
22-
return selectedCluster.summary.authorNames.map((authorArray: string[]) => {
23-
return authorArray.map((authorName: string) => {
24-
// 이미 추가된 사용자인지 확인 후 추가되지 않은 경우에만 추가하고 Set에 이름을 저장
25-
if (!addedAuthors.has(authorName)) {
26-
addedAuthors.add(authorName);
27-
return (
28-
<Author
29-
key={authorName}
30-
name={authorName}
31-
src={authSrcMap[authorName]}
32-
/>
33-
);
34-
}
35-
// 이미 추가된 사용자인 경우 null 반환
36-
return null;
37-
});
38-
});
39-
})}
23+
uniqueAuthorNames.map((authorName) => (
24+
<Author
25+
key={authorName}
26+
name={authorName}
27+
src={authSrcMap[authorName]}
28+
/>
29+
))}
4030
</div>
4131
</div>
4232
);

0 commit comments

Comments
 (0)