This commit is contained in:
2026-03-03 10:41:26 +03:00
parent 944e53df63
commit f925ea1cf1
17 changed files with 271 additions and 261 deletions

10
src/stores/menu.ts Normal file
View File

@@ -0,0 +1,10 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
export type SelectedMenu = 'chats' | 'users' | 'settings'
export const useMenuStore = defineStore('menu', () => {
const selected = ref<SelectedMenu>('chats')
return { selected }
})

View File

@@ -4,6 +4,7 @@ import { type Chat, useChatsStore } from '@/stores/chats.ts'
import { useAuthStore } from '@/stores/auth.ts'
import { type Message, useMessagesStore } from '@/stores/messages.ts'
import { useUsersStore } from '@/stores/users.ts'
import { useMenuStore } from '@/stores/menu.ts'
export enum SocketDataReq {
GET_CHATS = 'GET_CHATS',
@@ -37,6 +38,7 @@ export const useSocketsStore = defineStore('sockets', () => {
const chatsStore = useChatsStore()
const messagesStore = useMessagesStore()
const usersStore = useUsersStore()
const menuStore = useMenuStore()
const isConnected = ref(false)
const error = ref<string>()
@@ -68,10 +70,11 @@ export const useSocketsStore = defineStore('sockets', () => {
if (Array.isArray(data)) {
chatsStore.chats = data
} else {
console.log(data)
const idx = chatsStore.chats.findIndex((chat) => chat.id === data.id)
console.log(idx)
if (idx < 0) chatsStore.chats.push(data)
menuStore.selected = 'chats'
chatsStore.selected = data.id
}
break