import React, { useRef, useState } from 'react'; import { Database, Upload, Trash2, LayoutTemplate, Search, RefreshCw, Plus, Check } from 'lucide-react'; import { useAppContext } from './AppContext'; import { SpecService } from '../services/api'; const CollectionsPage = ({ onCollectionSelected }) => { const { collections, activeSpecId, loadSpec, deleteSpec, fetchCollections, isLoading, addToast, } = useAppContext(); const fileInputRef = useRef(null); const [isUploading, setIsUploading] = useState(false); const [searchQuery, setSearchQuery] = useState(''); const handleFileUpload = async (e) => { const file = e.target.files?.[0]; if (!file) return; setIsUploading(true); try { await SpecService.uploadSpec(file); await fetchCollections(); addToast('success', `"${file.name}" uploaded successfully.`); } catch (err) { console.error('Upload failed', err); addToast('error', err.message || 'Failed to upload spec.'); } finally { setIsUploading(false); if (fileInputRef.current) fileInputRef.current.value = ''; } }; const filteredSpecs = collections.filter(spec => spec.name.toLowerCase().includes(searchQuery.toLowerCase()) ); return (
Loading collections…
{searchQuery ? 'Try a different search term or clear the filter.' : 'Upload a Swagger / OpenAPI spec (.json, .yaml) to get started.'}
{!searchQuery && ( )}