Add edit message

This commit is contained in:
2026-01-24 13:20:45 +03:00
parent a690116399
commit 8c0c063bac
17 changed files with 1237 additions and 112 deletions
+8
View File
@@ -66,6 +66,14 @@ function App() {
</PrivateRoute>
}
/>
<Route
path="/chat/:chatId"
element={
<PrivateRoute>
<ChatPage />
</PrivateRoute>
}
/>
<Route
path="/profile"
element={
File diff suppressed because it is too large Load Diff
+58
View File
@@ -0,0 +1,58 @@
import apiClient from './api';
export type Chat = {
chat_id: string;
user_id: number;
last_message: string | null;
avatar_url: string | null;
display_name: string;
}
export type Message = {
id: string;
sender_id: number;
chat_id: string;
content: string;
is_edited?: boolean;
created_at: string;
updated_at: string;
}
export type MessageCreate = {
content: string;
chat_id?: string;
recipient_id?: number;
}
export type MessageUpdate = {
id: string;
content: string;
}
const chatService = {
async getChats(offset: number = 0, limit: number = 10): Promise<Chat[]> {
const response = await apiClient.get('/chats/', {
params: { offset, limit }
});
return response.data;
},
async getChatMessages(chatId: string, offset: number = 0, limit: number = 50): Promise<Message[]> {
const response = await apiClient.get(`/chats/${chatId}`, {
params: { offset, limit }
});
return response.data;
},
async sendMessage(data: MessageCreate): Promise<Message> {
const response = await apiClient.post('/chats/message', data);
return response.data;
},
async updateMessage(data: MessageUpdate): Promise<Message> {
const response = await apiClient.put('/chats/message', data);
return response.data;
}
};
export default chatService;
+5
View File
@@ -26,6 +26,11 @@ export const userService = {
return response.data;
},
getUserById: async (userId: number): Promise<User> => {
const response = await apiClient.get(`/users/${userId}`);
return response.data;
},
updateProfile: async (data: UserUpdate): Promise<User> => {
const response = await apiClient.put('/users/me', data);
return response.data;
+33
View File
@@ -0,0 +1,33 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
import type { Chat } from '../services/chatService';
interface ChatStore {
chats: Chat[];
setChats: (chats: Chat[]) => void;
updateChat: (chatId: string, updates: Partial<Chat>) => void;
clearChats: () => void;
}
export const useChatStore = create<ChatStore>()(
persist(
(set) => ({
chats: [],
setChats: (chats) => set({ chats }),
updateChat: (chatId, updates) =>
set((state) => ({
chats: state.chats.map(chat =>
chat.chat_id === chatId ? { ...chat, ...updates } : chat
)
})),
clearChats: () => set({ chats: [] }),
}),
{
name: 'aether-chats',
partialize: (state) => ({ chats: state.chats }),
}
)
);