Skip to content

Commit 8641647

Browse files
committed
Fix: Improve visibility of autosaved state for comments
This commit addresses issue #7211 by enhancing the user experience for the autosaved comments feature. The changes ensure users can easily recognize autosave status without increasing widget height. To test the fix, manually verify the autosave behavior by changing focus to another browser tab and checking that the comment remains editable with clear autosaved feedback. Signed-off-by: Parth Raiyani <[email protected]> Change-Id: I967fee3e4f696b8433a22602af759e1b758bb7b4
1 parent b57758d commit 8641647

File tree

3 files changed

+84
-10
lines changed

3 files changed

+84
-10
lines changed

browser/css/cool.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,9 +807,13 @@ body {
807807
font-size: var(--default-font-size);
808808
}
809809

810-
.cool-annotation-autosavelabel {
811-
font-size: var(--default-font-size);
812-
opacity: 75%;
810+
.annotation-button-autosaved {
811+
color: var(--color-primary-dark) !important;
812+
background-color: #e1e8f9 !important;
813+
}
814+
815+
.annotation-button-delete {
816+
color: var(--color-error) !important;
813817
}
814818

815819
.cool-annotation-menubar {

browser/src/canvas/sections/CommentListSection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ export class CommentSection extends CanvasSectionObject {
15701570
app.definitions.CommentSection.needFocus = annotation;
15711571
}
15721572
annotation.sectionProperties.container.style.visibility = 'visible';
1573-
annotation.sectionProperties.autoSave.innerText = _('Autosaved');
1573+
annotation.focusLost();
15741574
if (app.map._docLayer._docType === 'spreadsheet')
15751575
annotation.show();
15761576
if (autoSavedComment.sectionProperties.data.id === 'new')
@@ -1644,7 +1644,7 @@ export class CommentSection extends CanvasSectionObject {
16441644
this.update();
16451645

16461646
if (CommentSection.autoSavedComment) {
1647-
CommentSection.autoSavedComment.sectionProperties.autoSave.innerText = _('Autosaved');
1647+
modified.focusLost();
16481648
if (app.map._docLayer._docType === 'spreadsheet')
16491649
modified.show();
16501650
modified.edit();

browser/src/canvas/sections/CommentSection.ts

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ export class Comment extends CanvasSectionObject {
158158
return;
159159

160160
var button = L.DomUtil.create('div', 'annotation-btns-container', this.sectionProperties.nodeModify);
161+
L.DomEvent.on(this.sectionProperties.nodeModifyText, 'focus', this.onFocus, this);
162+
L.DomEvent.on(this.sectionProperties.nodeReplyText, 'focus', this.onFocusReply, this);
161163
L.DomEvent.on(this.sectionProperties.nodeModifyText, 'input', this.textAreaInput, this);
162164
L.DomEvent.on(this.sectionProperties.nodeReplyText, 'input', this.textAreaInput, this);
163165
L.DomEvent.on(this.sectionProperties.nodeModifyText, 'keydown', this.textAreaKeyDown, this);
@@ -300,7 +302,6 @@ export class Comment extends CanvasSectionObject {
300302
this.sectionProperties.authorAvatartdImg = tdImg;
301303
this.sectionProperties.contentAuthor = L.DomUtil.create('div', 'cool-annotation-content-author', tdAuthor);
302304
this.sectionProperties.contentDate = L.DomUtil.create('div', 'cool-annotation-date', tdAuthor);
303-
this.sectionProperties.autoSave = L.DomUtil.create('div', 'cool-annotation-autosavelabel', tdAuthor);
304305
}
305306

306307
private createMenu (): void {
@@ -423,8 +424,6 @@ export class Comment extends CanvasSectionObject {
423424
}
424425

425426
private textAreaInput(ev: any): void {
426-
this.sectionProperties.autoSave.innerText = '';
427-
428427
if (ev && app.map._docLayer._docType === 'text') {
429428
// special handling for mentions
430429
this.map?.mention.handleMentionInput(ev, this.isNewPara());
@@ -462,6 +461,14 @@ export class Comment extends CanvasSectionObject {
462461
return '';
463462
}
464463

464+
private onFocus() {
465+
this.resetControl(this.getSaveButton(), _('Save'), 'annotation-button-autosaved');
466+
}
467+
468+
private onFocusReply() {
469+
this.resetControl(this.getReplyButton(), _('Reply'), 'annotation-button-autosaved');
470+
}
471+
465472
private updateContent (): void {
466473
if(this.sectionProperties.data.html)
467474
this.sectionProperties.contentText.innerHTML = this.sanitize(this.sectionProperties.data.html);
@@ -1101,7 +1108,6 @@ export class Comment extends CanvasSectionObject {
11011108

11021109
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
11031110
public onSaveComment (e: any): void {
1104-
this.sectionProperties.commentContainerRemoved = true;
11051111
L.DomEvent.stopPropagation(e);
11061112
this.removeLastBRTag(this.sectionProperties.nodeModifyText);
11071113
this.sectionProperties.data.text = this.sectionProperties.nodeModifyText.innerText;
@@ -1122,6 +1128,43 @@ export class Comment extends CanvasSectionObject {
11221128
brElements[brElements.length-1].remove();
11231129
}
11241130

1131+
private getSaveButton(): HTMLButtonElement | null {
1132+
return this.sectionProperties.nodeModify.querySelector('input[type="button"][id^="annotation-save-"]');
1133+
}
1134+
1135+
private getCancelButton(): HTMLButtonElement | null {
1136+
return this.sectionProperties.nodeModify.querySelector('input[type="button"][id^="annotation-cancel-"]');
1137+
}
1138+
1139+
private getReplyButton(): HTMLButtonElement | null {
1140+
return this.sectionProperties.nodeReply.querySelector('input[type="button"][id^="annotation-reply-"]');
1141+
}
1142+
1143+
private getCancelReplyButton(): HTMLButtonElement | null {
1144+
return this.sectionProperties.nodeReply.querySelector('input[type="button"][id^="annotation-cancel-reply-"]');
1145+
}
1146+
1147+
private updateControl(
1148+
button: HTMLButtonElement | null,
1149+
label: string,
1150+
className: string
1151+
): void {
1152+
if (button) {
1153+
button.value = label;
1154+
button.classList.add(className);
1155+
}
1156+
}
1157+
1158+
private updateSaveControls() {
1159+
this.updateControl(this.getSaveButton(), _('Saved'), 'annotation-button-autosaved');
1160+
this.updateControl(this.getCancelButton(), _('Delete'), 'annotation-button-delete');
1161+
}
1162+
1163+
private updateReplyControls() {
1164+
this.updateControl(this.getReplyButton(), _('Saved'), 'annotation-button-autosaved');
1165+
this.updateControl(this.getCancelReplyButton(), _('Delete'), 'annotation-button-delete');
1166+
}
1167+
11251168
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
11261169
public onLostFocus (e: any): void {
11271170

@@ -1136,7 +1179,6 @@ export class Comment extends CanvasSectionObject {
11361179
return;
11371180
}
11381181
if (!this.sectionProperties.commentContainerRemoved) {
1139-
this.cachedIsEdit = false;
11401182
$(this.sectionProperties.container).removeClass('annotation-active reply-annotation-container modify-annotation-container');
11411183
this.removeLastBRTag(this.sectionProperties.nodeModifyText);
11421184
if (this.sectionProperties.contentText.origText !== this.sectionProperties.nodeModifyText.innerText ||
@@ -1183,6 +1225,27 @@ export class Comment extends CanvasSectionObject {
11831225
}
11841226
}
11851227

1228+
private resetControl(
1229+
button: HTMLButtonElement | null,
1230+
label: string,
1231+
className: string
1232+
): void {
1233+
if (button) {
1234+
button.value = label;
1235+
button.classList.remove(className);
1236+
}
1237+
}
1238+
1239+
private resetSaveControls(): void {
1240+
this.resetControl(this.getSaveButton(), _('Save'), 'annotation-button-autosaved');
1241+
this.resetControl(this.getCancelButton(), _('Cancel'), 'annotation-button-delete');
1242+
}
1243+
1244+
private resetReplyControls(): void {
1245+
this.resetControl(this.getReplyButton(), _('Reply'), 'annotation-button-autosaved');
1246+
this.resetControl(this.getCancelReplyButton(), _('Cancel'), 'annotation-button-delete');
1247+
}
1248+
11861249
public focus (): void {
11871250
this.sectionProperties.container.classList.add('annotation-active');
11881251
this.sectionProperties.nodeModifyText.focus({ focusVisible: true });
@@ -1198,6 +1261,13 @@ export class Comment extends CanvasSectionObject {
11981261
sel.addRange(range)
11991262
}
12001263

1264+
this.resetSaveControls();
1265+
this.resetReplyControls();
1266+
}
1267+
1268+
public focusLost (): void {
1269+
this.updateSaveControls();
1270+
this.updateReplyControls();
12011271
}
12021272

12031273
public reply (): Comment {

0 commit comments

Comments
 (0)