Don't use browser's confirm dialog when logging out

Refs https://github.com/conversejs/converse-desktop/issues/18
This commit is contained in:
JC Brand 2022-05-11 09:13:17 +02:00
parent b5bcc05947
commit a3c0f90476
3 changed files with 13 additions and 13 deletions

View File

@ -1,7 +1,6 @@
import UserSettingsModal from 'modals/user-settings';
import tpl_profile from './templates/profile.js';
import { CustomElement } from 'shared/components/element.js';
import { __ } from 'i18n';
import { _converse, api } from '@converse/headless/core';
class Profile extends CustomElement {
@ -31,14 +30,6 @@ class Profile extends CustomElement {
ev?.preventDefault();
api.modal.show(UserSettingsModal, {model: this.model, _converse}, ev);
}
logout (ev) { // eslint-disable-line class-methods-use-this
ev?.preventDefault();
const result = confirm(__("Are you sure you want to log out?"));
if (result === true) {
api.user.logout();
}
}
}
api.elements.define('converse-user-profile', Profile);

View File

@ -1,13 +1,13 @@
import 'shared/avatar/avatar.js';
import { __ } from 'i18n';
import { _converse, api } from "@converse/headless/core";
import { getPrettyStatus } from '../utils.js';
import { getPrettyStatus, logOut } from '../utils.js';
import { html } from "lit";
function tpl_signout (o) {
function tpl_signout () {
const i18n_logout = __('Log out');
return html`<a class="controlbox-heading__btn logout align-self-center" title="${i18n_logout}" @click=${o.logout}>
return html`<a class="controlbox-heading__btn logout align-self-center" title="${i18n_logout}" @click=${logOut}>
<converse-icon class="fa fa-sign-out-alt" size="1em"></converse-icon>
</a>`
}
@ -46,7 +46,7 @@ export default (el) => {
</a>
<span class="username w-100 align-self-center">${fullname}</span>
${show_settings_button ? tpl_user_settings_button(el) : ''}
${api.settings.get('allow_logout') ? tpl_signout(el) : ''}
${api.settings.get('allow_logout') ? tpl_signout() : ''}
</div>
<div class="d-flex xmpp-status">
<a class="change-status" title="${i18n_change_status}" data-toggle="modal" data-target="#changeStatusModal" @click=${el.showStatusChangeModal}>

View File

@ -1,4 +1,5 @@
import { __ } from 'i18n';
import { api } from '@converse/headless/core';
export function getPrettyStatus (stat) {
if (stat === 'chat') {
@ -15,3 +16,11 @@ export function getPrettyStatus (stat) {
return __(stat) || __('online');
}
}
export async function logOut (ev) {
ev?.preventDefault();
const result = await api.confirm(__("Are you sure you want to log out?"));
if (result) {
api.user.logout();
}
}