Skip to content

Commit 385b4d3

Browse files
committed
Improved autosaved state for comments
Signed-off-by: Parth Raiyani <[email protected]> Change-Id: I9ad6c36a393ef5d895ee463f44569c52f1c8fd61
1 parent b35c4f5 commit 385b4d3

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed

browser/css/cool.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,13 @@ nav.spreadsheet-color-indicator ~ #sidebar-dock-wrapper {
766766
font-size: var(--default-font-size);
767767
}
768768

769-
.cool-annotation-autosavelabel {
770-
font-size: var(--default-font-size);
771-
opacity: 75%;
769+
.annotation-button-autosaved {
770+
color: var(--color-primary-dark) !important;
771+
background-color: #e1e8f9 !important;
772+
}
773+
774+
.annotation-button-delete {
775+
color: var(--color-error) !important;
772776
}
773777

774778
.cool-annotation-menubar {

browser/src/layer/tile/CommentListSection.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,6 @@ export class CommentSection extends CanvasSectionObject {
11231123
if (action === 'Add') {
11241124
if (app.view.commentAutoSave) {
11251125
app.view.commentAutoSave.sectionProperties.data.id = obj.comment.id;
1126-
app.view.commentAutoSave.sectionProperties.autoSave.innerText = _('Autosaved') ;
11271126
app.view.commentAutoSave = null;
11281127
app.view.commentAutoAdded = true;
11291128
return;
@@ -1158,7 +1157,6 @@ export class CommentSection extends CanvasSectionObject {
11581157
}
11591158
} else if (action === 'Modify') {
11601159
if (app.view.commentAutoSave) {
1161-
app.view.commentAutoSave.sectionProperties.autoSave.innerText = _('Autosaved');
11621160
app.view.commentAutoSave = null;
11631161
return;
11641162
}

browser/src/layer/tile/CommentSection.ts

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export class Comment extends CanvasSectionObject {
114114
var button = L.DomUtil.create('div', 'annotation-btns-container', this.sectionProperties.nodeModify);
115115
L.DomEvent.on(this.sectionProperties.nodeModifyText, 'blur', this.onLostFocus, this);
116116
L.DomEvent.on(this.sectionProperties.nodeReplyText, 'blur', this.onLostFocusReply, this);
117-
L.DomEvent.on(this.sectionProperties.nodeModifyText, 'input', this.textAreaInput, this);
118-
L.DomEvent.on(this.sectionProperties.nodeReplyText, 'input', this.textAreaInput, this);
117+
L.DomEvent.on(this.sectionProperties.nodeModifyText, 'focus', this.onFocus, this);
118+
L.DomEvent.on(this.sectionProperties.nodeReplyText, 'focus', this.onFocusReply, this);
119119
this.createButton(button, 'annotation-cancel-' + this.sectionProperties.data.id, 'annotation-button button-secondary', _('Cancel'), this.onCancelClick);
120120
this.createButton(button, 'annotation-save-' + this.sectionProperties.data.id, 'annotation-button button-primary',_('Save'), this.handleSaveCommentButton);
121121
button = L.DomUtil.create('div', '', this.sectionProperties.nodeReply);
@@ -241,7 +241,6 @@ export class Comment extends CanvasSectionObject {
241241
this.sectionProperties.authorAvatartdImg = tdImg;
242242
this.sectionProperties.contentAuthor = L.DomUtil.create('div', 'cool-annotation-content-author', tdAuthor);
243243
this.sectionProperties.contentDate = L.DomUtil.create('div', 'cool-annotation-date', tdAuthor);
244-
this.sectionProperties.autoSave = L.DomUtil.create('div', 'cool-annotation-autosavelabel', tdAuthor);
245244
}
246245

247246
private createMenu (): void {
@@ -304,8 +303,12 @@ export class Comment extends CanvasSectionObject {
304303
this.sectionProperties.resolvedTextElement.innerText = state === 'true' ? _('Resolved') : '';
305304
}
306305

307-
private textAreaInput (): void {
308-
this.sectionProperties.autoSave.innerText = '';
306+
private onFocus() {
307+
this.resetControl(this.getSaveButton(), _('Save'), 'annotation-button-autosaved');
308+
}
309+
310+
private onFocusReply() {
311+
this.resetControl(this.getReplyButton(), _('Reply'), 'annotation-button-autosaved');
309312
}
310313

311314
private updateContent (): void {
@@ -784,7 +787,6 @@ export class Comment extends CanvasSectionObject {
784787

785788
public handleReplyCommentButton (e: any): void {
786789
app.view.commentAutoSave = null;
787-
this.textAreaInput();
788790
this.onReplyClick(e);
789791
}
790792

@@ -826,7 +828,6 @@ export class Comment extends CanvasSectionObject {
826828

827829
public handleSaveCommentButton (e: any): void {
828830
app.view.commentAutoSave = null;
829-
this.textAreaInput();
830831
this.onSaveComment(e);
831832
}
832833

@@ -841,10 +842,49 @@ export class Comment extends CanvasSectionObject {
841842
this.sectionProperties.commentListSection.save(this);
842843
}
843844

845+
846+
private getSaveButton(): HTMLButtonElement | null {
847+
return this.sectionProperties.nodeModify.querySelector('input[type="button"][id^="annotation-save-"]');
848+
}
849+
850+
private getCancelButton(): HTMLButtonElement | null {
851+
return this.sectionProperties.nodeModify.querySelector('input[type="button"][id^="annotation-cancel-"]');
852+
}
853+
854+
private getReplyButton(): HTMLButtonElement | null {
855+
return this.sectionProperties.nodeReply.querySelector('input[type="button"][id^="annotation-reply-"]');
856+
}
857+
858+
private getCancelReplyButton(): HTMLButtonElement | null {
859+
return this.sectionProperties.nodeReply.querySelector('input[type="button"][id^="annotation-cancel-reply-"]');
860+
}
861+
862+
private updateControl(
863+
button: HTMLButtonElement | null,
864+
label: string,
865+
className: string
866+
): void {
867+
if (button) {
868+
button.value = label;
869+
button.classList.add(className);
870+
}
871+
}
872+
873+
private updateSaveControls() {
874+
this.updateControl(this.getSaveButton(), _('Saved'), 'annotation-button-autosaved');
875+
this.updateControl(this.getCancelButton(), _('Delete'), 'annotation-button-delete');
876+
}
877+
878+
private updateReplyControls() {
879+
this.updateControl(this.getReplyButton(), _('Saved'), 'annotation-button-autosaved');
880+
this.updateControl(this.getCancelReplyButton(), _('Delete'), 'annotation-button-delete');
881+
}
882+
844883
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
845884
public onLostFocus (e: any): void {
846885
if (!this.sectionProperties.isRemoved) {
847886
app.view.commentAutoSave = this;
887+
this.updateSaveControls();
848888
if (this.sectionProperties.contentText.origText !== this.sectionProperties.nodeModifyText.value) {
849889
this.onSaveComment(e);
850890
}
@@ -868,6 +908,7 @@ export class Comment extends CanvasSectionObject {
868908
public onLostFocusReply (e: any): void {
869909

870910
if (this.sectionProperties.nodeReplyText.value !== '') {
911+
this.updateReplyControls();
871912
app.view.commentAutoSave = this;
872913
this.onReplyClick(e);
873914
}
@@ -877,11 +918,34 @@ export class Comment extends CanvasSectionObject {
877918
app.view.commentHasFocus = false;
878919
}
879920

921+
private resetControl(
922+
button: HTMLButtonElement | null,
923+
label: string,
924+
className: string
925+
): void {
926+
if (button) {
927+
button.value = label;
928+
button.classList.remove(className);
929+
}
930+
}
931+
932+
private resetSaveControls(): void {
933+
this.resetControl(this.getSaveButton(), _('Save'), 'annotation-button-autosaved');
934+
this.resetControl(this.getCancelButton(), _('Cancel'), 'annotation-button-delete');
935+
}
936+
937+
private resetReplyControls(): void {
938+
this.resetControl(this.getReplyButton(), _('Reply'), 'annotation-button-autosaved');
939+
this.resetControl(this.getCancelReplyButton(), _('Cancel'), 'annotation-button-delete');
940+
}
941+
880942
public focus (): void {
881943
this.sectionProperties.container.classList.add('annotation-active');
882944
this.sectionProperties.nodeModifyText.focus();
883945
this.sectionProperties.nodeReplyText.focus();
884946
app.view.commentHasFocus = true;
947+
this.resetSaveControls();
948+
this.resetReplyControls();
885949
}
886950

887951
public reply (): Comment {

0 commit comments

Comments
 (0)