wip
This commit is contained in:
10
src/stores/menu.ts
Normal file
10
src/stores/menu.ts
Normal 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 }
|
||||
})
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user