Skip to content

Commit

Permalink
Centralize tryToClose() for all popups
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Aug 6, 2024
1 parent fa15742 commit c33dd8f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 13 deletions.
5 changes: 2 additions & 3 deletions dev/Knoin/AbstractViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ export class AbstractViewPopup extends AbstractView
this.keyScope.scope = name;
this.modalVisible = ko.observable(false).extend({ rateLimit: 0 });
this.close = () => this.modalVisible(false);
this.tryToClose = () => (false === this.onClose()) || this.close();
addShortcut('escape,close', '', name, () => {
if (this.modalVisible() && false !== this.onClose()) {
this.close();
}
this.modalVisible() && this.tryToClose();
return false;
// return true; Issue with supported modal close
});
Expand Down
2 changes: 1 addition & 1 deletion dev/Knoin/Knoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const
if (screenName && fireEvent('sm-show-screen', screenName + (subPart ? '/' + subPart : ''), 1)) {
// Close all popups
for (let vm of visiblePopups) {
(false === vm.onClose()) || vm.close();
vm.tryToClose();
}

let vmScreen = screen(screenName);
Expand Down
8 changes: 4 additions & 4 deletions dev/View/Popup/Compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export class ComposePopupView extends AbstractViewPopup {
]
});

this.tryToClose = this.tryToClose.debounce(200);
this.doClose = this.doClose.debounce(200);

this.iTimer = 0;

Expand Down Expand Up @@ -665,7 +665,7 @@ export class ComposePopupView extends AbstractViewPopup {
this.saveCommand();
}

this.tryToClose();
this.doClose();
}

contactsCommand() {
Expand Down Expand Up @@ -1072,7 +1072,7 @@ export class ComposePopupView extends AbstractViewPopup {
}, 100);
}

tryToClose() {
doClose() {
if (AskPopupView.hidden()) {
if (ComposePopupView.inEdit() || (this.isEmptyForm() && !this.draftUid())) {
this.close();
Expand Down Expand Up @@ -1218,7 +1218,7 @@ export class ComposePopupView extends AbstractViewPopup {
});

addShortcut('escape,close', 'shift', ScopeCompose, () => {
this.tryToClose();
this.doClose();
return false;
});

Expand Down
4 changes: 0 additions & 4 deletions dev/View/Popup/Contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,6 @@ export class ContactsPopupView extends AbstractViewPopup {
}
}

tryToClose() {
(false === this.onClose()) || this.close();
}

onClose() {
const contact = this.contact();
if (AskPopupView.hidden() && contact?.hasChanges()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<header class="g-ui-user-select-none">
<a href="#" class="close" data-bind="click: close">×</a>
<a href="#" class="close" data-bind="click: tryToClose">×</a>
<h3 data-bind="visible: !edit()" data-i18n="POPUPS_IDENTITY/TITLE_ADD_IDENTITY"></h3>
<h3 data-bind="visible: edit" data-i18n="POPUPS_IDENTITY/TITLE_UPDATE_IDENTITY"></h3>
</header>
Expand Down

0 comments on commit c33dd8f

Please sign in to comment.