-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
128 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
frontend/src/components/conversations/ConversationComponent.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<template> | ||
<div class="px-3 py-3 conversations" v-if="currentConversationMessages"> | ||
<div | ||
v-for="conversationMessage in currentConversationMessages" | ||
:key="conversationMessage.id" | ||
class="d-flex mb-3" | ||
:class="{ 'justify-content-end': isCurrentUser(conversationMessage.sender?.id || 0) }" | ||
> | ||
<div | ||
class="card py-2 px-3" | ||
:class="[ | ||
isCurrentUser(conversationMessage.sender?.id || 0) ? 'text-bg-dark' : 'bg-light', | ||
conversationMessage.sender?.id === undefined ? 'ai-chat' : '', | ||
]" | ||
> | ||
<template v-if="conversationMessage.sender?.id === undefined"> | ||
<SvgRobot /> | ||
</template> | ||
{{ formatMessage(conversationMessage.message) }} | ||
</div> | ||
</div> | ||
<div class="chat-controls"> | ||
<form class="row chat-input-container" @submit.prevent="handleSendMessage()"> | ||
<div class="col-md-10"> | ||
<textarea class="w-100" name="Description" v-model="message" /> | ||
</div> | ||
<div class="col-md-1"> | ||
<input | ||
type="submit" | ||
value="Send" | ||
id="chat-button" | ||
class="btn float-btn btn-secondary" | ||
/> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { ref, onMounted, watch } from "vue" | ||
import useLoadingApi from "@/managedApi/useLoadingApi" | ||
import type { User, ConversationMessage } from "@/generated/backend" | ||
import SvgRobot from "@/components/svgs/SvgRobot.vue" | ||
const props = defineProps<{ | ||
conversationId: number | ||
user: User | ||
}>() | ||
const emit = defineEmits<{ | ||
(e: "conversation-fetched", conversationId: number): void | ||
}>() | ||
const { managedApi } = useLoadingApi() | ||
const currentConversationMessages = ref<ConversationMessage[] | undefined>( | ||
undefined | ||
) | ||
const message = ref("") | ||
const formatMessage = (message: string) => { | ||
return message.replace(/^"|"$/g, "").trim() | ||
} | ||
const isCurrentUser = (id: number): boolean => { | ||
return id === props.user?.id | ||
} | ||
const fetchConversationMessages = async () => { | ||
currentConversationMessages.value = | ||
await managedApi.restConversationMessageController.getConversationMessages( | ||
props.conversationId | ||
) | ||
emit("conversation-fetched", props.conversationId) | ||
} | ||
const handleSendMessage = async () => { | ||
await managedApi.restConversationMessageController.replyToConversation( | ||
props.conversationId, | ||
message.value | ||
) | ||
message.value = "" | ||
await fetchConversationMessages() | ||
} | ||
onMounted(() => { | ||
fetchConversationMessages() | ||
}) | ||
watch(() => props.conversationId, fetchConversationMessages) | ||
</script> | ||
<style scoped> | ||
.conversations { | ||
margin-bottom: 100px; | ||
} | ||
.ai-chat { | ||
color: red; | ||
} | ||
.chat-controls { | ||
position: fixed; | ||
width: 75%; | ||
bottom: 0; | ||
right: 0; | ||
background-color: white; | ||
box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1); | ||
padding: 10px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters