chore: Send typing events on keyup, not on focus (#1461)

This commit is contained in:
Pranav Raj S 2020-11-27 00:17:55 +05:30 committed by GitHub
parent a988724c91
commit f397c0c087
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 6 deletions

View file

@ -19,6 +19,8 @@
class="input"
:placeholder="messagePlaceHolder"
:min-height="4"
@typing-off="onTypingOff"
@typing-on="onTypingOn"
@focus="onFocus"
@blur="onBlur"
/>
@ -298,13 +300,17 @@ export default {
hideCannedResponse() {
this.showCannedResponsesList = false;
},
onTypingOn() {
this.toggleTyping('on');
},
onTypingOff() {
this.toggleTyping('off');
},
onBlur() {
this.isFocused = false;
this.toggleTyping('off');
},
onFocus() {
this.isFocused = true;
this.toggleTyping('on');
},
toggleTyping(status) {
if (this.isAWebWidgetInbox && !this.isPrivate) {

View file

@ -5,11 +5,14 @@
:value="value"
@input="onInput"
@focus="onFocus"
@keyup="onKeyup"
@blur="onBlur"
/>
</template>
<script>
const TYPING_INDICATOR_IDLE_TIME = 4000;
export default {
props: {
placeholder: {
@ -25,6 +28,11 @@ export default {
default: 2,
},
},
data() {
return {
idleTimer: null,
};
},
watch: {
value() {
this.resizeTextarea();
@ -42,7 +50,28 @@ export default {
this.$emit('input', event.target.value);
this.resizeTextarea();
},
resetTyping() {
this.$emit('typing-off');
this.idleTimer = null;
},
turnOffIdleTimer() {
if (this.idleTimer) {
clearTimeout(this.idleTimer);
}
},
onKeyup() {
if (!this.idleTimer) {
this.$emit('typing-on');
}
this.turnOffIdleTimer();
this.idleTimer = setTimeout(
() => this.resetTyping(),
TYPING_INDICATOR_IDLE_TIME
);
},
onBlur() {
this.turnOffIdleTimer();
this.resetTyping();
this.$emit('blur');
},
onFocus() {

View file

@ -4,8 +4,8 @@
v-model="userInput"
:placeholder="$t('CHAT_PLACEHOLDER')"
class="form-input user-message-input"
@focus="onFocus"
@blur="onBlur"
@typing-off="onTypingOff"
@typing-on="onTypingOn"
/>
<div class="button-wrap">
<chat-attachment-button
@ -111,10 +111,10 @@ export default {
emojiOnClick(emoji) {
this.userInput = `${this.userInput}${emoji} `;
},
onBlur() {
onTypingOff() {
this.toggleTyping('off');
},
onFocus() {
onTypingOn() {
this.toggleTyping('on');
},
toggleTyping(typingStatus) {