Skip to content

Commit ed30051

Browse files
committed
Refactor comment and reply event handling
Fixes #54
1 parent b3fc26a commit ed30051

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

packages/comment-widget/src/comment-form.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,7 @@ export class CommentForm extends LitElement {
140140
);
141141
}
142142

143-
window.dispatchEvent(
144-
new CustomEvent('comment:reload', {
145-
detail: {
146-
page: 1,
147-
scrollIntoView: true,
148-
},
149-
})
150-
);
143+
window.dispatchEvent(new CustomEvent('halo:comment:created'));
151144

152145
this.baseFormRef.value?.resetForm();
153146
} catch (error) {

packages/comment-widget/src/comment-list.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,12 @@ export class CommentList extends LitElement {
8585
super.connectedCallback();
8686
this.fetchComments();
8787

88-
// Handle comment:reload event
89-
window.addEventListener('comment:reload', (e: Event) => {
90-
if (e instanceof CustomEvent) {
91-
const data = e.detail;
92-
this.fetchComments({
93-
page: data.page,
94-
scrollIntoView: data.scrollIntoView,
95-
});
96-
}
88+
// Handle halo:comment:created event, then reload the comment list
89+
window.addEventListener('halo:comment:created', () => {
90+
this.fetchComments({
91+
page: 1,
92+
scrollIntoView: true,
93+
});
9794
});
9895
}
9996

packages/comment-widget/src/comment-replies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class CommentReplies extends LitElement {
5757
this.replies,
5858
(item) => item.metadata.name,
5959
(item) =>
60-
html` <reply-item
60+
html`<reply-item
6161
.comment=${this.comment}
6262
.reply="${item}"
6363
.replies=${this.replies}

packages/comment-widget/src/reply-form.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ export class ReplyForm extends LitElement {
144144
}
145145

146146
this.dispatchEvent(new CustomEvent('reload'));
147+
window.dispatchEvent(new CustomEvent('halo:comment-reply:created'));
148+
147149
this.baseFormRef.value?.resetForm();
148150
} catch (error) {
149151
if (error instanceof FetchError) {

packages/example/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
document.documentElement.classList.add(theme);
3838
}
3939
});
40+
41+
window.addEventListener("halo:comment:created", () => {
42+
console.log("halo:comment:created");
43+
});
44+
45+
window.addEventListener("halo:comment-reply:created", () => {
46+
console.log("halo:comment-reply:created");
47+
});
4048
</script>
4149
</head>
4250
<body>

0 commit comments

Comments
 (0)