wip
This commit is contained in:
@@ -10,6 +10,7 @@ export interface Chat {
|
||||
name: string
|
||||
users: User[]
|
||||
message?: Message
|
||||
image?: string
|
||||
}
|
||||
|
||||
export const useChatsStore = defineStore('chats', () => {
|
||||
@@ -18,6 +19,8 @@ export const useChatsStore = defineStore('chats', () => {
|
||||
const selected = ref<string[]>([])
|
||||
|
||||
const selectedChat = computed(() => {
|
||||
if (!selected.value.length) return
|
||||
|
||||
return chats.value.find((chat: Chat) => chat.id === selected.value[0])
|
||||
})
|
||||
|
||||
@@ -35,5 +38,9 @@ export const useChatsStore = defineStore('chats', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function getChatLastMessage(chat: Chat) {
|
||||
return chats.value.find((el) => el.id === chat.id)
|
||||
}
|
||||
|
||||
return { chats, selected, selectedChat, getChatInfo }
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useChatsStore } from '@/stores/chats.ts'
|
||||
|
||||
export interface Message {
|
||||
id: number
|
||||
@@ -9,7 +10,13 @@ export interface Message {
|
||||
}
|
||||
|
||||
export const useMessagesStore = defineStore('messages', () => {
|
||||
const chatsStore = useChatsStore()
|
||||
const messages = ref<Message[]>([])
|
||||
const message = ref<Message>()
|
||||
|
||||
return { messages }
|
||||
const lastMessage = computed(() => {
|
||||
return message.value ?? chatsStore.selectedChat?.message ?? null
|
||||
})
|
||||
|
||||
return { messages, lastMessage }
|
||||
})
|
||||
|
||||
@@ -76,7 +76,6 @@ export const useSocketsStore = defineStore('sockets', () => {
|
||||
const idx = chatsStore.chats.findIndex((chat) => chat.id === data.id)
|
||||
if (idx < 0) chatsStore.chats.push(data)
|
||||
|
||||
console.log(data.id)
|
||||
menuStore.selected = ['chats']
|
||||
chatsStore.selected = [data.id]
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface User {
|
||||
id: number
|
||||
email: string
|
||||
name: string
|
||||
image?: string
|
||||
}
|
||||
|
||||
export const useUsersStore = defineStore('users', () => {
|
||||
|
||||
Reference in New Issue
Block a user