Skip to content

Commit

Permalink
2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
adanski committed Feb 1, 2023
1 parent abce286 commit 68d0d7e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ax-comments",
"title": "ax-comments",
"version": "2.1.1",
"version": "2.1.2",
"author": {
"name": "Adrian Z."
},
Expand Down
18 changes: 12 additions & 6 deletions src/comments-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class CommentsElement extends HTMLElement implements WebComponent {
#spinnerFactory!: SpinnerFactory;

#currentSortKey!: SortKey;
#connected: boolean = false;
#dataFetched: boolean = false;

constructor() {
Expand All @@ -47,15 +48,14 @@ export class CommentsElement extends HTMLElement implements WebComponent {
}

connectedCallback(): void {
if (!Object.keys(this.#options).length) {
return;
this.#connected = true;
if (Object.keys(this.#options).length) {
this.#init();
}
this.#initServices();
this.#initElement();
this.#initEmitterListeners();
}

disconnectedCallback(): void {
this.#connected = false;
this.#commentViewModel.unsubscribeAll();
this.#unsubscribeEvents();
this.container.innerHTML = '';
Expand All @@ -73,7 +73,7 @@ export class CommentsElement extends HTMLElement implements WebComponent {
}
Object.assign(this.#options, getDefaultOptions(), options);
Object.freeze(this.#options);
this.connectedCallback();
if (this.#connected) this.#init();
}

/**
Expand All @@ -88,6 +88,12 @@ export class CommentsElement extends HTMLElement implements WebComponent {
this.container = shadowRoot.querySelector<HTMLElement>('#comments-container')!;
}

#init(): void {
this.#initServices();
this.#initElement();
this.#initEmitterListeners();
}

#initServices(): void {
OptionsProvider.set(this.container, this.#options);
this.#commentViewModel = CommentViewModelProvider.set(this.container, {});
Expand Down
2 changes: 1 addition & 1 deletion src/subcomponent/comment-container-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export class CommentContainerElement extends HTMLElement implements WebComponent
};

#isAllowedToDelete(commentModel: CommentModelEnriched): boolean {
if (!commentModel.createdByCurrentUser || !this.#options.enableDeleting) {
if (!this.#options.enableDeleting || !commentModel.createdByCurrentUser && !this.#options.currentUserIsAdmin) {
return false;
} else {
return this.#options.enableDeletingCommentWithReplies || !commentModel.childIds.length;
Expand Down
3 changes: 2 additions & 1 deletion src/subcomponent/commenting-field-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ export class CommentingFieldElement extends HTMLElement implements WebComponent
mainTextarea.clearTextarea();

// Clear attachments
this.querySelector('.attachments')!.innerHTML = '';
const attachments: HTMLElement | null = this.querySelector('.attachments');
if (attachments) attachments.innerHTML = '';

// Toggle save button
this.#toggleSaveButton();
Expand Down

0 comments on commit 68d0d7e

Please sign in to comment.