"use client"; import { useEffect, useState } from "react"; import { title } from "@/components/primitives"; import { ProjectCard } from "./project-card"; import { Button } from "@nextui-org/react"; import Config from "@/config/config"; const apiServer = Config.apiServer; /** * fetch project records * * @param {string} url - API endpoint url * @returns {Promise} - project record array * @throws {Error} */ async function fetchProjects(url) { try { const response = await fetch(url, { method: "GET", headers: { "Content-Type": "application/json", }, }); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } const data = await response.json(); return data; } catch (error) { console.error("Error fetching data:", error.message); } } /** * Create project * * @async * @function * @throws {Error} */ async function createProject() { const newProjectData = { name: "新しいプロジェクト", detail: "新しいプロジェクトの詳細説明がここにくるよ", }; const fetchOptions = { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(newProjectData), }; const url = `${apiServer}/projects`; fetch(url, fetchOptions) .then((response) => { if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } return response.json(); }) .then((data) => { console.log("New project created:", data); }) .catch((error) => { console.error("Error creating new project:", error); }); } export default function ProjectsPage() { const [projects, setProjects] = useState([]); const url = `${apiServer}/projects`; useEffect(() => { async function fetchDataEffect() { try { const data = await fetchProjects(url); setProjects(data); } catch (error) { console.error('Error in effect:', error.message); } } fetchDataEffect(); }, []); return (

Projects

{projects.map((project, index) => ( ))}
); }