Skip to content

Commit 2e7544a

Browse files
committed
Comments: Converted comment component to TS
1 parent 5e3c3ad commit 2e7544a

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed
Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,51 @@ import {buildForInput} from '../wysiwyg-tinymce/config';
44

55
export class PageComment extends Component {
66

7+
protected commentId: string;
8+
protected commentLocalId: string;
9+
protected commentContentRef: string;
10+
protected deletedText: string;
11+
protected updatedText: string;
12+
13+
protected wysiwygEditor: any = null;
14+
protected wysiwygLanguage: string;
15+
protected wysiwygTextDirection: string;
16+
17+
protected container: HTMLElement;
18+
protected contentContainer: HTMLElement;
19+
protected form: HTMLFormElement;
20+
protected formCancel: HTMLElement;
21+
protected editButton: HTMLElement;
22+
protected deleteButton: HTMLElement;
23+
protected replyButton: HTMLElement;
24+
protected input: HTMLInputElement;
25+
726
setup() {
827
// Options
928
this.commentId = this.$opts.commentId;
1029
this.commentLocalId = this.$opts.commentLocalId;
11-
this.commentParentId = this.$opts.commentParentId;
30+
this.commentContentRef = this.$opts.commentContentRef;
1231
this.deletedText = this.$opts.deletedText;
1332
this.updatedText = this.$opts.updatedText;
1433

1534
// Editor reference and text options
16-
this.wysiwygEditor = null;
1735
this.wysiwygLanguage = this.$opts.wysiwygLanguage;
1836
this.wysiwygTextDirection = this.$opts.wysiwygTextDirection;
1937

2038
// Element references
2139
this.container = this.$el;
2240
this.contentContainer = this.$refs.contentContainer;
23-
this.form = this.$refs.form;
41+
this.form = this.$refs.form as HTMLFormElement;
2442
this.formCancel = this.$refs.formCancel;
2543
this.editButton = this.$refs.editButton;
2644
this.deleteButton = this.$refs.deleteButton;
2745
this.replyButton = this.$refs.replyButton;
28-
this.input = this.$refs.input;
46+
this.input = this.$refs.input as HTMLInputElement;
2947

3048
this.setupListeners();
3149
}
3250

33-
setupListeners() {
51+
protected setupListeners(): void {
3452
if (this.replyButton) {
3553
this.replyButton.addEventListener('click', () => this.$emit('reply', {
3654
id: this.commentLocalId,
@@ -49,12 +67,12 @@ export class PageComment extends Component {
4967
}
5068
}
5169

52-
toggleEditMode(show) {
70+
protected toggleEditMode(show: boolean) : void {
5371
this.contentContainer.toggleAttribute('hidden', show);
5472
this.form.toggleAttribute('hidden', !show);
5573
}
5674

57-
startEdit() {
75+
protected startEdit() : void {
5876
this.toggleEditMode(true);
5977

6078
if (this.wysiwygEditor) {
@@ -67,29 +85,30 @@ export class PageComment extends Component {
6785
containerElement: this.input,
6886
darkMode: document.documentElement.classList.contains('dark-mode'),
6987
textDirection: this.wysiwygTextDirection,
88+
drawioUrl: '',
89+
pageId: 0,
7090
translations: {},
71-
translationMap: window.editor_translations,
91+
translationMap: (window as Record<string, Object>).editor_translations,
7292
});
7393

74-
window.tinymce.init(config).then(editors => {
94+
(window as {tinymce: {init: (Object) => Promise<any>}}).tinymce.init(config).then(editors => {
7595
this.wysiwygEditor = editors[0];
7696
setTimeout(() => this.wysiwygEditor.focus(), 50);
7797
});
7898
}
7999

80-
async update(event) {
100+
protected async update(event: Event): Promise<void> {
81101
event.preventDefault();
82102
const loading = this.showLoading();
83103
this.form.toggleAttribute('hidden', true);
84104

85105
const reqData = {
86106
html: this.wysiwygEditor.getContent(),
87-
parent_id: this.parentId || null,
88107
};
89108

90109
try {
91110
const resp = await window.$http.put(`/comment/${this.commentId}`, reqData);
92-
const newComment = htmlToDom(resp.data);
111+
const newComment = htmlToDom(resp.data as string);
93112
this.container.replaceWith(newComment);
94113
window.$events.success(this.updatedText);
95114
} catch (err) {
@@ -100,7 +119,7 @@ export class PageComment extends Component {
100119
}
101120
}
102121

103-
async delete() {
122+
protected async delete(): Promise<void> {
104123
this.showLoading();
105124

106125
await window.$http.delete(`/comment/${this.commentId}`);
@@ -109,7 +128,7 @@ export class PageComment extends Component {
109128
window.$events.success(this.deletedText);
110129
}
111130

112-
showLoading() {
131+
protected showLoading(): HTMLElement {
113132
const loading = getLoading();
114133
loading.classList.add('px-l');
115134
this.container.append(loading);

resources/views/comments/comment.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div component="{{ $readOnly ? '' : 'page-comment' }}"
55
option:page-comment:comment-id="{{ $comment->id }}"
66
option:page-comment:comment-local-id="{{ $comment->local_id }}"
7-
option:page-comment:comment-parent-id="{{ $comment->parent_id }}"
7+
option:page-comment:comment-content-ref="{{ $comment->content_ref }}"
88
option:page-comment:updated-text="{{ trans('entities.comment_updated_success') }}"
99
option:page-comment:deleted-text="{{ trans('entities.comment_deleted_success') }}"
1010
option:page-comment:wysiwyg-language="{{ $locale->htmlLang() }}"

0 commit comments

Comments
 (0)