Skip to content

Commit 29d22f0

Browse files
committed
Refine UI
Signed-off-by: Ryan Wang <[email protected]>
1 parent d490806 commit 29d22f0

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class CommentForm extends LitElement {
5454
@state()
5555
submitting = false;
5656

57+
@state()
5758
captcha = '';
5859

5960
baseFormRef: Ref<BaseForm> = createRef<BaseForm>();

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

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import './base-form';
21
import { CommentVo, Reply, ReplyRequest, ReplyVo, User } from '@halo-dev/api-client';
3-
import { html, LitElement } from 'lit';
4-
import { createRef, Ref, ref } from 'lit/directives/ref.js';
2+
import { consume } from '@lit/context';
3+
import { LitElement, html } from 'lit';
4+
import { property, state } from 'lit/decorators.js';
5+
import { Ref, createRef, ref } from 'lit/directives/ref.js';
6+
import './base-form';
7+
import { BaseForm } from './base-form';
58
import {
69
allowAnonymousCommentsContext,
710
baseUrlContext,
811
currentUserContext,
912
toastContext,
1013
} from './context';
11-
import { property, state } from 'lit/decorators.js';
12-
import { BaseForm } from './base-form';
13-
import { consume } from '@lit/context';
1414
import { ToastManager } from './lit-toast';
15+
import { getCaptchaCodeHeader, isRequireCaptcha } from './utils/captcha';
1516

1617
export class ReplyForm extends LitElement {
1718
@consume({ context: baseUrlContext })
@@ -39,6 +40,9 @@ export class ReplyForm extends LitElement {
3940
@state()
4041
submitting = false;
4142

43+
@state()
44+
captcha = '';
45+
4246
baseFormRef: Ref<BaseForm> = createRef<BaseForm>();
4347

4448
override connectedCallback(): void {
@@ -53,6 +57,7 @@ export class ReplyForm extends LitElement {
5357
override render() {
5458
return html` <base-form
5559
.submitting=${this.submitting}
60+
.captcha=${this.captcha}
5661
${ref(this.baseFormRef)}
5762
@submit="${this.onSubmit}"
5863
></base-form>`;
@@ -105,11 +110,21 @@ export class ReplyForm extends LitElement {
105110
method: 'POST',
106111
headers: {
107112
'Content-Type': 'application/json',
113+
...getCaptchaCodeHeader(data.captchaCode),
108114
},
109115
body: JSON.stringify(replyRequest),
110116
}
111117
);
112118

119+
if (isRequireCaptcha(response)) {
120+
const { captcha, detail } = await response.json();
121+
this.captcha = captcha;
122+
this.toastManager?.warn(detail);
123+
return;
124+
}
125+
126+
this.captcha = '';
127+
113128
if (!response.ok) {
114129
throw new Error('评论失败,请稍后重试');
115130
}

0 commit comments

Comments
 (0)