style: Made the user's first name appear on the chat bubble as well as the selected name for the Ai agent

This commit is contained in:
Lion Arar 2025-10-06 11:28:41 -04:00
parent 4aeafb1087
commit 064f941ca5
6 changed files with 19 additions and 16 deletions

View File

@ -7,14 +7,12 @@ import { useChatStore } from "src/stores/message-store";
const text = ref(''); const text = ref('');
const { messages } = useChatStore(); const { messages } = useChatStore();
const { sendMessage } = useChatApi(); const { sendMessage } = useChatApi();
const handleSend = async () => { const handleSend = async () => {
console.log(`'handleSend' ${text.value}`);
await sendMessage(text.value); await sendMessage(text.value);
text.value = ''; text.value = '';
}; };
</script> </script>
<template> <template>

View File

@ -1,6 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import DialoguePhrase from './dialogue-phrase.vue'; import DialoguePhrase from './dialogue-phrase.vue';
import type { Message } from '../types/dialogue-message'; import type { Message } from '../types/dialogue-message';
import { useAuthStore } from 'src/stores/auth-store';
const authStore = useAuthStore();
const currentUser = authStore.user;
defineProps<{ defineProps<{
messages: Message[]; messages: Message[];
@ -14,6 +18,7 @@ defineProps<{
:key="index" :key="index"
:text="msg.text" :text="msg.text"
:sent="msg.sent" :sent="msg.sent"
:name="msg.sent ? currentUser.firstName : 'AI Assistant'"
/> />
</q-infinite-scroll> </q-infinite-scroll>
</template> </template>

View File

@ -1,14 +1,18 @@
<script setup lang="ts"> <script setup lang="ts">
defineProps<{ const props = defineProps<{
text: string; text: string;
sent: boolean; sent: boolean;
}>(); }>();
</script> </script>
<template> <template>
<q-chat-message :sent="sent" :text="[text]" :bg-color="!sent ? 'secondary' : 'accent'"> <q-chat-message
:sent="props.sent"
:text="[text]"
:bg-color="!sent ? 'secondary' : 'accent'"
>
</q-chat-message> </q-chat-message>
</template> </template>

View File

@ -3,9 +3,9 @@ import { useChatStore } from "src/stores/message-store";
export const useChatApi = () => { export const useChatApi = () => {
const chatStore = useChatStore(); const chatStore = useChatStore();
const sendMessage = async (text: string) => { const sendMessage = async (text: string) => {
await chatStore.sendMessage(text); await chatStore.sendMessage(text);
console.log(`'useChatAPI' ${text}`);
}; };
return { sendMessage }; return { sendMessage };

View File

@ -2,11 +2,10 @@ import type { Message } from "../types/dialogue-message";
import { api } from "src/boot/axios"; import { api } from "src/boot/axios";
export const chatbotService = { export const chatbotService = {
// Function to get the message from the backend
getChatMessage: async (userInput: string): Promise<Message> => { getChatMessage: async (userInput: string): Promise<Message> => {
console.log('messageService'); const response = await api.post("/chat/respond", { userInput });
const response = await api.post('/chat/respond', {userInput}); console.log(response.data);
console.log({userInput});
return response.data as Message; return response.data as Message;
} },
}; };

View File

@ -4,13 +4,10 @@ import { chatbotService } from "src/modules/chatbot/services/messageService";
import { ref } from "vue"; import { ref } from "vue";
export const useChatStore = defineStore("chat", () => { export const useChatStore = defineStore("chat", () => {
const messages = ref<Message[]>([{ text: "test", sent: false }]); const messages = ref<Message[]>([]);
const sendMessage = async (userInput: string) => { const sendMessage = async (userInput: string) => {
console.log(`'useChatStore' ${userInput}`);
const reply = await chatbotService.getChatMessage(userInput); const reply = await chatbotService.getChatMessage(userInput);
messages.value.push({ text: userInput, sent: true }); messages.value.push({ text: userInput, sent: true });
messages.value.push(reply); messages.value.push(reply);
return reply; return reply;