From 9aee8d1a1f6e07154c8a515a2d7035f91f80b592 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 17 Mar 2025 17:01:59 +0530 Subject: [PATCH] feat: add separate typing indicator --- .../Conversation/Chips/TypingIndicator.vue | 59 +++++++++++++++++++ .../widgets/conversation/MessagesView.vue | 36 ++--------- app/javascript/dashboard/helper/commons.js | 18 ------ .../dashboard/helper/specs/commons.spec.js | 27 --------- 4 files changed, 63 insertions(+), 77 deletions(-) create mode 100644 app/javascript/dashboard/components-next/Conversation/Chips/TypingIndicator.vue diff --git a/app/javascript/dashboard/components-next/Conversation/Chips/TypingIndicator.vue b/app/javascript/dashboard/components-next/Conversation/Chips/TypingIndicator.vue new file mode 100644 index 000000000..f1955b371 --- /dev/null +++ b/app/javascript/dashboard/components-next/Conversation/Chips/TypingIndicator.vue @@ -0,0 +1,59 @@ + + + diff --git a/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue b/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue index d63be6dc7..00f2289ab 100644 --- a/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue +++ b/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue @@ -10,6 +10,7 @@ import { useMapGetter } from 'dashboard/composables/store'; import ReplyBox from './ReplyBox.vue'; import Message from './Message.vue'; import NextMessageList from 'next/message/MessageList.vue'; +import TypingIndicator from 'next/Conversation/Chips/TypingIndicator.vue'; import ConversationLabelSuggestion from './conversation/LabelSuggestion.vue'; import Banner from 'dashboard/components/ui/Banner.vue'; @@ -21,7 +22,6 @@ import inboxMixin, { INBOX_FEATURES } from 'shared/mixins/inboxMixin'; // utils import { emitter } from 'shared/helpers/mitt'; -import { getTypingUsersText } from '../../../helper/commons'; import { calculateScrollTop } from './helpers/scrollTopCalculationHelper'; import { LocalStorage } from 'shared/helpers/localStorage'; import { @@ -42,6 +42,7 @@ export default { Message, NextMessageList, ReplyBox, + TypingIndicator, Banner, ConversationLabelSuggestion, }, @@ -142,25 +143,6 @@ export default { inbox() { return this.$store.getters['inboxes/getInbox'](this.inboxId); }, - typingUsersList() { - const userList = this.$store.getters[ - 'conversationTypingStatus/getUserList' - ](this.currentChat.id); - return userList; - }, - isAnyoneTyping() { - const userList = this.typingUsersList; - return userList.length !== 0; - }, - typingUserNames() { - const userList = this.typingUsersList; - if (this.isAnyoneTyping) { - const [i18nKey, params] = getTypingUsersText(userList); - return this.$t(i18nKey, params); - } - - return ''; - }, getMessages() { const messages = this.currentChat.messages || []; if (this.isAWhatsAppChannel) { @@ -613,19 +595,9 @@ export default { }" > { return true; }; -export const getTypingUsersText = (users = []) => { - const count = users.length; - const [firstUser, secondUser] = users; - - if (count === 1) { - return ['TYPING.ONE', { user: firstUser.name }]; - } - - if (count === 2) { - return [ - 'TYPING.TWO', - { user: firstUser.name, secondUser: secondUser.name }, - ]; - } - - return ['TYPING.MULTIPLE', { user: firstUser.name, count: count - 1 }]; -}; - export const createPendingMessage = data => { const timestamp = Math.floor(new Date().getTime() / 1000); const tempMessageId = getUuid(); diff --git a/app/javascript/dashboard/helper/specs/commons.spec.js b/app/javascript/dashboard/helper/specs/commons.spec.js index 46065660f..6ded73e94 100644 --- a/app/javascript/dashboard/helper/specs/commons.spec.js +++ b/app/javascript/dashboard/helper/specs/commons.spec.js @@ -1,37 +1,10 @@ import { - getTypingUsersText, createPendingMessage, convertToAttributeSlug, convertToCategorySlug, convertToPortalSlug, } from '../commons'; -describe('#getTypingUsersText', () => { - it('returns the correct text is there is only one typing user', () => { - expect(getTypingUsersText([{ name: 'Pranav' }])).toEqual([ - 'TYPING.ONE', - { user: 'Pranav' }, - ]); - }); - - it('returns the correct text is there are two typing users', () => { - expect( - getTypingUsersText([{ name: 'Pranav' }, { name: 'Nithin' }]) - ).toEqual(['TYPING.TWO', { user: 'Pranav', secondUser: 'Nithin' }]); - }); - - it('returns the correct text is there are more than two users are typing', () => { - expect( - getTypingUsersText([ - { name: 'Pranav' }, - { name: 'Nithin' }, - { name: 'Subin' }, - { name: 'Sojan' }, - ]) - ).toEqual(['TYPING.MULTIPLE', { user: 'Pranav', count: 3 }]); - }); -}); - describe('#createPendingMessage', () => { const message = { message: 'hi',