Fix document scroll and preview dialog
ScrollArea (Radix) injected display:table on viewport, preventing scroll — replaced with plain div + overflow-y-auto. Preview dialog never loaded text because onOpenChange doesn't fire on initial mount — replaced with useEffect that fetches on open. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Progress } from "@/components/ui/progress";
|
import { Progress } from "@/components/ui/progress";
|
||||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@@ -126,33 +125,26 @@ function DocumentPreviewDialog({
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const loadText = async () => {
|
useEffect(() => {
|
||||||
if (text !== null) return; // already loaded
|
if (!open) {
|
||||||
setLoading(true);
|
|
||||||
setError(null);
|
|
||||||
try {
|
|
||||||
const res = await apiRequest<{ text: string }>(`/api/documents/${doc.id}/text`);
|
|
||||||
setText(res.text || "(ריק)");
|
|
||||||
} catch {
|
|
||||||
setError("לא ניתן לטעון את תוכן המסמך");
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleOpenChange = (v: boolean) => {
|
|
||||||
if (v) loadText();
|
|
||||||
if (!v) {
|
|
||||||
setText(null);
|
setText(null);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
onOpenChange(v);
|
let cancelled = false;
|
||||||
};
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
apiRequest<{ text: string }>(`/api/documents/${doc.id}/text`)
|
||||||
|
.then((res) => { if (!cancelled) setText(res.text || "(ריק)"); })
|
||||||
|
.catch(() => { if (!cancelled) setError("המסמך עדיין לא עובד או שאין בו טקסט"); })
|
||||||
|
.finally(() => { if (!cancelled) setLoading(false); });
|
||||||
|
return () => { cancelled = true; };
|
||||||
|
}, [open, doc.id]);
|
||||||
|
|
||||||
const displayName = doc.title || filenameFromPath(doc.file_path);
|
const displayName = doc.title || filenameFromPath(doc.file_path);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="sm:max-w-2xl max-h-[80vh] flex flex-col" dir="rtl">
|
<DialogContent className="sm:max-w-2xl max-h-[80vh] flex flex-col" dir="rtl">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="text-right">{displayName}</DialogTitle>
|
<DialogTitle className="text-right">{displayName}</DialogTitle>
|
||||||
@@ -168,11 +160,11 @@ function DocumentPreviewDialog({
|
|||||||
<div className="text-center py-12 text-danger text-sm">{error}</div>
|
<div className="text-center py-12 text-danger text-sm">{error}</div>
|
||||||
)}
|
)}
|
||||||
{text !== null && !loading && (
|
{text !== null && !loading && (
|
||||||
<ScrollArea className="h-[60vh] overflow-hidden" dir="rtl">
|
<div className="h-[60vh] overflow-y-auto" dir="rtl">
|
||||||
<pre className="whitespace-pre-wrap text-sm text-ink leading-relaxed font-sans p-2">
|
<pre className="whitespace-pre-wrap text-sm text-ink leading-relaxed font-sans p-2">
|
||||||
{text}
|
{text}
|
||||||
</pre>
|
</pre>
|
||||||
</ScrollArea>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<DialogFooter showCloseButton />
|
<DialogFooter showCloseButton />
|
||||||
@@ -385,13 +377,13 @@ export function DocumentsPanel({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<ScrollArea className="max-h-[70vh] overflow-hidden" dir="rtl">
|
<div className="max-h-[70vh] overflow-y-auto" dir="rtl">
|
||||||
<ul className="divide-y divide-rule" dir="rtl">
|
<ul className="divide-y divide-rule" dir="rtl">
|
||||||
{sorted.map((doc) => (
|
{sorted.map((doc) => (
|
||||||
<DocumentRow key={doc.id} doc={doc} caseNumber={caseNumber} />
|
<DocumentRow key={doc.id} doc={doc} caseNumber={caseNumber} />
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</ScrollArea>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user