aboutsummaryrefslogtreecommitdiff
path: root/islands/ListPackageDetails.tsx
blob: 3b7c36f89ce3f504dc6adfa849b6047f0f8640b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { useEffect, useState } from "preact/hooks";

export default function ListPackageDetails(props: any) {
    const [packages, setPacakges] = useState(props.packages);
    const [projectName, setProjectName] = useState(props.projectname);
    const [projectVersion, setProjectVersion] = useState(props.projectversion);
    const [projectDesc, setProjectDesc] = useState(props.projectdesc);
    const [isLoading, setIsLoading] = useState(false);
    useEffect(() => {
        fetchRegistry();
    }, [packages])

    const fetchRegistry = async () => {
        setIsLoading(true);
        const response = await fetch("/api/npm", {
            method: 'POST',
            body: JSON.stringify(packages)
        });
        const data = await response.json();
        setIsLoading(false);
    }

    return (
        <div>
            <h3>{projectName}</h3>
            <h4>{projectVersion}</h4>
            <h5>{projectDesc}</h5>
            {isLoading ? <>Loading</> : <>Data</>}
        </div>
    )
}