Merge pull request 'feat(halachot): חיפוש/איתור בתור-ההלכות + הערת חלון-תצוגה' (#282) from worktree-halacha-queue-search into main
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 1m30s
G12 Leak-Guard / leak-guard (push) Successful in 4s
Lint — undefined names / undefined-names (push) Successful in 10s

This commit was merged in pull request #282.
This commit is contained in:
2026-06-17 04:00:00 +00:00
4 changed files with 165 additions and 15 deletions

View File

@@ -1,7 +1,7 @@
"use client";
import { useEffect, useMemo, useState, type ReactNode } from "react";
import { Check, X, Edit2, ChevronDown, ChevronLeft, AlertTriangle, Clock, RotateCcw, Info } from "lucide-react";
import { Check, X, Edit2, ChevronDown, ChevronLeft, AlertTriangle, Clock, RotateCcw, Info, Search } from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
@@ -674,13 +674,25 @@ function PendingPanel() {
// "judgment" = items the panel deliberated (or clean) → chair approves/rejects;
// "fix" = flagged-but-never-adjudicated → extraction repair. (No empty "תור נקי".)
const [view, setView] = useState<"judgment" | "fix">("judgment");
const { data, isPending, error } = useHalachotPending({ limit: 500 });
// Locate a pending halacha by decision/text — server-side, so an item ranked
// below the 500-item display window is still reachable (the chair's core ask).
const [searchInput, setSearchInput] = useState("");
const [search, setSearch] = useState("");
useEffect(() => {
const t = setTimeout(() => setSearch(searchInput.trim()), 300);
return () => clearTimeout(t);
}, [searchInput]);
const searching = search.length > 0;
const { data, isPending, error } = useHalachotPending({ limit: 500, search });
const update = useUpdateHalacha();
const batch = useBatchReviewHalachot();
const [expandedIds, setExpandedIds] = useState<Set<string>>(new Set());
const [focusedId, setFocusedId] = useState<string | null>(null);
const allItems = useMemo(() => data?.items ?? [], [data]);
// Full pending count for this filter (incl. items beyond the display window).
const pendingTotal = data?.total ?? allItems.length;
const judgmentCount = useMemo(
() => allItems.filter((h) => !isExtractionFixItem(h)).length, [allItems]);
const fixCount = useMemo(
@@ -697,10 +709,11 @@ function PendingPanel() {
const visibleItems = useMemo<ReviewItem[]>(() => {
const out: ReviewItem[] = [];
for (const g of groups) {
if (expandedIds.has(g.caseLawId)) out.push(...g.items);
// a search narrows to a handful of cases — show them all open
if (searching || expandedIds.has(g.caseLawId)) out.push(...g.items);
}
return out;
}, [groups, expandedIds]);
}, [groups, expandedIds, searching]);
useEffect(() => {
if (focusedId === null) return;
@@ -851,7 +864,16 @@ function PendingPanel() {
</div>
);
} else if (!groups.length) {
body = (
body = searching ? (
<div className="text-center text-ink-muted py-16">
<p className="text-lg">לא נמצאו הלכות ממתינות התואמות ל״{search}״.</p>
<p className="text-sm mt-2">
נסה מספר-פס״ד, שם-תיק או מילה מנוסח-ההלכה או נקה את החיפוש.
{view === "judgment" && fixCount > 0 && " ייתכן שההתאמות נמצאות ב״דורש תיקון-חילוץ״."}
{view === "fix" && judgmentCount > 0 && " ייתכן שההתאמות נמצאות ב״להכרעתך״."}
</p>
</div>
) : (
<div className="text-center text-ink-muted py-16">
<p className="text-lg">
{view === "fix"
@@ -893,7 +915,7 @@ function PendingPanel() {
<div className="space-y-3">
{groups.map((g) => {
const isOpen = expandedIds.has(g.caseLawId);
const isOpen = searching || expandedIds.has(g.caseLawId);
return (
<div key={g.caseLawId} className="rounded-lg border border-rule bg-surface overflow-hidden">
<button
@@ -984,8 +1006,64 @@ function PendingPanel() {
);
}
const overWindow = !searching && pendingTotal > allItems.length;
return (
<div className="space-y-4">
{/* Locate bar — reach any pending halacha, not only the top window */}
<div className="flex items-center gap-2.5 rounded-lg border border-rule bg-surface px-3.5 py-2.5 shadow-sm">
<Search className="w-4 h-4 text-ink-muted shrink-0" />
<input
value={searchInput}
onChange={(e) => setSearchInput(e.target.value)}
placeholder="חיפוש בתור — מספר פס״ד, שם-תיק או נוסח-הלכה"
dir="rtl"
className="flex-1 bg-transparent border-0 outline-none text-sm text-ink placeholder:text-ink-muted"
/>
{searchInput && (
<button
type="button"
onClick={() => setSearchInput("")}
className="shrink-0 w-5 h-5 rounded-full bg-rule-soft text-ink-muted hover:text-navy
flex items-center justify-center text-[0.7rem]"
title="נקה"
>
<X className="w-3 h-3" />
</button>
)}
</div>
{overWindow && (
<p className="flex items-center gap-2 text-[0.78rem] text-ink-muted px-1 leading-relaxed">
<span className="bg-info-bg text-info rounded-full px-2 py-0.5 font-semibold text-[0.72rem] shrink-0">
חלון התצוגה
</span>
<span>
התור מציג את <b className="text-navy">{allItems.length}</b> ההלכות בעלות-העדיפות מתוך{" "}
<b className="text-navy">{pendingTotal}</b> הממתינות. הלכה מחוץ לחלון אתר אותה בחיפוש.
</span>
</p>
)}
{searching && (
<div className="flex items-center gap-2 flex-wrap rounded-lg border border-gold/50 bg-gold-wash px-3.5 py-2.5 text-sm text-navy">
<span>מציג ממתינות עבור</span>
<span className="rounded bg-navy text-parchment text-[0.78rem] font-semibold px-2 py-0.5">
{search}
</span>
<span className="text-ink-muted">
· {pendingTotal} {pendingTotal === 1 ? "התאמה" : "התאמות"}
</span>
<button
type="button"
onClick={() => setSearchInput("")}
className="ms-auto text-gold-deep font-semibold text-[0.8rem] underline hover:no-underline"
>
נקה חיפוש · חזרה לכל התור
</button>
</div>
)}
{viewToggle}
{body}
</div>

View File

@@ -211,7 +211,7 @@ export const libraryKeys = {
search: (q: string, filters: Record<string, string | boolean>) =>
[...libraryKeys.all, "search", q, filters] as const,
stats: () => [...libraryKeys.all, "stats"] as const,
halachotPending: () => [...libraryKeys.all, "halachot", "pending"] as const,
halachotPending: (search = "") => [...libraryKeys.all, "halachot", "pending", search] as const,
halachot: (filters: Record<string, string>) =>
[...libraryKeys.all, "halachot", filters] as const,
};
@@ -615,15 +615,18 @@ export function useRequestHalachotExtraction() {
* review panel splits this client-side by ACTION — "להכרעה" (has a panel round)
* vs "תיקון-חילוץ" (flagged, never adjudicated) — instead of the old empty
* clean/needsfix toggle. */
export function useHalachotPending(opts: { limit?: number } = {}) {
const { limit = 200 } = opts;
export function useHalachotPending(opts: { limit?: number; search?: string } = {}) {
const { limit = 200, search = "" } = opts;
const term = search.trim();
const qs = `review_status=pending_review&exclude_low_quality=false`
+ `&order_by_priority=true&cluster=true&include_equivalents=true`
+ `&include_panel_round=true&limit=${limit}`;
+ `&include_panel_round=true&with_total=true&limit=${limit}`
+ (term ? `&search=${encodeURIComponent(term)}` : "");
return useQuery({
queryKey: libraryKeys.halachotPending(),
queryKey: libraryKeys.halachotPending(term),
queryFn: ({ signal }) =>
apiRequest<{ items: Halacha[]; count: number }>(`/api/halachot?${qs}`, { signal }),
apiRequest<{ items: Halacha[]; count: number; total?: number }>(
`/api/halachot?${qs}`, { signal }),
staleTime: 5_000,
refetchOnMount: "always",
});