diff --git a/app/pages/messages/index.vue b/app/pages/messages/index.vue index 06dcafb..8a277ed 100644 --- a/app/pages/messages/index.vue +++ b/app/pages/messages/index.vue @@ -95,7 +95,7 @@ definePageMeta({ const { instances, fetchInstances } = useInstances() -const selectedInstance = ref(null) +const selectedInstance = ref<{ label: string; value: string } | null>(null) const searchQuery = ref('') const selectedChat = ref(null) const chats = ref([]) @@ -113,20 +113,20 @@ const instanceOptions = computed(() => // Auto-select first connected instance watch(instanceOptions, (opts) => { if (opts.length > 0 && !selectedInstance.value) { - selectedInstance.value = opts[0].value + selectedInstance.value = opts[0] } }, { immediate: true }) // Load chats when instance changes -watch(selectedInstance, async (instanceId) => { - if (!instanceId) { +watch(selectedInstance, async (instance) => { + if (!instance?.value) { chats.value = [] return } loadingChats.value = true try { - chats.value = await $fetch(`/api/messages/${instanceId}/chats`) + chats.value = await $fetch(`/api/messages/${instance.value}/chats`) } catch (e) { console.error('Error loading chats:', e) chats.value = [] @@ -137,14 +137,14 @@ watch(selectedInstance, async (instanceId) => { // Load messages when chat changes watch(selectedChat, async (chat) => { - if (!chat || !selectedInstance.value) { + if (!chat || !selectedInstance.value?.value) { messages.value = [] return } loadingMessages.value = true try { - messages.value = await $fetch(`/api/messages/${selectedInstance.value}/${chat.id}`) + messages.value = await $fetch(`/api/messages/${selectedInstance.value.value}/${chat.id}`) } catch (e) { console.error('Error loading messages:', e) messages.value = [] @@ -161,16 +161,16 @@ const filteredChats = computed(() => { }) const handleSendMessage = async (content: string) => { - if (!selectedInstance.value || !selectedChat.value) return + if (!selectedInstance.value?.value || !selectedChat.value) return try { - await $fetch(`/api/messages/${selectedInstance.value}/${selectedChat.value.id}/send`, { + await $fetch(`/api/messages/${selectedInstance.value.value}/${selectedChat.value.id}/send`, { method: 'POST', body: { content } }) // Reload messages - messages.value = await $fetch(`/api/messages/${selectedInstance.value}/${selectedChat.value.id}`) + messages.value = await $fetch(`/api/messages/${selectedInstance.value.value}/${selectedChat.value.id}`) } catch (e) { console.error('Error sending message:', e) }