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

Select Your Document Set to Chat with:

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