From abf4d41c2336bd4a3262940294d17ac4b0e3b345 Mon Sep 17 00:00:00 2001 From: Opti1337 Date: Thu, 14 May 2026 07:09:52 +0600 Subject: [PATCH] chat wip --- new-client/package.json | 1 + new-client/src/shared/api/qUser.ts | 22 +++++ .../src/shared/components/ui/Avatar.vue | 20 +++-- .../src/shared/components/ui/Button.vue | 7 +- .../src/shared/components/ui/Spinner.vue | 43 ++++++++++ .../shared/composables/use-user-details.ts | 12 +++ new-client/src/shared/layouts/Default.vue | 7 ++ .../src/widgets/chat/api/qChatMessages.ts | 17 ++-- .../widgets/chat/api/qMessageAttachment.ts | 16 ++++ .../src/widgets/chat/composables/use-chat.ts | 3 +- new-client/src/widgets/chat/ui/Chat.vue | 30 ++++--- new-client/src/widgets/chat/ui/ChatInput.vue | 16 ++++ .../src/widgets/chat/ui/ChatMessage.vue | 82 ++++++++++++++++--- .../widgets/chat/ui/ChatMessageAttachment.vue | 46 +++++++++++ .../src/widgets/chat/ui/ChatMessages.vue | 59 +++++++++++++ new-client/yarn.lock | 7 ++ server/plugins/schemas/user.ts | 1 + server/routes/user.ts | 2 +- 18 files changed, 350 insertions(+), 41 deletions(-) create mode 100644 new-client/src/shared/api/qUser.ts create mode 100644 new-client/src/shared/components/ui/Spinner.vue create mode 100644 new-client/src/shared/composables/use-user-details.ts create mode 100644 new-client/src/widgets/chat/api/qMessageAttachment.ts create mode 100644 new-client/src/widgets/chat/ui/ChatInput.vue create mode 100644 new-client/src/widgets/chat/ui/ChatMessageAttachment.vue create mode 100644 new-client/src/widgets/chat/ui/ChatMessages.vue diff --git a/new-client/package.json b/new-client/package.json index e400431..9437415 100644 --- a/new-client/package.json +++ b/new-client/package.json @@ -11,6 +11,7 @@ "dependencies": { "@ark-ui/vue": "^5.36.2", "@lucide/vue": "^1.14.0", + "@tanstack/query-persist-client-core": "^5.100.10", "@tanstack/vue-query": "^5.100.10", "@tauri-apps/plugin-global-shortcut": "^2.3.1", "@tauri-apps/plugin-opener": "~2", diff --git a/new-client/src/shared/api/qUser.ts b/new-client/src/shared/api/qUser.ts new file mode 100644 index 0000000..b4b88a7 --- /dev/null +++ b/new-client/src/shared/api/qUser.ts @@ -0,0 +1,22 @@ +import type { ResponseError, User } from '@shared/api/generated-chad-api.ts' +import type { MaybeRefOrGetter } from 'vue' +import api from '@shared/api/client.ts' +import { useQuery } from '@tanstack/vue-query' +import { toValue } from 'vue' + +export function qUser(username: MaybeRefOrGetter) { + return useQuery({ + queryKey: ['user', username], + queryFn: async () => { + const response = await api.chad.userGet({ id: toValue(username) }) + + return response.data + }, + staleTime: Infinity, + // persister: experimental_createQueryPersister({ + // storage: localStorage, + // maxAge: 1000 * 60 * 60 * 24, + // prefix: 'CHAD_USER_', + // }), + }) +} diff --git a/new-client/src/shared/components/ui/Avatar.vue b/new-client/src/shared/components/ui/Avatar.vue index 224ee9f..707ec4d 100644 --- a/new-client/src/shared/components/ui/Avatar.vue +++ b/new-client/src/shared/components/ui/Avatar.vue @@ -1,5 +1,5 @@ + + diff --git a/new-client/src/shared/composables/use-user-details.ts b/new-client/src/shared/composables/use-user-details.ts new file mode 100644 index 0000000..ee4cb37 --- /dev/null +++ b/new-client/src/shared/composables/use-user-details.ts @@ -0,0 +1,12 @@ +import type { MaybeRefOrGetter } from 'vue' +import { qUser } from '@shared/api/qUser.ts' +import { readonly } from 'vue' + +export function useUserDetails(username: MaybeRefOrGetter) { + const { data: user, isFetching } = qUser(username) + + return { + user: readonly(user), + isFetching, + } +} diff --git a/new-client/src/shared/layouts/Default.vue b/new-client/src/shared/layouts/Default.vue index ee812ff..7336acc 100644 --- a/new-client/src/shared/layouts/Default.vue +++ b/new-client/src/shared/layouts/Default.vue @@ -20,6 +20,10 @@
@@ -29,7 +33,9 @@ diff --git a/new-client/src/widgets/chat/ui/ChatInput.vue b/new-client/src/widgets/chat/ui/ChatInput.vue new file mode 100644 index 0000000..432d9fc --- /dev/null +++ b/new-client/src/widgets/chat/ui/ChatInput.vue @@ -0,0 +1,16 @@ + + + + + diff --git a/new-client/src/widgets/chat/ui/ChatMessage.vue b/new-client/src/widgets/chat/ui/ChatMessage.vue index a2941a0..5f613b9 100644 --- a/new-client/src/widgets/chat/ui/ChatMessage.vue +++ b/new-client/src/widgets/chat/ui/ChatMessage.vue @@ -1,32 +1,72 @@ diff --git a/new-client/src/widgets/chat/ui/ChatMessageAttachment.vue b/new-client/src/widgets/chat/ui/ChatMessageAttachment.vue new file mode 100644 index 0000000..038c48a --- /dev/null +++ b/new-client/src/widgets/chat/ui/ChatMessageAttachment.vue @@ -0,0 +1,46 @@ + + + + + diff --git a/new-client/src/widgets/chat/ui/ChatMessages.vue b/new-client/src/widgets/chat/ui/ChatMessages.vue new file mode 100644 index 0000000..7a0d7ce --- /dev/null +++ b/new-client/src/widgets/chat/ui/ChatMessages.vue @@ -0,0 +1,59 @@ + + + + + diff --git a/new-client/yarn.lock b/new-client/yarn.lock index 05a14c6..f50b1d1 100644 --- a/new-client/yarn.lock +++ b/new-client/yarn.lock @@ -818,6 +818,13 @@ resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.100.10.tgz#aeb34d301fd4ff9762e67dfa018adc33b7a18be4" integrity sha512-8UR0yJR+GiQ40m3lPhUr0xbfAupe6GSQiksSBSa9SM2NjezFyxXCIA69/lz8cSoNKZLrw1/PktIyQBJcVeMi3w== +"@tanstack/query-persist-client-core@^5.100.10": + version "5.100.10" + resolved "https://registry.yarnpkg.com/@tanstack/query-persist-client-core/-/query-persist-client-core-5.100.10.tgz#efe9ea2b7cea90330129afdf7393f09fd06ad358" + integrity sha512-O9Pey40DhTTDBABS0bHr+KNL5/VMf6PrqjexS8WoDDtnkaoWM+y0MSe0V9E5W+BwvkjM33mB3aYcCxa175gZTQ== + dependencies: + "@tanstack/query-core" "5.100.10" + "@tanstack/vue-query@^5.100.10": version "5.100.10" resolved "https://registry.yarnpkg.com/@tanstack/vue-query/-/vue-query-5.100.10.tgz#eafed0d51887c12dcbba5edb1b7108522ebc3891" diff --git a/server/plugins/schemas/user.ts b/server/plugins/schemas/user.ts index 10c7130..f2f8b08 100644 --- a/server/plugins/schemas/user.ts +++ b/server/plugins/schemas/user.ts @@ -2,6 +2,7 @@ import { Type } from 'typebox' export const GetUserQuerySchema = Type.Partial(Type.Object({ username: Type.String(), + id: Type.String(), }), { $id: 'GetUserQuery' }) export const UserPreferencesSchema = Type.Object({ diff --git a/server/routes/user.ts b/server/routes/user.ts index f11d873..6ac41fc 100644 --- a/server/routes/user.ts +++ b/server/routes/user.ts @@ -19,7 +19,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => { }, async (req, reply) => { const user = await fastify.prisma.user.findFirst({ - where: { username: req.query.username }, + where: { username: req.query.username, id: req.query.id }, select: { id: true, username: true,