mirror of
https://github.com/lorsanstand/Aether.git
synced 2026-06-19 20:15:16 +03:00
Add edit message
This commit is contained in:
@@ -66,6 +66,14 @@ function App() {
|
||||
</PrivateRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/chat/:chatId"
|
||||
element={
|
||||
<PrivateRoute>
|
||||
<ChatPage />
|
||||
</PrivateRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/profile"
|
||||
element={
|
||||
|
||||
+1027
-30
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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 }),
|
||||
}
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user