Compare commits
10 Commits
2cc21bb284
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 09028e0ced | |||
| bc704b03cd | |||
| ad76c710dd | |||
| b84a76ac08 | |||
| 43366a5089 | |||
| 5a188b80e3 | |||
| 24c935df5f | |||
| f925ea1cf1 | |||
| 944e53df63 | |||
| 54fa90b2a5 |
@@ -3,6 +3,9 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="icon" href="/favicon.ico">
|
<link rel="icon" href="/favicon.ico">
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&family=Roboto:ital,wdth@0,75..100;1,75..100&display=swap" rel="stylesheet">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Vite App</title>
|
<title>Vite App</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
791
package-lock.json
generated
791
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -15,10 +15,16 @@
|
|||||||
"format": "prettier --write --experimental-cli src/"
|
"format": "prettier --write --experimental-cli src/"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/roboto": "^5.2.9",
|
"@primeuix/themes": "^2.0.3",
|
||||||
|
"@tailwindcss/vite": "^4.2.1",
|
||||||
|
"@vueuse/core": "^14.2.1",
|
||||||
"pinia": "^3.0.4",
|
"pinia": "^3.0.4",
|
||||||
|
"primeicons": "^7.0.0",
|
||||||
|
"primevue": "^4.5.4",
|
||||||
|
"tailwindcss": "^4.2.1",
|
||||||
|
"tailwindcss-primeui": "^0.6.1",
|
||||||
"vue": "^3.5.28",
|
"vue": "^3.5.28",
|
||||||
"vuetify": "^3.11.8"
|
"vuetify": "^4.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@mdi/font": "^7.4.47",
|
"@mdi/font": "^7.4.47",
|
||||||
|
|||||||
23
src/App.vue
23
src/App.vue
@@ -1,25 +1,18 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import ChatView from '@/views/ChatView.vue'
|
|
||||||
import { useAuthStore } from '@/stores/auth.ts'
|
import { useAuthStore } from '@/stores/auth.ts'
|
||||||
import SignInView from '@/views/SignInView.vue'
|
import SignInView from '@/views/SignInView.vue'
|
||||||
|
import MainView from '@/views/MainView.vue'
|
||||||
|
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<v-app>
|
<div class="h-screen bg-gray-500">
|
||||||
<v-main class="chat-fullscreen">
|
<div class="h-full m-auto py-4 md:w-full sm:w-full w-full">
|
||||||
<v-container fluid class="h-100 pa-0">
|
<MainView v-if="authStore.isAuth" />
|
||||||
<chat-view v-if="authStore.isAuth" />
|
<SignInView v-else />
|
||||||
<sign-in-view v-else />
|
</div>
|
||||||
<!-- <sign-in-view />-->
|
</div>
|
||||||
</v-container>
|
|
||||||
</v-main>
|
|
||||||
</v-app>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style></style>
|
||||||
.chat-fullscreen {
|
|
||||||
height: 100vh;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
9
src/assets/main.css
Normal file
9
src/assets/main.css
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
|
|
||||||
|
html {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 400;
|
||||||
|
font-family: "Montserrat", sans-serif;
|
||||||
|
font-optical-sizing: auto;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
13
src/assets/main_.css
Normal file
13
src/assets/main_.css
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
|
@import "tailwindcss-primeui";
|
||||||
|
@import "primeicons/primeicons.css";
|
||||||
|
|
||||||
|
html {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 400;
|
||||||
|
font-family: "Montserrat", sans-serif;
|
||||||
|
font-optical-sizing: auto;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-component, .p-component * {}
|
||||||
22
src/components/AppMenu.vue
Normal file
22
src/components/AppMenu.vue
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { JustList, JustListItem, JustNav } from '@/components/simple'
|
||||||
|
import { type SelectedMenu, useMenuStore } from '@/stores/menu.ts'
|
||||||
|
|
||||||
|
const menuStore = useMenuStore()
|
||||||
|
|
||||||
|
function onSelect(value: SelectedMenu) {
|
||||||
|
menuStore.selected = value
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<JustNav>
|
||||||
|
<JustList>
|
||||||
|
<JustListItem value="users" icon="mdi-account" @click="onSelect" />
|
||||||
|
<JustListItem value="chats" icon="mdi-message" @click="onSelect" />
|
||||||
|
<JustListItem value="settings" icon="mdi-cog" @click="onSelect" />
|
||||||
|
</JustList>
|
||||||
|
</JustNav>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
16
src/components/BackToChats.vue
Normal file
16
src/components/BackToChats.vue
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useMenuStore } from '@/stores/menu.ts'
|
||||||
|
|
||||||
|
const menuStore = useMenuStore()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VBtn
|
||||||
|
icon="mdi-arrow-left"
|
||||||
|
color="default"
|
||||||
|
size="small"
|
||||||
|
@click="menuStore.selected = ['chats']"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { type Chat, useChatsStore } from '@/stores/chats.ts'
|
|
||||||
import { SocketDataReq, useSocketsStore } from '@/stores/sockets.ts'
|
|
||||||
import { useAuthStore } from '@/stores/auth.ts'
|
|
||||||
|
|
||||||
const authStore = useAuthStore()
|
|
||||||
const chatsStore = useChatsStore()
|
|
||||||
const socketsStore = useSocketsStore()
|
|
||||||
|
|
||||||
function onSelect(value: { id: unknown }) {
|
|
||||||
console.log('onSelectChat', value.id)
|
|
||||||
|
|
||||||
const chatId = value.id as string
|
|
||||||
chatsStore.selected = chatId
|
|
||||||
|
|
||||||
socketsStore.send({
|
|
||||||
type: SocketDataReq.GET_MESSAGES,
|
|
||||||
data: { chat_id: chatId },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function getChatName(chat: Chat) {
|
|
||||||
if (chat.type_id === 2) {
|
|
||||||
return chat.name
|
|
||||||
} else if (chat.type_id === 1) {
|
|
||||||
const otherUsers = chat.users.filter((user) => user.id !== authStore.me?.id)
|
|
||||||
return otherUsers[0]?.name ?? otherUsers[0]?.email ?? 'unknown'
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'unknown ID'
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<v-list theme="dark" density="compact" lines="two" @click:select="onSelect">
|
|
||||||
<v-list-subheader>Чаты</v-list-subheader>
|
|
||||||
<v-list-item
|
|
||||||
v-for="chat in chatsStore.chats"
|
|
||||||
:key="chat.id"
|
|
||||||
:value="chat.id"
|
|
||||||
subtitle="last message..."
|
|
||||||
>
|
|
||||||
<template v-slot:title>{{ getChatName(chat) }} </template>
|
|
||||||
<template v-slot:prepend>
|
|
||||||
<v-avatar color="grey-lighten-1" text="V"> </v-avatar>
|
|
||||||
</template>
|
|
||||||
<template v-slot:append>
|
|
||||||
<div class="d-flex flex-column align-end">
|
|
||||||
<v-chip density="compact" size="small">0</v-chip>
|
|
||||||
<div class="text-caption">00:00</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</v-list-item>
|
|
||||||
</v-list>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref } from 'vue'
|
|
||||||
|
|
||||||
const search = ref('')
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="d-flex align-center ga-4">
|
|
||||||
<v-btn icon="mdi-menu" variant="text"></v-btn>
|
|
||||||
<v-text-field
|
|
||||||
v-model="search"
|
|
||||||
rounded="xl"
|
|
||||||
density="compact"
|
|
||||||
hide-details
|
|
||||||
variant="outlined"
|
|
||||||
bg-color="black"
|
|
||||||
base-color="black"
|
|
||||||
color="primary"
|
|
||||||
placeholder="Search..."
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
58
src/components/Chats/ChatListElement.vue
Normal file
58
src/components/Chats/ChatListElement.vue
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { type Chat, useChatsStore } from '@/stores/chats.ts'
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { useMessagesStore } from '@/stores/messages.ts'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
chat: Chat
|
||||||
|
}
|
||||||
|
|
||||||
|
const { chat } = defineProps<Props>()
|
||||||
|
const chatsStore = useChatsStore()
|
||||||
|
|
||||||
|
const chatInfo = computed(() => {
|
||||||
|
return chatsStore.getChatInfo(chat)
|
||||||
|
})
|
||||||
|
|
||||||
|
const convertDate = (dateString: string) => {
|
||||||
|
const date = new Date(dateString)
|
||||||
|
return date.toLocaleTimeString('ru-RU', { timeStyle: 'short' })
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VListItem :value="chat.id">
|
||||||
|
<template v-slot:prepend>
|
||||||
|
<VAvatar color="primary" :text="chatInfo?.name.slice(0, 1).toUpperCase()" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #title>
|
||||||
|
<div class="flex justify-between">
|
||||||
|
<div class="font-medium truncate">
|
||||||
|
{{ chatInfo.name }}
|
||||||
|
</div>
|
||||||
|
<div v-if="chat.message" class="text-xs">
|
||||||
|
{{ convertDate(chat.message.createdAt) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-if="chat.message" #subtitle>
|
||||||
|
<div class="flex justify-between">
|
||||||
|
<div>{{ chat.message.message }}</div>
|
||||||
|
<div class="text-xs">
|
||||||
|
<!-- <VChip v-show="true" size="small" text="0" />-->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- <template v-slot:append>-->
|
||||||
|
<!-- <div class="flex flex-col">-->
|
||||||
|
<!-- <div class="text-sm">{{ lastMessageCreatedAt }}</div>-->
|
||||||
|
<!-- <VChip v-show="true" size="small">0</VChip>-->
|
||||||
|
<!-- </div>-->
|
||||||
|
<!-- </template>-->
|
||||||
|
</VListItem>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
14
src/components/Chats/ChatToolbar.vue
Normal file
14
src/components/Chats/ChatToolbar.vue
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
const search = ref('')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex gap-2 p-4 border bg-amber-200">
|
||||||
|
<button>menu</button>
|
||||||
|
<input v-model="search" placeholder="Search..." />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
56
src/components/Chats/ChatsList.vue
Normal file
56
src/components/Chats/ChatsList.vue
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useChatsStore } from '@/stores/chats.ts'
|
||||||
|
import { SocketDataReq, useSocketsStore } from '@/stores/sockets.ts'
|
||||||
|
import { watchEffect } from 'vue'
|
||||||
|
import { useMenuStore } from '@/stores/menu.ts'
|
||||||
|
import ChatListElement from '@/components/Chats/ChatListElement.vue'
|
||||||
|
|
||||||
|
const chatsStore = useChatsStore()
|
||||||
|
const socketsStore = useSocketsStore()
|
||||||
|
const menuStore = useMenuStore()
|
||||||
|
|
||||||
|
watchEffect(() => getMessages(chatsStore.selected))
|
||||||
|
|
||||||
|
function getMessages([selected]: string[]) {
|
||||||
|
if (selected) {
|
||||||
|
socketsStore.send({
|
||||||
|
type: SocketDataReq.GET_MESSAGES,
|
||||||
|
data: { chatId: selected },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col h-full">
|
||||||
|
<VToolbar theme="dark" class="px-2">
|
||||||
|
<VMenu transition="slide-y-transition">
|
||||||
|
<template v-slot:activator="{ props }">
|
||||||
|
<VBtn size="small" icon="mdi-menu" class="mr-2" color="white" v-bind="props" />
|
||||||
|
</template>
|
||||||
|
<VList
|
||||||
|
class="top-1"
|
||||||
|
width="200"
|
||||||
|
density="compact"
|
||||||
|
slim
|
||||||
|
v-model:selected="menuStore.selected"
|
||||||
|
>
|
||||||
|
<VListItem class="pa-0">
|
||||||
|
<div class="bg-amber-600 flex justify-center">HELLO WORLD</div>
|
||||||
|
</VListItem>
|
||||||
|
<VListItem value="users" title="Contacts" prepend-icon="mdi-account" />
|
||||||
|
<VListItem value="settings" title="Settings" prepend-icon="mdi-cog" />
|
||||||
|
<VDivider class="my-1" />
|
||||||
|
<VListItem value="logout" title="Log Out" prepend-icon="mdi-logout" />
|
||||||
|
</VList>
|
||||||
|
</VMenu>
|
||||||
|
|
||||||
|
<VTextField bg-color="black" prepend-inner-icon="mdi-magnify" placeholder="search chat" />
|
||||||
|
</VToolbar>
|
||||||
|
<VList theme="dark" v-model:selected="chatsStore.selected" mandatory lines="one">
|
||||||
|
<ChatListElement v-for="chat in chatsStore.chats" :key="chat.id" :chat />
|
||||||
|
</VList>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import ChatToolbar from '@/components/ChatToolbar.vue'
|
|
||||||
import ChatList from '@/components/ChatList.vue'
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<v-sheet class="pa-4 d-flex flex-column h-100" theme="dark">
|
|
||||||
<chat-toolbar />
|
|
||||||
<chat-list />
|
|
||||||
</v-sheet>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
30
src/components/LeftPane.vue
Normal file
30
src/components/LeftPane.vue
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useMenuStore } from '@/stores/menu.ts'
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import ChatsList from '@/components/Chats/ChatsList.vue'
|
||||||
|
import UsersList from '@/components/Users/UsersList.vue'
|
||||||
|
import SettingsList from '@/components/Settings/SettingsList.vue'
|
||||||
|
|
||||||
|
const menuStore = useMenuStore()
|
||||||
|
|
||||||
|
const component = computed(() => {
|
||||||
|
switch (menuStore.selected[0]) {
|
||||||
|
case 'chats':
|
||||||
|
return ChatsList
|
||||||
|
case 'users':
|
||||||
|
return UsersList
|
||||||
|
case 'settings':
|
||||||
|
return SettingsList
|
||||||
|
default:
|
||||||
|
return ChatsList
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col h-full gap-2">
|
||||||
|
<slot :component="component" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { computed, ref } from 'vue'
|
|
||||||
import { SocketDataReq, useSocketsStore } from '@/stores/sockets.ts'
|
|
||||||
import { useChatsStore } from '@/stores/chats.ts'
|
|
||||||
|
|
||||||
const socketsStore = useSocketsStore()
|
|
||||||
const chatsStore = useChatsStore()
|
|
||||||
|
|
||||||
const text = ref('')
|
|
||||||
|
|
||||||
const sendMessage = () => {
|
|
||||||
if (text.value.trim()) {
|
|
||||||
socketsStore.send({
|
|
||||||
type: SocketDataReq.CREATE_MESSAGE,
|
|
||||||
data: {
|
|
||||||
chat_id: chatsStore.selected,
|
|
||||||
text: text.value,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
text.value = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
const isEmptyText = computed(() => {
|
|
||||||
return !text.value
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<v-row dense align="center">
|
|
||||||
<v-col>
|
|
||||||
<v-text-field
|
|
||||||
rounded="lg"
|
|
||||||
bg-color="white"
|
|
||||||
variant="outlined"
|
|
||||||
hide-details
|
|
||||||
label="Message"
|
|
||||||
v-model="text"
|
|
||||||
@keyup.enter="sendMessage"
|
|
||||||
>
|
|
||||||
<template v-slot:prepend-inner>
|
|
||||||
<v-btn icon variant="text" density="compact" color="grey-darken-1">
|
|
||||||
<v-icon>mdi-emoticon-outline</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</template>
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
|
|
||||||
<v-col v-if="false" cols="auto">
|
|
||||||
<v-btn icon variant="text" color="grey-darken-1">
|
|
||||||
<v-icon>mdi-paperclip</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</v-col>
|
|
||||||
|
|
||||||
<v-col cols="auto">
|
|
||||||
<v-btn :disabled="isEmptyText" icon variant="flat" color="primary" @click="sendMessage">
|
|
||||||
<v-icon>mdi-send</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<script setup lang="ts"></script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<v-toolbar color="white" class="flex-grow-0 px-4">
|
|
||||||
<v-avatar color="grey-lighten-1" text="V"></v-avatar>
|
|
||||||
<v-toolbar-title class="">name</v-toolbar-title>
|
|
||||||
</v-toolbar>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
45
src/components/Messages/MessageInput.vue
Normal file
45
src/components/Messages/MessageInput.vue
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { SocketDataReq, useSocketsStore } from '@/stores/sockets.ts'
|
||||||
|
import { useChatsStore } from '@/stores/chats.ts'
|
||||||
|
|
||||||
|
const socketsStore = useSocketsStore()
|
||||||
|
const chatsStore = useChatsStore()
|
||||||
|
|
||||||
|
const message = ref('')
|
||||||
|
|
||||||
|
const sendMessage = () => {
|
||||||
|
if (message.value && chatsStore.selectedChat) {
|
||||||
|
socketsStore.send({
|
||||||
|
type: SocketDataReq.CREATE_MESSAGE,
|
||||||
|
data: {
|
||||||
|
chatId: chatsStore.selectedChat.id,
|
||||||
|
message: message.value.trim().slice(0, 200),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
message.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const isEmptyText = computed(() => {
|
||||||
|
return !message.value
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex gap-2 pa-2 items-center">
|
||||||
|
<VTextField
|
||||||
|
prepend-inner-icon="mdi-emoticon-outline"
|
||||||
|
append-inner-icon="mdi-paperclip"
|
||||||
|
bg-color="white"
|
||||||
|
v-model="message"
|
||||||
|
placeholder="message"
|
||||||
|
density="default"
|
||||||
|
@keyup.enter="sendMessage"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<VBtn :disabled="isEmptyText" icon="mdi-send" @click="sendMessage" color="primary" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -1,23 +1,27 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
|
||||||
const props = withDefaults(
|
interface Props {
|
||||||
defineProps<{ createdAt?: string; username?: string; my?: boolean; text?: string }>(),
|
createdAt?: string
|
||||||
{
|
username?: string
|
||||||
my: false,
|
onRightSide?: boolean
|
||||||
text: 'foobar',
|
message?: string
|
||||||
username: 'robot',
|
}
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
const createdAt = computed(() => {
|
const { message, username, createdAt } = withDefaults(defineProps<Props>(), {
|
||||||
return props.createdAt
|
my: false,
|
||||||
? new Date(props.createdAt).toLocaleTimeString('ru-RU', { timeStyle: 'short' })
|
message: 'foobar',
|
||||||
|
username: 'robot',
|
||||||
|
})
|
||||||
|
|
||||||
|
const messageDate = computed(() => {
|
||||||
|
return createdAt
|
||||||
|
? new Date(createdAt).toLocaleTimeString('ru-RU', { timeStyle: 'short' })
|
||||||
: new Date().toLocaleTimeString('ru-RU', { timeStyle: 'short' })
|
: new Date().toLocaleTimeString('ru-RU', { timeStyle: 'short' })
|
||||||
})
|
})
|
||||||
|
|
||||||
const avatarLetter = computed(() => {
|
const avatarLetter = computed(() => {
|
||||||
return props.username.slice(0, 1).toUpperCase()
|
return username.slice(0, 1).toUpperCase()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -35,29 +39,17 @@ const avatarLetter = computed(() => {
|
|||||||
<!-- </div>-->
|
<!-- </div>-->
|
||||||
<!-- </div>-->
|
<!-- </div>-->
|
||||||
|
|
||||||
<v-sheet color="transparent" class="d-flex ga-2" :class="{ 'flex-row-reverse': props.my }">
|
<div class="flex gap-2" :class="{ 'flex-row-reverse': onRightSide }">
|
||||||
<!-- <v-avatar size="36" color="deep-purple-lighten-4">-->
|
<!-- <v-avatar size="36" color="deep-purple-lighten-4">-->
|
||||||
<!-- <span class="text-deep-purple-darken-2">{{ avatarLetter }}</span>-->
|
<!-- <span class="text-deep-purple-darken-2">{{ avatarLetter }}</span>-->
|
||||||
<!-- </v-avatar>-->
|
<!-- </v-avatar>-->
|
||||||
|
|
||||||
<!-- :class="props.my ? 'message-shaped-right' : 'message-shaped'"-->
|
<!-- :class="props.my ? 'message-shaped-right' : 'message-shaped'"-->
|
||||||
<v-sheet class="pa-4 message-width rounded-lg" :color="props.my ? 'primary' : 'white'">
|
<div class="flex gap-1 pa-4" :class="onRightSide ? 'bg-blue-400' : 'bg-white'">
|
||||||
<span class="text-body-1">{{ props.text }}</span>
|
<span class="">{{ message }}</span>
|
||||||
<span class="text-caption ml-2">{{ createdAt }}</span>
|
<span class="text-xs self-end">{{ messageDate }}</span>
|
||||||
</v-sheet>
|
</div>
|
||||||
</v-sheet>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped></style>
|
||||||
.message-shaped {
|
|
||||||
border-radius: 0 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-shaped-right {
|
|
||||||
border-radius: 24px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-width {
|
|
||||||
max-width: 66%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
17
src/components/Messages/MessageToolbar.vue
Normal file
17
src/components/Messages/MessageToolbar.vue
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
interface Props {
|
||||||
|
name?: string
|
||||||
|
image?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const { name, image } = defineProps<Props>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VToolbar theme="dark" class="px-2">
|
||||||
|
<VAvatar :text="name?.slice(0, 1).toUpperCase()" color="primary" />
|
||||||
|
<VToolbarTitle :text="name" />
|
||||||
|
</VToolbar>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
12
src/components/Messages/MessagesList.vue
Normal file
12
src/components/Messages/MessagesList.vue
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import MessageData from '@/components/Messages/MessageData.vue'
|
||||||
|
import type { Message } from '@/stores/messages.ts'
|
||||||
|
|
||||||
|
const { messages } = defineProps<{ messages: Message[] }>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<MessageData v-for="message in messages" :key="message.id" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
45
src/components/Messages/MessagesWrapper.vue
Normal file
45
src/components/Messages/MessagesWrapper.vue
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'
|
||||||
|
import { useScroll } from '@vueuse/core'
|
||||||
|
import type { User } from '@/stores/users.ts'
|
||||||
|
import { useChatsStore } from '@/stores/chats.ts'
|
||||||
|
import { useMessagesStore } from '@/stores/messages.ts'
|
||||||
|
|
||||||
|
const chatsStore = useChatsStore()
|
||||||
|
const messagesStore = useMessagesStore()
|
||||||
|
|
||||||
|
// const area = useTemplateRef('messageArea')
|
||||||
|
// const { y, arrivedState } = useScroll(area)
|
||||||
|
// const messages = computed(() => {
|
||||||
|
// return [...messagesStore.messages]
|
||||||
|
// })
|
||||||
|
// async function scrollToBottom() {
|
||||||
|
// await nextTick()
|
||||||
|
// if (area.value) y.value = area.value?.scrollHeight
|
||||||
|
// }
|
||||||
|
|
||||||
|
const chatInfo = computed(() => {
|
||||||
|
if (chatsStore.selectedChat) {
|
||||||
|
return chatsStore.getChatInfo(chatsStore.selectedChat)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
const messages = ref([])
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex h-full flex-col overflow-hidden">
|
||||||
|
<div class="grow-0" v-if="chatsStore.selectedChat">
|
||||||
|
<slot name="toolbar" :info="chatInfo" />
|
||||||
|
</div>
|
||||||
|
<div class="px-8 gap-2 grow flex flex-col-reverse overflow-y-auto" ref="messageArea">
|
||||||
|
<slot :messages="messagesStore.messages" />
|
||||||
|
</div>
|
||||||
|
<div class="grow-0">
|
||||||
|
<slot name="input" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import MessageToolbar from '@/components/MessageToolbar.vue'
|
|
||||||
import MessageForm from '@/components/MessageForm.vue'
|
|
||||||
import MessageData from '@/components/MessageData.vue'
|
|
||||||
import { useMessagesStore } from '@/stores/messages.ts'
|
|
||||||
import { useAuthStore } from '@/stores/auth.ts'
|
|
||||||
import { computed } from 'vue'
|
|
||||||
|
|
||||||
const authStore = useAuthStore()
|
|
||||||
const messagesStore = useMessagesStore()
|
|
||||||
|
|
||||||
const messages = computed(() => {
|
|
||||||
return [...messagesStore.messages]
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="h-100 d-flex flex-column">
|
|
||||||
<message-toolbar />
|
|
||||||
|
|
||||||
<v-card
|
|
||||||
rounded="0"
|
|
||||||
variant="flat"
|
|
||||||
color="grey-lighten-3"
|
|
||||||
class="flex-grow-1 d-flex flex-column overflow-hidden"
|
|
||||||
>
|
|
||||||
<v-card-text class="flex-grow-1 d-flex ga-1 flex-column overflow-y-auto justify-end">
|
|
||||||
<message-data
|
|
||||||
v-for="message in messages"
|
|
||||||
:key="message.id"
|
|
||||||
:text="message.text"
|
|
||||||
:my="authStore.me?.id === message.user_id"
|
|
||||||
:created-at="message.created_at"
|
|
||||||
/>
|
|
||||||
</v-card-text>
|
|
||||||
|
|
||||||
<v-card-actions class="flex-grow-0 bg-white pa-4">
|
|
||||||
<message-form />
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
37
src/components/RightPane.vue
Normal file
37
src/components/RightPane.vue
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import MessageToolbar from '@/components/Messages/MessageToolbar.vue'
|
||||||
|
import MessageInput from '@/components/Messages/MessageInput.vue'
|
||||||
|
import { useChatsStore } from '@/stores/chats.ts'
|
||||||
|
import MessageItem from '@/components/Messages/MessageItem.vue'
|
||||||
|
import MessagesWrapper from '@/components/Messages/MessagesWrapper.vue'
|
||||||
|
|
||||||
|
const chatsStore = useChatsStore()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="h-full bg-gray-100">
|
||||||
|
<div class="flex flex-col h-full">
|
||||||
|
<MessagesWrapper v-if="chatsStore.selectedChat">
|
||||||
|
<template #toolbar="{ info }">
|
||||||
|
<MessageToolbar v-bind="info" />
|
||||||
|
</template>
|
||||||
|
<template #default="{ messages }">
|
||||||
|
<MessageItem v-for="message in messages" :key="message.id" v-bind="message" />
|
||||||
|
</template>
|
||||||
|
<template #input>
|
||||||
|
<MessageInput />
|
||||||
|
</template>
|
||||||
|
</MessagesWrapper>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.scroll-down {
|
||||||
|
right: 16px;
|
||||||
|
bottom: 104px;
|
||||||
|
}
|
||||||
|
.test {
|
||||||
|
height: 400px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
5
src/components/Settings/SettingsList.vue
Normal file
5
src/components/Settings/SettingsList.vue
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<script setup lang="ts"></script>
|
||||||
|
|
||||||
|
<template>2</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
50
src/components/Users/UsersList.vue
Normal file
50
src/components/Users/UsersList.vue
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SocketDataReq, useSocketsStore } from '@/stores/sockets.ts'
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
import { useUsersStore } from '@/stores/users.ts'
|
||||||
|
import UsersListElement from '@/components/Users/UsersListElement.vue'
|
||||||
|
import { useAuthStore } from '@/stores/auth.ts'
|
||||||
|
import BackToChats from '@/components/BackToChats.vue'
|
||||||
|
|
||||||
|
const socketsStore = useSocketsStore()
|
||||||
|
const usersStore = useUsersStore()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
socketsStore.send({
|
||||||
|
type: SocketDataReq.GET_USERS,
|
||||||
|
data: {},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function onStartChat(userId: number) {
|
||||||
|
console.log('user', userId)
|
||||||
|
console.log('me', authStore.me?.id)
|
||||||
|
|
||||||
|
socketsStore.send({
|
||||||
|
type: SocketDataReq.CREATE_CHAT,
|
||||||
|
data: { userId: userId },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col h-full">
|
||||||
|
<VToolbar theme="dark" class="px-2">
|
||||||
|
<BackToChats class="mr-2" />
|
||||||
|
|
||||||
|
<VTextField bg-color="black" prepend-inner-icon="mdi-magnify" placeholder="search contacts" />
|
||||||
|
</VToolbar>
|
||||||
|
|
||||||
|
<VList>
|
||||||
|
<UsersListElement
|
||||||
|
v-for="user in usersStore.users"
|
||||||
|
:key="user.id"
|
||||||
|
v-bind:user="user"
|
||||||
|
@click="onStartChat"
|
||||||
|
/>
|
||||||
|
</VList>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
46
src/components/Users/UsersListElement.vue
Normal file
46
src/components/Users/UsersListElement.vue
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { User } from '@/stores/users.ts'
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
user: User
|
||||||
|
}
|
||||||
|
|
||||||
|
const { user } = defineProps<Props>()
|
||||||
|
const emit = defineEmits<{
|
||||||
|
click: [id: number]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const avatarText = computed(() => {
|
||||||
|
return user.name.slice(0, 1).toUpperCase() ?? ':)'
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VListItem>
|
||||||
|
<template v-slot:prepend>
|
||||||
|
<VAvatar color="primary" :text="avatarText" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #title>
|
||||||
|
<div>
|
||||||
|
{{ user.name }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #subtitle>
|
||||||
|
<div>last seen never recently</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #append>
|
||||||
|
<VBtn
|
||||||
|
icon="mdi-message-outline"
|
||||||
|
variant="plain"
|
||||||
|
size="small"
|
||||||
|
@click="emit('click', user.id)"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</VListItem>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref } from 'vue'
|
|
||||||
|
|
||||||
const message = ref('')
|
|
||||||
const selectedChat = ref('')
|
|
||||||
|
|
||||||
// const { messages, chats, isConnected, error, send } = useSharedWebSocket({
|
|
||||||
// onMessage: (data) => {
|
|
||||||
// console.log('Received message:', data)
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
|
|
||||||
const onChatClick = (id: string) => {
|
|
||||||
console.log(id)
|
|
||||||
selectedChat.value = id
|
|
||||||
// send({
|
|
||||||
// type: WsDataType.GET_MESSAGES,
|
|
||||||
// data: { chat_id: id },
|
|
||||||
// })
|
|
||||||
}
|
|
||||||
|
|
||||||
const sendMessage = () => {
|
|
||||||
if (message.value.trim()) {
|
|
||||||
// send({
|
|
||||||
// type: WsDataType.CREATE_MESSAGE,
|
|
||||||
// data: {
|
|
||||||
// chat_id: selectedChat.value,
|
|
||||||
// text: message.value,
|
|
||||||
// },
|
|
||||||
})
|
|
||||||
message.value = ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<v-row>
|
|
||||||
<v-col>
|
|
||||||
<!-- <div class="status" :class="{ isConnected, disconnected: !isConnected }">-->
|
|
||||||
<!-- status: {{ isConnected ? 'connected' : 'disconnected' }}-->
|
|
||||||
<!-- </div>-->
|
|
||||||
<div>selected chat {{ selectedChat }}</div>
|
|
||||||
<!-- <div class="error">Error: {{ error }}</div>-->
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col>
|
|
||||||
<div>
|
|
||||||
<!-- <div v-for="chat in chats" :key="chat.id" @click="onChatClick(chat.id)">-->
|
|
||||||
<!-- <div>{{ chat.id }}</div>-->
|
|
||||||
<!-- <div>{{ chat.users }}</div>-->
|
|
||||||
<!-- </div>-->
|
|
||||||
</div>
|
|
||||||
</v-col>
|
|
||||||
<v-col>
|
|
||||||
<v-sheet border class="pa-4 border-opacity-50">
|
|
||||||
<div v-if="selectedChat">
|
|
||||||
<v-sheet height="400px" class="overflow-y-auto">
|
|
||||||
<!-- <div v-for="message in messages" :key="message.id">-->
|
|
||||||
<!-- <div>{{ message }}</div>-->
|
|
||||||
<!-- </div>-->
|
|
||||||
</v-sheet>
|
|
||||||
|
|
||||||
<div class="d-flex align-center ga-1">
|
|
||||||
<v-text-field
|
|
||||||
rounded="lg"
|
|
||||||
hide-details
|
|
||||||
variant="outlined"
|
|
||||||
v-model="message"
|
|
||||||
@keyup.enter="sendMessage"
|
|
||||||
placeholder="Type message..."
|
|
||||||
>
|
|
||||||
</v-text-field>
|
|
||||||
<!-- <v-btn-->
|
|
||||||
<!-- :disabled="!isConnected"-->
|
|
||||||
<!-- variant="elevated"-->
|
|
||||||
<!-- color="primary"-->
|
|
||||||
<!-- icon="mdi-send"-->
|
|
||||||
<!-- @click="sendMessage"-->
|
|
||||||
<!-- />-->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</v-sheet>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
459
src/composables/useLayout.ts
Normal file
459
src/composables/useLayout.ts
Normal file
@@ -0,0 +1,459 @@
|
|||||||
|
import { updatePrimaryPalette, updateSurfacePalette } from '@primeuix/themes'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
const appState = ref({
|
||||||
|
primary: 'black',
|
||||||
|
surface: '',
|
||||||
|
darkMode: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
const primaryColors = ref([
|
||||||
|
{
|
||||||
|
name: 'emerald',
|
||||||
|
palette: {
|
||||||
|
50: '#ecfdf5',
|
||||||
|
100: '#d1fae5',
|
||||||
|
200: '#a7f3d0',
|
||||||
|
300: '#6ee7b7',
|
||||||
|
400: '#34d399',
|
||||||
|
500: '#10b981',
|
||||||
|
600: '#059669',
|
||||||
|
700: '#047857',
|
||||||
|
800: '#065f46',
|
||||||
|
900: '#064e3b',
|
||||||
|
950: '#022c22',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'green',
|
||||||
|
palette: {
|
||||||
|
50: '#f0fdf4',
|
||||||
|
100: '#dcfce7',
|
||||||
|
200: '#bbf7d0',
|
||||||
|
300: '#86efac',
|
||||||
|
400: '#4ade80',
|
||||||
|
500: '#22c55e',
|
||||||
|
600: '#16a34a',
|
||||||
|
700: '#15803d',
|
||||||
|
800: '#166534',
|
||||||
|
900: '#14532d',
|
||||||
|
950: '#052e16',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'lime',
|
||||||
|
palette: {
|
||||||
|
50: '#f7fee7',
|
||||||
|
100: '#ecfccb',
|
||||||
|
200: '#d9f99d',
|
||||||
|
300: '#bef264',
|
||||||
|
400: '#a3e635',
|
||||||
|
500: '#84cc16',
|
||||||
|
600: '#65a30d',
|
||||||
|
700: '#4d7c0f',
|
||||||
|
800: '#3f6212',
|
||||||
|
900: '#365314',
|
||||||
|
950: '#1a2e05',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'orange',
|
||||||
|
palette: {
|
||||||
|
50: '#fff7ed',
|
||||||
|
100: '#ffedd5',
|
||||||
|
200: '#fed7aa',
|
||||||
|
300: '#fdba74',
|
||||||
|
400: '#fb923c',
|
||||||
|
500: '#f97316',
|
||||||
|
600: '#ea580c',
|
||||||
|
700: '#c2410c',
|
||||||
|
800: '#9a3412',
|
||||||
|
900: '#7c2d12',
|
||||||
|
950: '#431407',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'amber',
|
||||||
|
palette: {
|
||||||
|
50: '#fffbeb',
|
||||||
|
100: '#fef3c7',
|
||||||
|
200: '#fde68a',
|
||||||
|
300: '#fcd34d',
|
||||||
|
400: '#fbbf24',
|
||||||
|
500: '#f59e0b',
|
||||||
|
600: '#d97706',
|
||||||
|
700: '#b45309',
|
||||||
|
800: '#92400e',
|
||||||
|
900: '#78350f',
|
||||||
|
950: '#451a03',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'yellow',
|
||||||
|
palette: {
|
||||||
|
50: '#fefce8',
|
||||||
|
100: '#fef9c3',
|
||||||
|
200: '#fef08a',
|
||||||
|
300: '#fde047',
|
||||||
|
400: '#facc15',
|
||||||
|
500: '#eab308',
|
||||||
|
600: '#ca8a04',
|
||||||
|
700: '#a16207',
|
||||||
|
800: '#854d0e',
|
||||||
|
900: '#713f12',
|
||||||
|
950: '#422006',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'teal',
|
||||||
|
palette: {
|
||||||
|
50: '#f0fdfa',
|
||||||
|
100: '#ccfbf1',
|
||||||
|
200: '#99f6e4',
|
||||||
|
300: '#5eead4',
|
||||||
|
400: '#2dd4bf',
|
||||||
|
500: '#14b8a6',
|
||||||
|
600: '#0d9488',
|
||||||
|
700: '#0f766e',
|
||||||
|
800: '#115e59',
|
||||||
|
900: '#134e4a',
|
||||||
|
950: '#042f2e',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'cyan',
|
||||||
|
palette: {
|
||||||
|
50: '#ecfeff',
|
||||||
|
100: '#cffafe',
|
||||||
|
200: '#a5f3fc',
|
||||||
|
300: '#67e8f9',
|
||||||
|
400: '#22d3ee',
|
||||||
|
500: '#06b6d4',
|
||||||
|
600: '#0891b2',
|
||||||
|
700: '#0e7490',
|
||||||
|
800: '#155e75',
|
||||||
|
900: '#164e63',
|
||||||
|
950: '#083344',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'sky',
|
||||||
|
palette: {
|
||||||
|
50: '#f0f9ff',
|
||||||
|
100: '#e0f2fe',
|
||||||
|
200: '#bae6fd',
|
||||||
|
300: '#7dd3fc',
|
||||||
|
400: '#38bdf8',
|
||||||
|
500: '#0ea5e9',
|
||||||
|
600: '#0284c7',
|
||||||
|
700: '#0369a1',
|
||||||
|
800: '#075985',
|
||||||
|
900: '#0c4a6e',
|
||||||
|
950: '#082f49',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'blue',
|
||||||
|
palette: {
|
||||||
|
50: '#eff6ff',
|
||||||
|
100: '#dbeafe',
|
||||||
|
200: '#bfdbfe',
|
||||||
|
300: '#93c5fd',
|
||||||
|
400: '#60a5fa',
|
||||||
|
500: '#3b82f6',
|
||||||
|
600: '#2563eb',
|
||||||
|
700: '#1d4ed8',
|
||||||
|
800: '#1e40af',
|
||||||
|
900: '#1e3a8a',
|
||||||
|
950: '#172554',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'indigo',
|
||||||
|
palette: {
|
||||||
|
50: '#eef2ff',
|
||||||
|
100: '#e0e7ff',
|
||||||
|
200: '#c7d2fe',
|
||||||
|
300: '#a5b4fc',
|
||||||
|
400: '#818cf8',
|
||||||
|
500: '#6366f1',
|
||||||
|
600: '#4f46e5',
|
||||||
|
700: '#4338ca',
|
||||||
|
800: '#3730a3',
|
||||||
|
900: '#312e81',
|
||||||
|
950: '#1e1b4b',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'violet',
|
||||||
|
palette: {
|
||||||
|
50: '#f5f3ff',
|
||||||
|
100: '#ede9fe',
|
||||||
|
200: '#ddd6fe',
|
||||||
|
300: '#c4b5fd',
|
||||||
|
400: '#a78bfa',
|
||||||
|
500: '#8b5cf6',
|
||||||
|
600: '#7c3aed',
|
||||||
|
700: '#6d28d9',
|
||||||
|
800: '#5b21b6',
|
||||||
|
900: '#4c1d95',
|
||||||
|
950: '#2e1065',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'purple',
|
||||||
|
palette: {
|
||||||
|
50: '#faf5ff',
|
||||||
|
100: '#f3e8ff',
|
||||||
|
200: '#e9d5ff',
|
||||||
|
300: '#d8b4fe',
|
||||||
|
400: '#c084fc',
|
||||||
|
500: '#a855f7',
|
||||||
|
600: '#9333ea',
|
||||||
|
700: '#7e22ce',
|
||||||
|
800: '#6b21a8',
|
||||||
|
900: '#581c87',
|
||||||
|
950: '#3b0764',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'fuchsia',
|
||||||
|
palette: {
|
||||||
|
50: '#fdf4ff',
|
||||||
|
100: '#fae8ff',
|
||||||
|
200: '#f5d0fe',
|
||||||
|
300: '#f0abfc',
|
||||||
|
400: '#e879f9',
|
||||||
|
500: '#d946ef',
|
||||||
|
600: '#c026d3',
|
||||||
|
700: '#a21caf',
|
||||||
|
800: '#86198f',
|
||||||
|
900: '#701a75',
|
||||||
|
950: '#4a044e',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'pink',
|
||||||
|
palette: {
|
||||||
|
50: '#fdf2f8',
|
||||||
|
100: '#fce7f3',
|
||||||
|
200: '#fbcfe8',
|
||||||
|
300: '#f9a8d4',
|
||||||
|
400: '#f472b6',
|
||||||
|
500: '#ec4899',
|
||||||
|
600: '#db2777',
|
||||||
|
700: '#be185d',
|
||||||
|
800: '#9d174d',
|
||||||
|
900: '#831843',
|
||||||
|
950: '#500724',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'rose',
|
||||||
|
palette: {
|
||||||
|
50: '#fff1f2',
|
||||||
|
100: '#ffe4e6',
|
||||||
|
200: '#fecdd3',
|
||||||
|
300: '#fda4af',
|
||||||
|
400: '#fb7185',
|
||||||
|
500: '#f43f5e',
|
||||||
|
600: '#e11d48',
|
||||||
|
700: '#be123c',
|
||||||
|
800: '#9f1239',
|
||||||
|
900: '#881337',
|
||||||
|
950: '#4c0519',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const surfaces = ref([
|
||||||
|
{
|
||||||
|
name: 'slate',
|
||||||
|
palette: {
|
||||||
|
0: '#ffffff',
|
||||||
|
50: '#f8fafc',
|
||||||
|
100: '#f1f5f9',
|
||||||
|
200: '#e2e8f0',
|
||||||
|
300: '#cbd5e1',
|
||||||
|
400: '#94a3b8',
|
||||||
|
500: '#64748b',
|
||||||
|
600: '#475569',
|
||||||
|
700: '#334155',
|
||||||
|
800: '#1e293b',
|
||||||
|
900: '#0f172a',
|
||||||
|
950: '#020617',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'gray',
|
||||||
|
palette: {
|
||||||
|
0: '#ffffff',
|
||||||
|
50: '#f9fafb',
|
||||||
|
100: '#f3f4f6',
|
||||||
|
200: '#e5e7eb',
|
||||||
|
300: '#d1d5db',
|
||||||
|
400: '#9ca3af',
|
||||||
|
500: '#6b7280',
|
||||||
|
600: '#4b5563',
|
||||||
|
700: '#374151',
|
||||||
|
800: '#1f2937',
|
||||||
|
900: '#111827',
|
||||||
|
950: '#030712',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'zinc',
|
||||||
|
palette: {
|
||||||
|
0: '#ffffff',
|
||||||
|
50: '#fafafa',
|
||||||
|
100: '#f4f4f5',
|
||||||
|
200: '#e4e4e7',
|
||||||
|
300: '#d4d4d8',
|
||||||
|
400: '#a1a1aa',
|
||||||
|
500: '#71717a',
|
||||||
|
600: '#52525b',
|
||||||
|
700: '#3f3f46',
|
||||||
|
800: '#27272a',
|
||||||
|
900: '#18181b',
|
||||||
|
950: '#09090b',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'neutral',
|
||||||
|
palette: {
|
||||||
|
0: '#ffffff',
|
||||||
|
50: '#fafafa',
|
||||||
|
100: '#f5f5f5',
|
||||||
|
200: '#e5e5e5',
|
||||||
|
300: '#d4d4d4',
|
||||||
|
400: '#a3a3a3',
|
||||||
|
500: '#737373',
|
||||||
|
600: '#525252',
|
||||||
|
700: '#404040',
|
||||||
|
800: '#262626',
|
||||||
|
900: '#171717',
|
||||||
|
950: '#0a0a0a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'stone',
|
||||||
|
palette: {
|
||||||
|
0: '#ffffff',
|
||||||
|
50: '#fafaf9',
|
||||||
|
100: '#f5f5f4',
|
||||||
|
200: '#e7e5e4',
|
||||||
|
300: '#d6d3d1',
|
||||||
|
400: '#a8a29e',
|
||||||
|
500: '#78716c',
|
||||||
|
600: '#57534e',
|
||||||
|
700: '#44403c',
|
||||||
|
800: '#292524',
|
||||||
|
900: '#1c1917',
|
||||||
|
950: '#0c0a09',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'soho',
|
||||||
|
palette: {
|
||||||
|
0: '#ffffff',
|
||||||
|
50: '#f4f4f4',
|
||||||
|
100: '#e8e9e9',
|
||||||
|
200: '#d2d2d4',
|
||||||
|
300: '#bbbcbe',
|
||||||
|
400: '#a5a5a9',
|
||||||
|
500: '#8e8f93',
|
||||||
|
600: '#77787d',
|
||||||
|
700: '#616268',
|
||||||
|
800: '#4a4b52',
|
||||||
|
900: '#34343d',
|
||||||
|
950: '#1d1e27',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'viva',
|
||||||
|
palette: {
|
||||||
|
0: '#ffffff',
|
||||||
|
50: '#f3f3f3',
|
||||||
|
100: '#e7e7e8',
|
||||||
|
200: '#cfd0d0',
|
||||||
|
300: '#b7b8b9',
|
||||||
|
400: '#9fa1a1',
|
||||||
|
500: '#87898a',
|
||||||
|
600: '#6e7173',
|
||||||
|
700: '#565a5b',
|
||||||
|
800: '#3e4244',
|
||||||
|
900: '#262b2c',
|
||||||
|
950: '#0e1315',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ocean',
|
||||||
|
palette: {
|
||||||
|
0: '#ffffff',
|
||||||
|
50: '#fbfcfc',
|
||||||
|
100: '#F7F9F8',
|
||||||
|
200: '#EFF3F2',
|
||||||
|
300: '#DADEDD',
|
||||||
|
400: '#B1B7B6',
|
||||||
|
500: '#828787',
|
||||||
|
600: '#5F7274',
|
||||||
|
700: '#415B61',
|
||||||
|
800: '#29444E',
|
||||||
|
900: '#183240',
|
||||||
|
950: '#0c1920',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
export function useLayout() {
|
||||||
|
function setPrimary(value: string) {
|
||||||
|
appState.value.primary = value
|
||||||
|
}
|
||||||
|
|
||||||
|
function setSurface(value: string) {
|
||||||
|
appState.value.surface = value
|
||||||
|
}
|
||||||
|
|
||||||
|
function setDarkMode(value: boolean) {
|
||||||
|
appState.value.darkMode = value
|
||||||
|
if (value) {
|
||||||
|
document.documentElement.classList.add('p-dark')
|
||||||
|
} else {
|
||||||
|
document.documentElement.classList.remove('p-dark')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleDarkMode() {
|
||||||
|
appState.value.darkMode = !appState.value.darkMode
|
||||||
|
document.documentElement.classList.toggle('p-dark')
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateColors(type: string, colorName: string) {
|
||||||
|
if (type === 'primary') {
|
||||||
|
setPrimary(colorName)
|
||||||
|
const color = primaryColors.value.find((c) => c.name === colorName)
|
||||||
|
updatePrimaryPalette(color?.palette)
|
||||||
|
} else if (type === 'surface') {
|
||||||
|
setSurface(colorName)
|
||||||
|
const surfaceColor = surfaces.value.find((s) => s.name === colorName)
|
||||||
|
updateSurfacePalette(surfaceColor?.palette)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const isDarkMode = computed(() => appState.value.darkMode)
|
||||||
|
const primary = computed(() => appState.value.primary)
|
||||||
|
const surface = computed(() => appState.value.surface)
|
||||||
|
|
||||||
|
return {
|
||||||
|
primaryColors,
|
||||||
|
surfaces,
|
||||||
|
isDarkMode,
|
||||||
|
primary,
|
||||||
|
surface,
|
||||||
|
toggleDarkMode,
|
||||||
|
setDarkMode,
|
||||||
|
setPrimary,
|
||||||
|
setSurface,
|
||||||
|
updateColors,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
import { ref, onUnmounted, onMounted } from 'vue'
|
|
||||||
|
|
||||||
export interface Message {
|
|
||||||
id: number
|
|
||||||
text: string
|
|
||||||
userId: string
|
|
||||||
createdAt: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Chat {
|
|
||||||
id: string
|
|
||||||
type_id: number
|
|
||||||
users: User[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface User {
|
|
||||||
id: number
|
|
||||||
email: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WsData {
|
|
||||||
type: WsDataType2
|
|
||||||
// data: Chat | Message | User | User[] | Message[] | Chat[]
|
|
||||||
data: unknown
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum WsDataType2 {
|
|
||||||
GET_CHATS = 'GET_CHATS',
|
|
||||||
GET_USERS = 'GET_USERS',
|
|
||||||
GET_MESSAGES = 'GET_MESSAGES',
|
|
||||||
CREATE_MESSAGE = 'CREATE_MESSAGE',
|
|
||||||
CHATS = 'CHATS',
|
|
||||||
USER = 'USER',
|
|
||||||
MESSAGES = 'MESSAGES',
|
|
||||||
STATUS = 'STATUS',
|
|
||||||
ERROR = 'ERROR',
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum COMMAND2 {
|
|
||||||
CONNECT = 'CONNECT',
|
|
||||||
SEND = 'SEND',
|
|
||||||
CLOSE = 'CLOSE',
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useSharedWebSocket(options?: { url?: string; autoConnect?: true }) {
|
|
||||||
const url = options?.url || 'ws://localhost:3000/ws'
|
|
||||||
const autoConnect = options?.autoConnect ?? false
|
|
||||||
const messages = ref<Message[]>([])
|
|
||||||
const chats = ref<Chat[]>([])
|
|
||||||
const users = ref<unknown[]>([])
|
|
||||||
const isConnected = ref(false)
|
|
||||||
const error = ref<string>()
|
|
||||||
const worker = ref<SharedWorker>()
|
|
||||||
|
|
||||||
const init = () => {
|
|
||||||
console.log('INIT WORKER')
|
|
||||||
|
|
||||||
if (!window.SharedWorker) {
|
|
||||||
console.log('SharedWorker not supported')
|
|
||||||
error.value = 'SharedWorker not supported'
|
|
||||||
}
|
|
||||||
|
|
||||||
worker.value = new SharedWorker(new URL('@/workers/worker.js', import.meta.url), {
|
|
||||||
type: 'module',
|
|
||||||
})
|
|
||||||
|
|
||||||
worker.value.port.onmessage = (event) => {
|
|
||||||
const { type, data, connected, message } = event.data
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case WsDataType2.USER:
|
|
||||||
break
|
|
||||||
case WsDataType2.CHATS:
|
|
||||||
chats.value = data
|
|
||||||
break
|
|
||||||
case WsDataType2.MESSAGES:
|
|
||||||
messages.value = data
|
|
||||||
// if (options.onMessage) {
|
|
||||||
// options.onMessage(data)
|
|
||||||
// }
|
|
||||||
break
|
|
||||||
case WsDataType2.CREATE_MESSAGE:
|
|
||||||
messages.value.push(data)
|
|
||||||
break
|
|
||||||
case WsDataType2.STATUS:
|
|
||||||
isConnected.value = connected
|
|
||||||
break
|
|
||||||
case WsDataType2.ERROR:
|
|
||||||
error.value = message
|
|
||||||
logout()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
worker.value.port.postMessage({
|
|
||||||
command: COMMAND2.CONNECT,
|
|
||||||
data: { url: url, token: getToken() },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function logout() {
|
|
||||||
return localStorage.removeItem('token')
|
|
||||||
}
|
|
||||||
|
|
||||||
function getToken() {
|
|
||||||
return localStorage.getItem('token')
|
|
||||||
}
|
|
||||||
|
|
||||||
const send = (data: WsData) => {
|
|
||||||
if (worker.value) {
|
|
||||||
worker.value.port.postMessage({
|
|
||||||
command: COMMAND2.SEND,
|
|
||||||
data: data,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const close = () => {
|
|
||||||
if (worker.value) {
|
|
||||||
worker.value.port.postMessage({ command: COMMAND2.CLOSE })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
if (autoConnect) init()
|
|
||||||
})
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
if (worker.value) close()
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
messages,
|
|
||||||
chats,
|
|
||||||
isConnected,
|
|
||||||
error,
|
|
||||||
send,
|
|
||||||
close,
|
|
||||||
init,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
25
src/main.ts
25
src/main.ts
@@ -1,28 +1,41 @@
|
|||||||
import '@fontsource/roboto/100.css'
|
|
||||||
import '@fontsource/roboto/300.css'
|
|
||||||
import '@fontsource/roboto/400.css'
|
|
||||||
import '@mdi/font/css/materialdesignicons.css'
|
import '@mdi/font/css/materialdesignicons.css'
|
||||||
|
import './assets/main.css'
|
||||||
|
|
||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import { createPinia } from 'pinia'
|
import { createPinia } from 'pinia'
|
||||||
import App from './App.vue'
|
// import PrimeVue from 'primevue/config'
|
||||||
|
|
||||||
import 'vuetify/styles'
|
import 'vuetify/styles'
|
||||||
import { createVuetify } from 'vuetify'
|
import { createVuetify } from 'vuetify'
|
||||||
import * as components from 'vuetify/components'
|
import * as components from 'vuetify/components'
|
||||||
import * as directives from 'vuetify/directives'
|
import * as directives from 'vuetify/directives'
|
||||||
|
|
||||||
const app = createApp(App)
|
import App from './App.vue'
|
||||||
|
import { version } from 'vue'
|
||||||
|
import theme from '@/themes/noir.ts'
|
||||||
|
|
||||||
app.use(createPinia())
|
const app = createApp(App)
|
||||||
|
console.log('version', version)
|
||||||
|
|
||||||
|
// app.use(PrimeVue, { theme: theme })
|
||||||
|
|
||||||
const vuetify = createVuetify({
|
const vuetify = createVuetify({
|
||||||
components,
|
components,
|
||||||
directives,
|
directives,
|
||||||
|
theme: { defaultTheme: 'light' },
|
||||||
icons: {
|
icons: {
|
||||||
defaultSet: 'mdi',
|
defaultSet: 'mdi',
|
||||||
},
|
},
|
||||||
|
defaults: {
|
||||||
|
VAvatar: { density: 'compact' },
|
||||||
|
VChip: { density: 'compact' },
|
||||||
|
VBtn: { color: 'black', variant: 'flat' },
|
||||||
|
VSwitch: { color: 'black', hideDetails: true },
|
||||||
|
VOtpInput: { density: 'compact' },
|
||||||
|
VTextField: { color: 'black', density: 'compact', variant: 'outlined', hideDetails: true },
|
||||||
|
},
|
||||||
})
|
})
|
||||||
app.use(vuetify)
|
app.use(vuetify)
|
||||||
|
|
||||||
|
app.use(createPinia())
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import type { WsData } from '@/composables/useSharedWebSocket.ts'
|
|
||||||
import type { User } from '@/stores/users.ts'
|
import type { User } from '@/stores/users.ts'
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', () => {
|
export const useAuthStore = defineStore('auth', () => {
|
||||||
@@ -16,7 +15,7 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({ email: email }),
|
body: JSON.stringify({ email: email }),
|
||||||
}
|
}
|
||||||
const res = await fetch('http://localhost:5173/login', options)
|
const res = await fetch('http://localhost:5173/api/login', options)
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data: { accessToken: string; refreshToken: string } = await res.json()
|
const data: { accessToken: string; refreshToken: string } = await res.json()
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,46 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import type { User } from '@/stores/users.ts'
|
import type { User } from '@/stores/users.ts'
|
||||||
|
import type { Message } from '@/stores/messages.ts'
|
||||||
|
import { useAuthStore } from '@/stores/auth.ts'
|
||||||
|
|
||||||
export interface Chat {
|
export interface Chat {
|
||||||
id: string
|
id: string
|
||||||
type_id: number
|
typeId: number
|
||||||
name: string
|
name: string
|
||||||
users: User[]
|
users: User[]
|
||||||
|
message?: Message
|
||||||
|
image?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useChatsStore = defineStore('chats', () => {
|
export const useChatsStore = defineStore('chats', () => {
|
||||||
|
const authStore = useAuthStore()
|
||||||
const chats = ref<Chat[]>([])
|
const chats = ref<Chat[]>([])
|
||||||
const selected = ref<string>()
|
const selected = ref<string[]>([])
|
||||||
|
|
||||||
return { chats, selected }
|
const selectedChat = computed(() => {
|
||||||
|
if (!selected.value.length) return
|
||||||
|
|
||||||
|
return chats.value.find((chat: Chat) => chat.id === selected.value[0])
|
||||||
|
})
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getChatLastMessage(chat: Chat) {
|
||||||
|
return chats.value.find((el) => el.id === chat.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
return { chats, selected, selectedChat, getChatInfo }
|
||||||
})
|
})
|
||||||
|
|||||||
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 MenuItems = 'chats' | 'users' | 'settings'
|
||||||
|
|
||||||
|
export const useMenuStore = defineStore('menu', () => {
|
||||||
|
const selected = ref<MenuItems[]>(['chats'])
|
||||||
|
|
||||||
|
return { selected }
|
||||||
|
})
|
||||||
@@ -1,15 +1,22 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
|
import { useChatsStore } from '@/stores/chats.ts'
|
||||||
|
|
||||||
export interface Message {
|
export interface Message {
|
||||||
id: number
|
id: number
|
||||||
text: string
|
message: string
|
||||||
user_id: number
|
userId: number
|
||||||
created_at: string
|
createdAt: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useMessagesStore = defineStore('messages', () => {
|
export const useMessagesStore = defineStore('messages', () => {
|
||||||
|
const chatsStore = useChatsStore()
|
||||||
const messages = ref<Message[]>([])
|
const messages = ref<Message[]>([])
|
||||||
|
const message = ref<Message>()
|
||||||
|
|
||||||
return { messages }
|
const lastMessage = computed(() => {
|
||||||
|
return message.value ?? chatsStore.selectedChat?.message ?? null
|
||||||
|
})
|
||||||
|
|
||||||
|
return { messages, lastMessage }
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { onMounted, onUnmounted, ref } from 'vue'
|
|||||||
import { type Chat, useChatsStore } from '@/stores/chats.ts'
|
import { type Chat, useChatsStore } from '@/stores/chats.ts'
|
||||||
import { useAuthStore } from '@/stores/auth.ts'
|
import { useAuthStore } from '@/stores/auth.ts'
|
||||||
import { type Message, useMessagesStore } from '@/stores/messages.ts'
|
import { type Message, useMessagesStore } from '@/stores/messages.ts'
|
||||||
|
import { useUsersStore } from '@/stores/users.ts'
|
||||||
|
import { useMenuStore } from '@/stores/menu.ts'
|
||||||
|
|
||||||
export enum SocketDataReq {
|
export enum SocketDataReq {
|
||||||
GET_CHATS = 'GET_CHATS',
|
GET_CHATS = 'GET_CHATS',
|
||||||
@@ -35,6 +37,8 @@ export const useSocketsStore = defineStore('sockets', () => {
|
|||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
const chatsStore = useChatsStore()
|
const chatsStore = useChatsStore()
|
||||||
const messagesStore = useMessagesStore()
|
const messagesStore = useMessagesStore()
|
||||||
|
const usersStore = useUsersStore()
|
||||||
|
const menuStore = useMenuStore()
|
||||||
|
|
||||||
const isConnected = ref(false)
|
const isConnected = ref(false)
|
||||||
const error = ref<string>()
|
const error = ref<string>()
|
||||||
@@ -57,27 +61,36 @@ export const useSocketsStore = defineStore('sockets', () => {
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SocketDataRes.USERS:
|
case SocketDataRes.USERS:
|
||||||
console.log('USERS_LIST', data)
|
console.log('Received from back: USERS', data)
|
||||||
|
usersStore.users = data
|
||||||
break
|
break
|
||||||
case SocketDataRes.USER:
|
case SocketDataRes.USER:
|
||||||
console.log('USER', data)
|
console.log('Received from back: USER', data)
|
||||||
authStore.me = data
|
authStore.me = data
|
||||||
break
|
break
|
||||||
case SocketDataRes.CHATS:
|
case SocketDataRes.CHATS:
|
||||||
console.log('CHATS', data)
|
console.log('Received from back: CHATS', data)
|
||||||
|
if (Array.isArray(data)) {
|
||||||
chatsStore.chats = data
|
chatsStore.chats = data
|
||||||
|
} else {
|
||||||
|
const idx = chatsStore.chats.findIndex((chat) => chat.id === data.id)
|
||||||
|
if (idx < 0) chatsStore.chats.push(data)
|
||||||
|
|
||||||
|
menuStore.selected = ['chats']
|
||||||
|
chatsStore.selected = [data.id]
|
||||||
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
case SocketDataRes.MESSAGES:
|
case SocketDataRes.MESSAGES:
|
||||||
console.log('MESSAGES', data)
|
console.log('Received from back: MESSAGES', data)
|
||||||
|
messagesStore.messages = data
|
||||||
messagesStore.messages = data.reverse()
|
|
||||||
// if (options.onMessage) {
|
// if (options.onMessage) {
|
||||||
// options.onMessage(data)
|
// options.onMessage(data)
|
||||||
// }
|
// }
|
||||||
break
|
break
|
||||||
case SocketDataRes.MESSAGE:
|
case SocketDataRes.MESSAGE:
|
||||||
console.log('MESSAGE', data)
|
console.log('Received from back: MESSAGE', data)
|
||||||
messagesStore.messages.push(data)
|
messagesStore.messages.unshift(data)
|
||||||
break
|
break
|
||||||
case SocketDataRes.STATUS:
|
case SocketDataRes.STATUS:
|
||||||
isConnected.value = connected
|
isConnected.value = connected
|
||||||
@@ -101,6 +114,7 @@ export const useSocketsStore = defineStore('sockets', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const send = (data: unknown) => {
|
const send = (data: unknown) => {
|
||||||
|
console.log(COMMAND.SEND, data)
|
||||||
postMessage(COMMAND.SEND, data)
|
postMessage(COMMAND.SEND, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export interface User {
|
|||||||
id: number
|
id: number
|
||||||
email: string
|
email: string
|
||||||
name: string
|
name: string
|
||||||
|
image?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useUsersStore = defineStore('users', () => {
|
export const useUsersStore = defineStore('users', () => {
|
||||||
|
|||||||
59
src/themes/noir.ts
Normal file
59
src/themes/noir.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import '@primeuix/styles' // When styles change, the app will hot reload.
|
||||||
|
|
||||||
|
import { definePreset } from '@primeuix/themes'
|
||||||
|
import Aura from '@primeuix/themes/aura'
|
||||||
|
|
||||||
|
export const NoirPreset = definePreset(Aura, {
|
||||||
|
semantic: {
|
||||||
|
primary: {
|
||||||
|
50: '{surface.50}',
|
||||||
|
100: '{surface.100}',
|
||||||
|
200: '{surface.200}',
|
||||||
|
300: '{surface.300}',
|
||||||
|
400: '{surface.400}',
|
||||||
|
500: '{surface.500}',
|
||||||
|
600: '{surface.600}',
|
||||||
|
700: '{surface.700}',
|
||||||
|
800: '{surface.800}',
|
||||||
|
900: '{surface.900}',
|
||||||
|
950: '{surface.950}',
|
||||||
|
},
|
||||||
|
colorScheme: {
|
||||||
|
light: {
|
||||||
|
primary: {
|
||||||
|
color: '{primary.950}',
|
||||||
|
contrastColor: '#ffffff',
|
||||||
|
hoverColor: '{primary.800}',
|
||||||
|
activeColor: '{primary.700}',
|
||||||
|
},
|
||||||
|
highlight: {
|
||||||
|
background: '{primary.950}',
|
||||||
|
focusBackground: '{primary.700}',
|
||||||
|
color: '#ffffff',
|
||||||
|
focusColor: '#ffffff',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dark: {
|
||||||
|
primary: {
|
||||||
|
color: '{primary.50}',
|
||||||
|
contrastColor: '{primary.950}',
|
||||||
|
hoverColor: '{primary.200}',
|
||||||
|
activeColor: '{primary.300}',
|
||||||
|
},
|
||||||
|
highlight: {
|
||||||
|
background: '{primary.50}',
|
||||||
|
focusBackground: '{primary.300}',
|
||||||
|
color: '{primary.950}',
|
||||||
|
focusColor: '{primary.950}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default {
|
||||||
|
preset: NoirPreset,
|
||||||
|
options: {
|
||||||
|
darkModeSelector: '.p-dark',
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { onMounted, ref } from 'vue'
|
|
||||||
import ChatsPane from '@/components/ChatsPane.vue'
|
|
||||||
import MessagesPane from '@/components/MessagesPane.vue'
|
|
||||||
import { useSocketsStore } from '@/stores/sockets.ts'
|
|
||||||
import { useChatsStore } from '@/stores/chats.ts'
|
|
||||||
|
|
||||||
const socketsStore = useSocketsStore()
|
|
||||||
// const { messages, chats, isConnected, error, send } = useSharedWebSocket({ autoConnect: true })
|
|
||||||
|
|
||||||
// const socketsStore = useSocketsStore()
|
|
||||||
|
|
||||||
const chatsStore = useChatsStore()
|
|
||||||
|
|
||||||
const message = ref('')
|
|
||||||
const selectedChat = ref('')
|
|
||||||
|
|
||||||
// const onChatClick = (id: string) => {
|
|
||||||
// console.log(id)
|
|
||||||
// selectedChat.value = id
|
|
||||||
// send({
|
|
||||||
// type: WsDataType.GET_MESSAGES,
|
|
||||||
// data: { chat_id: id },
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const sendMessage = () => {
|
|
||||||
// if (message.value.trim()) {
|
|
||||||
// send({
|
|
||||||
// type: WsDataType.CREATE_MESSAGE,
|
|
||||||
// data: {
|
|
||||||
// chat_id: selectedChat.value,
|
|
||||||
// text: message.value,
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// message.value = ''
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
onMounted(() => {
|
|
||||||
socketsStore.init()
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<v-row no-gutters class="h-100">
|
|
||||||
<v-col cols="12" md="4" lg="3" sm="5">
|
|
||||||
<chats-pane />
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" md="8" lg="9" sm="7" class="h-100">
|
|
||||||
<messages-pane v-if="chatsStore.selected" />
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
29
src/views/MainView.vue
Normal file
29
src/views/MainView.vue
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
import { useSocketsStore } from '@/stores/sockets.ts'
|
||||||
|
import LeftPane from '@/components/LeftPane.vue'
|
||||||
|
import RightPane from '@/components/RightPane.vue'
|
||||||
|
|
||||||
|
const socketsStore = useSocketsStore()
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
socketsStore.init()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex h-full">
|
||||||
|
<div class="md:w-1/3 sm:w-1/2 w-1/2 bg-white">
|
||||||
|
<LeftPane>
|
||||||
|
<template #default="{ component }">
|
||||||
|
<component :is="component" />
|
||||||
|
</template>
|
||||||
|
</LeftPane>
|
||||||
|
</div>
|
||||||
|
<div class="md:w-2/3 sm:w-1/2 w-1/2">
|
||||||
|
<RightPane />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -1,41 +1,49 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { useAuthStore } from '@/stores/auth.ts'
|
import { useAuthStore } from '@/stores/auth.ts'
|
||||||
|
// import {
|
||||||
|
// Button,
|
||||||
|
// InputText,
|
||||||
|
// Card,
|
||||||
|
// InputOtp,
|
||||||
|
// ToggleSwitch,
|
||||||
|
// Divider,
|
||||||
|
// IconField,
|
||||||
|
// InputIcon,
|
||||||
|
// } from 'primevue'
|
||||||
|
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
const email = ref('vadim.olonin@gmail.com')
|
const email = ref('vadim.olonin@gmail.com')
|
||||||
|
const name = ref('Vadim')
|
||||||
|
const otp = ref('123456')
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
await authStore.login(email.value)
|
await authStore.login(email.value)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<v-row justify="center" align="center" class="h-100">
|
<div class="h-full flex flex-col justify-center items-center px-4">
|
||||||
<v-col cols="12" md="4" lg="4">
|
<VCard class="w-full md:w-1/2">
|
||||||
<v-card elevation="0" border rounded="lg">
|
<template #title>
|
||||||
<v-card-title class="mb-2">Sign in</v-card-title>
|
<div class="text-2xl">Sign in</div>
|
||||||
<v-card-text>
|
</template>
|
||||||
<form @submit.prevent="onSubmit">
|
<template #text>
|
||||||
<div class="d-flex flex-column ga-4">
|
<form @submit.prevent="onSubmit" class="flex flex-col gap-4">
|
||||||
<v-text-field
|
<VTextField v-model="email" placeholder="email" />
|
||||||
hide-details
|
<VTextField v-model="name" placeholder="name" />
|
||||||
variant="outlined"
|
<div class="flex justify-center">
|
||||||
v-model="email"
|
<VOtpInput v-model="otp" />
|
||||||
placeholder="email"
|
|
||||||
type="email"
|
|
||||||
rounded="lg"
|
|
||||||
/>
|
|
||||||
<div class="d-flex ga-4 align-center justify-space-between">
|
|
||||||
<v-switch color="black" label="Keep me signed in" hide-details></v-switch>
|
|
||||||
<v-btn variant="flat" rounded="lg" type="submit" color="black">login</v-btn>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex items-center justify-between gap-2">
|
||||||
|
<VSwitch hide-details label="Keep me signed in" />
|
||||||
|
<VBtn type="submit">Sign In</VBtn>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</v-card-text>
|
</template>
|
||||||
</v-card>
|
</VCard>
|
||||||
</v-col>
|
</div>
|
||||||
</v-row>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { fileURLToPath, URL } from 'node:url'
|
import { fileURLToPath, URL } from 'node:url'
|
||||||
|
import tailwindcss from '@tailwindcss/vite'
|
||||||
|
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
@@ -6,10 +7,7 @@ import vueDevTools from 'vite-plugin-vue-devtools'
|
|||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [vue(), tailwindcss(), vueDevTools()],
|
||||||
vue(),
|
|
||||||
// vueDevTools(),
|
|
||||||
],
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||||
@@ -18,7 +16,7 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
proxy: {
|
proxy: {
|
||||||
'/login': 'http://localhost:3000',
|
'/api': 'http://localhost:3000',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user