74
74
<chat-toolbar :partner-id =" partnerId" >
75
75
<template #avatar-toolbar >
76
76
<ChatAvatar
77
+ v-if =" !showSpinner"
77
78
class =" chat-avatar"
78
79
:user-id =" partnerId"
79
80
use-public-key
80
81
@click =" onClickAvatar(partnerId)"
81
82
/>
83
+ <v-progress-circular
84
+ v-else
85
+ class =" connection-spinner ml-1 mr-4"
86
+ indeterminate
87
+ :size =" 32"
88
+ />
82
89
</template >
83
90
</chat-toolbar >
84
91
</template >
@@ -298,6 +305,7 @@ import AChatAttachment from '@/components/AChat/AChatAttachment/AChatAttachment.
298
305
import { useI18n } from ' vue-i18n'
299
306
import { useRouter } from ' vue-router'
300
307
import { useStore } from ' vuex'
308
+ import { useChatsSpinner } from ' @/hooks/useChatsSpinner'
301
309
import ProgressIndicator from ' @/components/ProgressIndicator.vue'
302
310
import { useChatStateStore } from ' @/stores/chat-state'
303
311
@@ -308,7 +316,7 @@ const validationErrors = {
308
316
messageTooLong: ' MESSAGE_LENGTH_EXCEED'
309
317
}
310
318
311
- const { partnerId } = defineProps ({
319
+ const props = defineProps ({
312
320
partnerId: {
313
321
type: String ,
314
322
required: true
@@ -319,10 +327,11 @@ const emit = defineEmits(['click:chat-avatar'])
319
327
const router = useRouter ()
320
328
const store = useStore ()
321
329
const { t } = useI18n ()
330
+ const showSpinner = useChatsSpinner ()
322
331
323
332
const isMenuOpen = ref (false )
324
333
325
- const attachments = useAttachments (partnerId )()
334
+ const attachments = useAttachments (props . partnerId )()
326
335
const handleAttachments = (files : FileData []) => {
327
336
const maxFileSizeExceeded = files .some (({ file }) => file .size >= UPLOAD_MAX_FILE_SIZE )
328
337
const maxFileCountExceeded = attachments .list .length + files .length > UPLOAD_MAX_FILE_COUNT
@@ -367,7 +376,7 @@ const actionsDropdownMessageId = computed({
367
376
set: setActionsDropdownMessageId
368
377
})
369
378
370
- const messages = computed (() => store .getters [' chat/messages' ](partnerId ))
379
+ const messages = computed (() => store .getters [' chat/messages' ](props . partnerId ))
371
380
const userId = computed (() => store .state .address )
372
381
373
382
const getPartnerName = (address : string ) => {
@@ -379,17 +388,19 @@ const getUserMeta = (address: string) => ({
379
388
id: address ,
380
389
name: address === userId .value ? t (' chats.you' ) : getPartnerName (address )
381
390
})
382
- const partners = computed (() => [getUserMeta (userId .value ), getUserMeta (partnerId )])
391
+ const partners = computed (() => [getUserMeta (userId .value ), getUserMeta (props . partnerId )])
383
392
const sendMessageOnEnter = computed <boolean >(() => store .state .options .sendMessageOnEnter )
384
393
const isFulfilled = computed <boolean >(() => store .state .chat .isFulfilled )
385
394
const lastMessage = computed <NormalizedChatMessageTransaction >(() =>
386
- store .getters [' chat/lastMessage' ](partnerId )
395
+ store .getters [' chat/lastMessage' ](props . partnerId )
387
396
)
388
- const chatPage = computed <number >(() => store .getters [' chat/chatPage' ](partnerId ))
397
+ const chatPage = computed <number >(() => store .getters [' chat/chatPage' ](props . partnerId ))
389
398
const scrollPosition = computed <number | false >(() =>
390
- store .getters [' chat/scrollPosition' ](partnerId )
399
+ store .getters [' chat/scrollPosition' ](props .partnerId )
400
+ )
401
+ const numOfNewMessages = computed <number >(() =>
402
+ store .getters [' chat/numOfNewMessages' ](props .partnerId )
391
403
)
392
- const numOfNewMessages = computed <number >(() => store .getters [' chat/numOfNewMessages' ](partnerId ))
393
404
const replyMessage = computed <NormalizedChatMessageTransaction >(() =>
394
405
store .getters [' chat/messageById' ](replyMessageId .value )
395
406
)
@@ -399,6 +410,7 @@ const actionMessage = computed<NormalizedChatMessageTransaction>(() =>
399
410
400
411
const chatFormRef = ref <any >(null ) // @todo type
401
412
const chatRef = ref <any >(null ) // @todo type
413
+
402
414
// Scroll to the bottom every time window focused by desktop notification
403
415
watch (
404
416
() => store .state .notification .desktopActivateClickCount ,
@@ -445,7 +457,7 @@ onMounted(() => {
445
457
if (state === ' visible' && isScrolledToBottom .value ) markAsRead ()
446
458
})
447
459
448
- const draftMessage = store .getters [' draftMessage/draftReplyTold' ](partnerId )
460
+ const draftMessage = store .getters [' draftMessage/draftReplyTold' ](props . partnerId )
449
461
if (draftMessage ) {
450
462
replyMessageId .value = draftMessage
451
463
}
@@ -518,19 +530,19 @@ const cancelReplyMessage = () => {
518
530
replyMessageId .value = - 1
519
531
store .commit (' draftMessage/deleteReplyTold' , {
520
532
replyToId: replyMessageId .value ,
521
- partnerId: partnerId
533
+ partnerId: props . partnerId
522
534
})
523
535
}
524
536
525
537
const sendMessage = (message : string ) => {
526
- store .dispatch (' draftMessage/deleteDraft' , { partnerId: partnerId })
538
+ store .dispatch (' draftMessage/deleteDraft' , { partnerId: props . partnerId })
527
539
const replyToId = replyMessageId .value !== - 1 ? replyMessageId .value : undefined
528
540
529
541
if (attachments .list .length > 0 ) {
530
542
store .dispatch (' chat/sendAttachment' , {
531
543
files: attachments .list ,
532
544
message ,
533
- recipientId: partnerId ,
545
+ recipientId: props . partnerId ,
534
546
replyToId
535
547
})
536
548
@@ -540,7 +552,7 @@ const sendMessage = (message: string) => {
540
552
return store
541
553
.dispatch (' chat/sendMessage' , {
542
554
message ,
543
- recipientId: partnerId ,
555
+ recipientId: props . partnerId ,
544
556
replyToId
545
557
})
546
558
.catch ((err ) => {
@@ -562,7 +574,7 @@ const sendReaction = (reactToId: string, emoji: string) => {
562
574
closeActionsDropdown ()
563
575
emojiWeight .addReaction (emoji )
564
576
return store .dispatch (' chat/sendReaction' , {
565
- recipientId: partnerId ,
577
+ recipientId: props . partnerId ,
566
578
reactToId ,
567
579
reactMessage: emoji
568
580
})
@@ -573,7 +585,7 @@ const removeReaction = (reactToId: string, emoji: string) => {
573
585
closeActionsDropdown ()
574
586
emojiWeight .removeReaction (emoji )
575
587
return store .dispatch (' chat/sendReaction' , {
576
- recipientId: partnerId ,
588
+ recipientId: props . partnerId ,
577
589
reactToId ,
578
590
reactMessage: ' '
579
591
})
@@ -584,7 +596,7 @@ const onEmojiSelect = (transactionId: string, emoji: string) => {
584
596
}
585
597
586
598
const markAsRead = () => {
587
- store .commit (' chat/markAsRead' , partnerId )
599
+ store .commit (' chat/markAsRead' , props . partnerId )
588
600
}
589
601
590
602
const onScrollTop = () => {
@@ -598,7 +610,7 @@ const onScrollBottom = () => {
598
610
const onScroll = (scrollPosition : number , isBottom : boolean ) => {
599
611
isScrolledToBottom .value = isBottom
600
612
store .commit (' chat/updateScrollPosition' , {
601
- contactId: partnerId ,
613
+ contactId: props . partnerId ,
602
614
scrollPosition
603
615
})
604
616
}
@@ -608,14 +620,14 @@ const onClickAvatar = (address: string) => {
608
620
}
609
621
610
622
const onQuotedMessageClick = async (transactionId : string ) => {
611
- let transactionIndex = store .getters [' chat/indexOfMessage' ](partnerId , transactionId )
623
+ let transactionIndex = store .getters [' chat/indexOfMessage' ](props . partnerId , transactionId )
612
624
613
625
// if the message is not present in the store
614
626
// fetch chat history until reach that message
615
627
if (transactionIndex === - 1 ) {
616
628
await fetchUntilFindTransaction (transactionId )
617
629
618
- transactionIndex = store .getters [' chat/indexOfMessage' ](partnerId , transactionId )
630
+ transactionIndex = store .getters [' chat/indexOfMessage' ](props . partnerId , transactionId )
619
631
}
620
632
621
633
// if after fetching chat history the message still cannot be found
@@ -688,7 +700,7 @@ const openReplyPreview = (message: NormalizedChatMessageTransaction) => {
688
700
chatFormRef .value .focus ()
689
701
store .commit (' draftMessage/saveReplyToId' , {
690
702
replyToId: message .id ,
691
- partnerId: partnerId
703
+ partnerId: props . partnerId
692
704
})
693
705
}
694
706
@@ -722,7 +734,7 @@ const openTransaction = (transaction: NormalizedChatMessageTransaction) => {
722
734
},
723
735
query: {
724
736
fromChat: ' true' ,
725
- from: ` /chats/${partnerId } `
737
+ from: ` /chats/${props . partnerId } `
726
738
}
727
739
})
728
740
}
@@ -738,7 +750,7 @@ const fetchChatMessages = () => {
738
750
loading .value = true
739
751
740
752
return store
741
- .dispatch (' chat/getChatRoomMessages' , { contactId: partnerId })
753
+ .dispatch (' chat/getChatRoomMessages' , { contactId: props . partnerId })
742
754
.catch (() => {
743
755
noMoreMessages .value = true
744
756
})
@@ -749,11 +761,14 @@ const fetchChatMessages = () => {
749
761
}
750
762
const fetchUntilFindTransaction = (transactionId : string ) => {
751
763
const fetchMessages = async () => {
752
- await store .dispatch (' chat/getChatRoomMessages' , { contactId: partnerId })
764
+ await store .dispatch (' chat/getChatRoomMessages' , { contactId: props . partnerId })
753
765
754
766
chatRef .value .maintainScrollPosition ()
755
767
756
- const transactionFound = store .getters [' chat/partnerMessageById' ](partnerId , transactionId )
768
+ const transactionFound = store .getters [' chat/partnerMessageById' ](
769
+ props .partnerId ,
770
+ transactionId
771
+ )
757
772
if (transactionFound ) return
758
773
759
774
if (store .state .chat .offset > - 1 ) {
@@ -794,6 +809,9 @@ const onKeyPress = (e: KeyboardEvent) => {
794
809
</script >
795
810
796
811
<style scoped lang="scss">
812
+ @use ' sass:map' ;
813
+ @use ' @/assets/styles/settings/_colors.scss' ;
814
+
797
815
.chat-menu {
798
816
margin-right : 8px ;
799
817
}
@@ -806,4 +824,17 @@ const onKeyPress = (e: KeyboardEvent) => {
806
824
.chat-avatar {
807
825
margin-right : 12px ;
808
826
}
827
+
828
+ /* * Themes **/
829
+ .v-theme--light {
830
+ .connection-spinner {
831
+ color : map .get (colors .$adm-colors , ' grey' );
832
+ }
833
+ }
834
+
835
+ .v-theme--dark {
836
+ .connection-spinner {
837
+ color : map .get (colors .$adm-colors , ' regular' );
838
+ }
839
+ }
809
840
</style >
0 commit comments