wip
This commit is contained in:
@@ -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 }
|
||||
})
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export type SelectedMenu = 'chats' | 'users' | 'settings'
|
||||
export type MenuItems = 'chats' | 'users' | 'settings'
|
||||
|
||||
export const useMenuStore = defineStore('menu', () => {
|
||||
const selected = ref<SelectedMenu>('chats')
|
||||
const selected = ref<MenuItems[]>(['chats'])
|
||||
|
||||
return { selected }
|
||||
})
|
||||
|
||||
@@ -76,8 +76,9 @@ export const useSocketsStore = defineStore('sockets', () => {
|
||||
const idx = chatsStore.chats.findIndex((chat) => chat.id === data.id)
|
||||
if (idx < 0) chatsStore.chats.push(data)
|
||||
|
||||
menuStore.selected = 'chats'
|
||||
chatsStore.selected = data.id
|
||||
console.log(data.id)
|
||||
menuStore.selected = ['chats']
|
||||
chatsStore.selected = [data.id]
|
||||
}
|
||||
|
||||
break
|
||||
@@ -114,6 +115,7 @@ export const useSocketsStore = defineStore('sockets', () => {
|
||||
}
|
||||
|
||||
const send = (data: unknown) => {
|
||||
console.log(COMMAND.SEND, data)
|
||||
postMessage(COMMAND.SEND, data)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user