import { useState, useEffect, useRef } from 'react'; import { Helmet } from 'react-helmet'; // Import Helmet function Cache() { const [searchQuery, setSearchQuery] = useState(''); const [cacheData, setCacheData] = useState([]); const [keyCount, setKeyCount] = useState(0); // New state to store the key count const debounceTimeout = useRef(null); // Fetch the key count when the component mounts useEffect(() => { const fetchKeyCount = async () => { try { const response = await fetch('/api/cache/keycount'); const data = await response.json(); setKeyCount(data.count); // Update key count } catch (error) { console.error('Error fetching key count:', error); } }; fetchKeyCount(); }, []); // Run only once when the component mounts const handleInputChange = (event) => { const query = event.target.value; setSearchQuery(query); // Update the search query // Clear the previous timeout if (debounceTimeout.current) { clearTimeout(debounceTimeout.current); } // Set a new timeout to send the API call after 1 second of no typing debounceTimeout.current = setTimeout(() => { if (query.trim() !== '') { sendApiCall(query); // Only call the API if the query is not empty } else { setCacheData([]); // Clear results if query is empty } }, 1000); // 1 second delay }; const sendApiCall = (text) => { fetch('/api/cache/search', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ input: text }), }) .then((response) => response.json()) .then((data) => setCacheData(data)) // Update cache data with the results .catch((error) => console.error('Error:', error)); }; return (
PSSH | KID | Key |
---|---|---|
{item.PSSH} | {item.KID} | {item.Key} |
No data found |