This commit is contained in:
2026-03-15 20:55:00 +03:00
parent 43366a5089
commit b84a76ac08
16 changed files with 91 additions and 103 deletions

View File

@@ -1,7 +1,8 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { computed, ref } from 'vue'
import type { User } from '@/stores/users.ts'
import type { Message } from '@/stores/messages.ts'
import { useAuthStore } from '@/stores/auth.ts'
export interface Chat {
id: string
@@ -12,8 +13,31 @@ export interface Chat {
}
export const useChatsStore = defineStore('chats', () => {
const authStore = useAuthStore()
const chats = ref<Chat[]>([])
const selected = ref<string>()
const selected = ref<string[]>([])
return { chats, selected }
const selectedChat = computed(() => {
const chatId = selected.value[0]
return chats.value.find((chat: Chat) => {
return chat.id === chatId
})
})
function getChatInfo(chat: Chat) {
switch (chat.typeId) {
case 1:
const user = chat.users.find((user) => {
return user.id !== authStore.me?.id
})
return user ?? chat
case 2:
return chat
default:
return chat
}
}
return { chats, selected, selectedChat, getChatInfo }
})