fixup nickname dialog for enter key pressed event (#1623)

also add some type for it and remove unused props
pull/1628/head
Audric Ackermann 4 years ago committed by GitHub
parent c91f866d95
commit 3d9fbd9153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -384,15 +384,8 @@
};
window.showNicknameDialog = params => {
const options = {
title: params.title || undefined,
message: params.message,
placeholder: params.placeholder,
convoId: params.convoId || undefined,
};
if (appView) {
appView.showNicknameDialog(options);
appView.showNicknameDialog(params);
}
};

@ -1,26 +1,20 @@
import React, { useState } from 'react';
import { ConversationController } from '../../session/conversations/ConversationController';
import { SessionModal } from './SessionModal';
import { SessionButton, SessionButtonColor } from './SessionButton';
import { SessionButton } from './SessionButton';
import { DefaultTheme, withTheme } from 'styled-components';
import _ from 'lodash';
type Props = {
message: string;
title: string;
placeholder?: string;
onOk?: any;
onClose?: any;
onClickOk: any;
onClickClose: any;
hideCancel: boolean;
okTheme: SessionButtonColor;
theme: DefaultTheme;
convoId?: string;
convoId: string;
};
const SessionNicknameInner = (props: Props) => {
const { title = '', message, onClickOk, onClickClose, convoId, placeholder } = props;
const showHeader = true;
const { onClickOk, onClickClose, convoId, theme } = props;
const [nickname, setNickname] = useState('');
/**
@ -30,9 +24,10 @@ const SessionNicknameInner = (props: Props) => {
const onNicknameInput = async (event: any) => {
if (event.key === 'Enter') {
await saveNickname();
} else {
const currentNicknameEntered = event.target.value;
setNickname(currentNicknameEntered);
}
const currentNicknameEntered = event.target.value;
setNickname(currentNicknameEntered);
};
/**
@ -49,24 +44,24 @@ const SessionNicknameInner = (props: Props) => {
return (
<SessionModal
title={title}
title={window.i18n('changeNickname')}
onClose={onClickClose}
showExitIcon={false}
showHeader={showHeader}
theme={props.theme}
showHeader={true}
theme={theme}
>
{!showHeader && <div className="spacer-lg" />}
<div className="session-modal__centered">
<span className="subtle">{message}</span>
<span className="subtle">{window.i18n('changeNicknameMessage')}</span>
<div className="spacer-lg" />
</div>
<input
type="nickname"
id="nickname-modal-input"
placeholder={placeholder}
onKeyUp={onNicknameInput}
placeholder={window.i18n('nicknamePlaceholder')}
onKeyPress={e => {
void onNicknameInput(_.cloneDeep(e));
}}
/>
<div className="session-modal__button-group">

@ -1313,9 +1313,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
);
}
window.showNicknameDialog({
title: window.i18n('changeNickname') || 'Change Nickname',
message: window.i18n('changeNicknameMessage') || '',
placeholder: window.i18n('nicknamePlaceholder') || '',
convoId: this.id,
});
}

2
ts/window.d.ts vendored

@ -68,7 +68,7 @@ declare global {
setPassword: any;
setSettingValue: any;
showEditProfileDialog: any;
showNicknameDialog: any;
showNicknameDialog: (options: { convoId: string }) => void;
showResetSessionIdDialog: any;
storage: any;
textsecure: LibTextsecure;

Loading…
Cancel
Save