feat: Use typing status from utils (#8589)

This commit is contained in:
Sivin Varghese
2023-12-22 13:47:41 +05:30
committed by GitHub
parent f48e014694
commit 78fab7897d
4 changed files with 32 additions and 45 deletions

View File

@@ -17,6 +17,7 @@ import {
removeSignature,
extractTextFromMarkdown,
} from 'dashboard/helper/editorHelper';
import { createTypingIndicator } from '@chatwoot/utils';
const TYPING_INDICATOR_IDLE_TIME = 4000;
export default {
@@ -54,7 +55,15 @@ export default {
},
data() {
return {
idleTimer: null,
typingIndicator: createTypingIndicator(
() => {
this.$emit('typing-on');
},
() => {
this.$emit('typing-off');
},
TYPING_INDICATOR_IDLE_TIME
),
};
},
computed: {
@@ -137,28 +146,11 @@ 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
);
this.typingIndicator.start();
},
onBlur() {
this.turnOffIdleTimer();
this.resetTyping();
this.typingIndicator.stop();
this.$emit('blur');
},
onFocus() {