import { h, Fragment } from 'preact'; import { useEffect, useState } from 'preact/hooks'; import Styles from './PluginSearchPage.module.css'; async function searchPlugins(val) { const params3 = new URLSearchParams([ ['q', 'snowpack plugin ' + (val || '')], ['count', '100'], ]); const res = await fetch( `https://api.skypack.dev/v1/search?${params3.toString()}`, ); const jsonres = await res.json(); return jsonres.results; } function Card({ result }) { const updatedAtFormatted = Intl.DateTimeFormat('en', { month: 'long', day: 'numeric', year: 'numeric', }).format(Date.parse(result.updatedAt)); return (
  • {result.name}

    {result.description.split('. ')[0]}

    Updated

  • ); } function PluginSearchPageLive() { const searchParams = new URLSearchParams(window.location.search); const [results, setResults] = useState(null); const [searchQuery, setSearchQuery] = useState(searchParams.get('q')); useEffect(() => { (async () => { setResults(await searchPlugins(searchParams.get('q'))); })(); }, []); async function onFormSubmit(e) { e.preventDefault(); const form = new FormData(e.target); const formula = form.get('q'); // document.getElementById('loading-message').style.display = 'block'; const searchParams = new URLSearchParams(window.location.search); searchParams.set('q', formula); window.history.pushState(null, null, '?' + searchParams.toString()); setSearchQuery(formula); setResults(await searchPlugins(formula)); return false; } return ( <>
    {!searchQuery && results && results.length > 50 && `${results.length}+ plugins available!`}
    {!results && (
    Loading...
    )} {results && results.length === 0 && ( )} {results && results.length > 0 && ( )}
    ); } export default function PluginSearchPage(props) { return import.meta.env.astro ? (
    Loading...
    ) : ( ); }