Create Home tab

This commit is contained in:
Takeshi Kimata
2024-03-20 20:09:06 +09:00
parent 66f36c1f31
commit 8a2ca8c563
8 changed files with 117 additions and 8 deletions

View File

@@ -0,0 +1,59 @@
"use client";
import Config from "@/config/config";
const apiServer = Config.apiServer;
import { useState, useEffect } from "react";
async function fetchProject(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);
}
}
type Props = {
projectId: string;
};
export function Home({ projectId }: Props) {
const [project, setProject] = useState({
Folders: [],
});
const url = `${apiServer}/projects/${projectId}`;
useEffect(() => {
async function fetchDataEffect() {
try {
const data = await fetchProject(url);
setProject(data);
console.log(data);
} catch (error) {
console.error("Error in effect:", error.message);
}
}
fetchDataEffect();
}, [url]);
return (
<>
<h3 className="font-bold ms-2">Home</h3>
<h4 className="font-bold ms-2 mt-5">
Folder num: {project.Folders.length}
</h4>
</>
);
}

View File

@@ -0,0 +1,9 @@
import { Home } from "./home";
export default function Page({ params }: { params: { projectId: string } }) {
return (
<>
<Home projectId={params.projectId} />
</>
);
}