fixed code

This commit is contained in:
SlimusMinus
2026-08-11 00:24:07 +03:00
parent c50b75eece
commit 7f59ee1f38
95 changed files with 3623 additions and 2830 deletions

View File

@@ -1,10 +1,14 @@
import { useState, useCallback } from "react";
import { useTranslation } from 'react-i18next';
import { API_URL } from "../config/authConstants";
import { apiFetch } from "../api/apiClient";
import { useUnread } from "../context/UnreadContext";
export function useDeleteChat() {
const { t } = useTranslation();
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const { clearChatUnread } = useUnread();
const deleteChat = useCallback(async (chatId) => {
setLoading(true);
@@ -13,17 +17,22 @@ export function useDeleteChat() {
const res = await apiFetch(`${API_URL}/api/v1/chats/${chatId}`, {
method: "DELETE",
});
if (!res.ok) {
throw new Error(`Ошибка ${res.status}`);
let body;
try { body = await res.json(); } catch { body = null; }
throw new Error(body?.message || t('chat.deleteErrorWithStatus', { status: res.status }));
}
clearChatUnread(chatId);
return true;
} catch (err) {
setError(err.message || "Failed to delete chat");
setError(err.message || t('chat.deleteError'));
return false;
} finally {
setLoading(false);
}
}, []);
}, [t, clearChatUnread]);
return { deleteChat, loading, error };
}