Skip to content

Commit 602646e

Browse files
committed
feat: search sub-comments
1 parent f16de85 commit 602646e

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/App.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ export default function App() {
2424
// `e.currentTarget` will be null after `await`
2525
const keyword = e.currentTarget.value
2626
const allComments = await promise!
27-
const comments = allComments.filter((comment) =>
28-
comment.content.message.includes(keyword)
29-
)
27+
const comments = searchComments(allComments, keyword)
3028
setComments(comments)
3129
}
3230
}}
@@ -49,7 +47,7 @@ export default function App() {
4947
}
5048

5149
interface CommentProps {
52-
comments?: Reply[]
50+
comments?: Reply[] | null
5351
sub?: boolean
5452
}
5553
const CommentTree: React.FC<CommentProps> = ({ comments, sub = false }) => {
@@ -97,3 +95,12 @@ const CommentTree: React.FC<CommentProps> = ({ comments, sub = false }) => {
9795
</ul>
9896
)
9997
}
98+
99+
function searchComments(allComments: Reply[], keyword: string) {
100+
return allComments.filter((comment) => {
101+
return (
102+
comment.content.message.includes(keyword) ||
103+
comment.replies?.some((reply) => reply.content.message.includes(keyword))
104+
)
105+
})
106+
}

src/reply.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface Reply {
1919
action: number
2020
member: Member
2121
content: Content
22-
replies: Reply[]
22+
replies: Reply[] | null
2323
assist: number
2424
up_action: UpAction
2525
invisible: boolean

0 commit comments

Comments
 (0)