@@ -15,19 +15,17 @@ import {
1515 InputGroupButton ,
1616 InputGroupTextarea ,
1717} from ' @/components/ui/input-group' ;
18- import { Badge } from ' @/components/ui/badge'
1918import AppLayout from ' @/layouts/AppLayout.vue' ;
2019import { dashboard , chat } from ' @/routes' ;
2120import { show } from ' @/actions/App/Http/Controllers/FileController' ;
2221import { type BreadcrumbItem } from ' @/types' ;
23- import { Check , Circle , Dot } from ' lucide-vue-next' ;
2422import { Button } from ' @/components/ui/button' ;
2523import { Head , Form , Link } from ' @inertiajs/vue3' ;
2624import { Ellipsis , Trash , ArrowUpIcon } from " lucide-vue-next" ;
2725import { ScrollArea } from ' @/components/ui/scroll-area' ;
2826import store from ' @/actions/App/Http/Controllers/FileChatStoreController' ;
2927import chatDetails from ' @/actions/App/Http/Controllers/FileChatDetailsController' ;
30- import { ref , onMounted , nextTick } from ' vue' ;
28+ import { ref , onMounted , nextTick , watch } from ' vue' ;
3129
3230const props = defineProps <{
3331 file: any ;
@@ -36,8 +34,6 @@ const props = defineProps<{
3634 conversations: any ;
3735}>();
3836
39- const emit = defineEmits ([' addMessage' ]);
40-
4137const disabledButton = ref (false );
4238
4339const scrollAreaRef = ref <{ $el: HTMLElement } | null >(null );
@@ -50,6 +46,12 @@ if(props.messages.data.length > 0 && props.messages.data[props.messages.data.len
5046 disabledButton .value = true ;
5147}
5248
49+ if (props .messages .data .length == 1 && props .messages .data [props .messages .data .length - 1 ].participant === ' user' ) {
50+ isTyping .value = true ;
51+ }
52+
53+ const localMessages = ref (props .messages .data );
54+
5355const isReady = ref (true );
5456
5557const breadcrumbs: BreadcrumbItem [] = [
@@ -81,14 +83,16 @@ const handleError = () => {
8183 console .log (' error' );
8284}
8385
84-
86+ const addNewMessage = (message : any ) => {
87+ localMessages .value .push (message );
88+ }
8589
8690onMounted (() => {
8791 window .Echo .private (` message-created.${props .conversation .data .id } ` )
8892 .listen (' MessageCreated' , async (e ) => {
8993 disabledButton .value = false ;
9094 isTyping .value = false ;
91- props . messages . data . push (e .message );
95+ addNewMessage (e .message );
9296 await nextTick ();
9397 scrollToBottom ();
9498 });
@@ -99,6 +103,14 @@ onMounted(async () => {
99103 await scrollToBottom ();
100104});
101105
106+ watch (
107+ () => props .messages .data ,
108+ (newMessagesData ) => {
109+ localMessages .value = newMessagesData ;
110+ },
111+ { deep: true }
112+ );
113+
102114 </script >
103115
104116
@@ -116,7 +128,7 @@ onMounted(async () => {
116128 <ScrollArea v-show =" isReady" ref =" scrollAreaRef" class =" w-full rounded-md h-[600px] md:h-[350px] p-2 mb-2" >
117129 <div class =" space-y-2" >
118130 <div
119- v-for =" message in messages.data "
131+ v-for =" message in localMessages "
120132 :key =" message.id" class =" flex"
121133 :class =" message.participant === 'user' ? 'justify-end' : 'justify-start'"
122134 >
@@ -126,7 +138,7 @@ onMounted(async () => {
126138 </p >
127139 </div >
128140 </div >
129- <div v-if =" isTyping" class =" relative flex items-center space-x-2 px-2" >
141+ <div v-if =" isTyping" class =" relative flex items-center space-x-2 px-2 mb-4 " >
130142 <span class =" flex h-3 w-3" >
131143 <span class =" animate-ping absolute inline-flex h-3 w-3 rounded-full bg-blue-400 opacity-75" ></span >
132144 <span class =" relative inline-flex rounded-full h-3 w-3 bg-blue-500" ></span >
@@ -146,8 +158,6 @@ onMounted(async () => {
146158 class =" w-full px-1"
147159 #default =" {
148160 processing,
149- errors,
150- reset
151161 }"
152162 >
153163 <InputGroup class =" w-full rounded-3xl" >
0 commit comments