Fix QuestionSplitView error handling, loading state, file key

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-19 13:47:35 +05:00
parent 3a2f64d47d
commit d2362a3f1e
+27 -5
View File
@@ -61,12 +61,24 @@ export function QuestionSplitView({ currentUserId }: { currentUserId: string })
const [sending, setSending] = useState(false); const [sending, setSending] = useState(false);
const [closing, setClosing] = useState(false); const [closing, setClosing] = useState(false);
const [error, setError] = useState(""); const [error, setError] = useState("");
const [listError, setListError] = useState("");
const [listLoading, setListLoading] = useState(true);
const fetchList = useCallback(async () => { const fetchList = useCallback(async () => {
const res = await fetch("/api/questions"); setListError("");
if (res.ok) { setListLoading(true);
try {
const res = await fetch("/api/questions");
if (!res.ok) {
setListError("Не удалось загрузить вопросы");
return;
}
const data = await res.json(); const data = await res.json();
setQuestions(data); setQuestions(data);
} catch {
setListError("Не удалось загрузить вопросы");
} finally {
setListLoading(false);
} }
}, []); }, []);
@@ -166,7 +178,17 @@ export function QuestionSplitView({ currentUserId }: { currentUserId: string })
{/* Question list */} {/* Question list */}
<div className="flex-1 overflow-y-auto"> <div className="flex-1 overflow-y-auto">
{filtered.length === 0 && ( {listError && (
<p className="text-xs p-4" style={{ color: "var(--destructive)" }}>
{listError}
</p>
)}
{listLoading && (
<p className="text-xs p-4" style={{ color: "var(--muted-foreground)" }}>
Загрузка...
</p>
)}
{!listLoading && filtered.length === 0 && (
<p className="text-xs p-4" style={{ color: "var(--muted-foreground)" }}> <p className="text-xs p-4" style={{ color: "var(--muted-foreground)" }}>
Нет вопросов Нет вопросов
</p> </p>
@@ -270,9 +292,9 @@ export function QuestionSplitView({ currentUserId }: { currentUserId: string })
<p style={{ color: "var(--foreground)" }}>{msg.text}</p> <p style={{ color: "var(--foreground)" }}>{msg.text}</p>
{msg.files && msg.files.length > 0 && ( {msg.files && msg.files.length > 0 && (
<div className="flex flex-col gap-1 mt-2"> <div className="flex flex-col gap-1 mt-2">
{msg.files.map((f, i) => ( {msg.files.map((f) => (
<a <a
key={i} key={f.url}
href={f.url} href={f.url}
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"