-
+
-
-
-
+
+
diff --git a/src/components/Users/UsersListElement.vue b/src/components/Users/UsersListElement.vue
index 00e4bbd..03688d7 100644
--- a/src/components/Users/UsersListElement.vue
+++ b/src/components/Users/UsersListElement.vue
@@ -33,7 +33,12 @@ const avatarText = computed(() => {
-
+
diff --git a/src/stores/chats.ts b/src/stores/chats.ts
index dd105dd..7fa9a8a 100644
--- a/src/stores/chats.ts
+++ b/src/stores/chats.ts
@@ -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([])
- const selected = ref()
+ const selected = ref([])
- 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 }
})
diff --git a/src/stores/menu.ts b/src/stores/menu.ts
index e98c39e..9541927 100644
--- a/src/stores/menu.ts
+++ b/src/stores/menu.ts
@@ -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('chats')
+ const selected = ref(['chats'])
return { selected }
})
diff --git a/src/stores/sockets.ts b/src/stores/sockets.ts
index afb65e0..a1c27a2 100644
--- a/src/stores/sockets.ts
+++ b/src/stores/sockets.ts
@@ -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)
}
diff --git a/src/views/MainView.vue b/src/views/MainView.vue
index 7929f1e..586a48d 100644
--- a/src/views/MainView.vue
+++ b/src/views/MainView.vue
@@ -21,7 +21,7 @@ onMounted(() => {
-
+