"use client"; import { useState, useEffect } from 'react'; import { ChatHandler } from '@/app/components/ui/chat'; import { IconSpinner } from '@/app/components/ui/icons'; export default function ChatSelection( props: Pick, ) { const [publicCollections, setPublicCollections] = useState([]); const [isLoading, setIsLoading] = useState(true); // Loading state const handleCollectionSelect = (collectionId: string, displayName: string) => { props.handleCollIdSelect(collectionId); props.handleCollNameSelect(displayName); }; // Retrieve the public collection sets from the database const getPublicCollections = async () => { setIsLoading(true); // Set loading state to true // Fetch the public collection sets from the API const response = await fetch('/api/public/collections', { method: 'GET', headers: { 'Content-Type': 'application/json', }, }); if (!response.ok) { console.error("Error fetching public collections:", response.statusText); return; } const data = await response.json(); // Sort the collections by created date in descending order (oldest first) const sortedPublicCollections = data.publicCollections.sort((a: any, b: any) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime()); setPublicCollections(sortedPublicCollections); setIsLoading(false); // Set loading state to false } // On component mount, retrieve the public collection sets from the database useEffect(() => { getPublicCollections(); }, []); // console.log('publicCollections:', publicCollections); return (

Select Document Set to Chat with:

{isLoading ? ( ) : publicCollections.length === 0 ? (
No collections found.
) : publicCollections.map((collection, index) => (
))}
); };