import { useCallback, useEffect, useRef, useState } from "react"; import { clsx } from "clsx"; import { RefreshCw } from "lucide-react"; import { DocumentsFacetsNav } from "../../../facets"; import { DocumentTable } from "../DocumentTable"; import { useDocumentSearch, useWatchDocumentSearchFacets, useWatchDocumentSearchResult } from "../search/DocumentSearchContext"; import { DocumentSearchProvider } from "../search/DocumentSearchProvider"; import { ContentDispositionButton } from "./ContentDispositionButton"; import { ColumnLayout, ContentObjectItem } from "@vertesia/common"; import { Button, ErrorBox, Spinner, useIntersectionObserver } from "@vertesia/ui/core"; import { useUITranslation } from '../../../../i18n/index.js'; const layout: ColumnLayout[] = [ { "name": "Name", "field": "properties.title", "type": "string", "fallback": "name" }, { "name": "Type", "field": "type.name", "type": "string" }, { "name": "Status", "field": "status", "type": "string" }, { "name": "Created At", "field": "created_at", "type": "date" } ]; const LAST_DISPLAYED_VIEW = "vertesia.content_store.lastDisplayedView" interface SelectDocumentProps { onChange: (value: ContentObjectItem) => void; type?: string; mimeType?: string; /** IDs of already-selected documents — used to highlight rows */ selectedIds?: Set; } export function SelectDocument({ onChange, selectedIds }: Readonly) { const onRowClick = (selected: ContentObjectItem) => { onChange(selected || undefined); } return ( ) } interface SelectDocumentImplProps { onRowClick: (selected: ContentObjectItem) => void; selectedIds?: Set; } function SelectDocumentImpl({ onRowClick, selectedIds }: Readonly) { const { t } = useUITranslation(); const highlightRow = useCallback( (item: ContentObjectItem) => !!selectedIds?.has(item.id), [selectedIds], ); const [isReady, setIsReady] = useState(false); const [isGridView, setIsGridView] = useState(localStorage.getItem(LAST_DISPLAYED_VIEW) === "grid"); const { search, isLoading, error, objects, hasMore } = useWatchDocumentSearchResult(); const loadMoreRef = useRef(null); useIntersectionObserver(loadMoreRef, () => { if (isReady && hasMore && !isLoading) { setIsReady(false); search.loadMore(true) .finally(() => { setIsReady(true); }); } }, { threshold: 0.1, deps: [isReady, hasMore, isLoading] }); useEffect(() => { search.search() .finally(() => { setIsReady(true); }); }, []); const facets = useWatchDocumentSearchFacets(); const facetSearch = useDocumentSearch(); const handleRefetch = () => { setIsReady(false); search.search().then(() => setIsReady(true)); } if (error) { return {error.message} } return (
{/* Documents Display Grid or Table */} {/* Intersection observer target */}
{/* Loading spinner */}
) }