Commit b4049f15 authored by janickess's avatar janickess
Browse files

Fixed view for commits from API (#2)

parent cc7be883
......@@ -3,10 +3,11 @@ import Commit from "./commit";
function commitView() {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [data, setData] = useState(null);
let token = "YURNVX7jHALBGSGgz_Xa";
const [commits, setCommits] = useState([]);
let token = "3Nhst8cnMWx5puz8KEzR";
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
// Kode hentet fra https://www.freecodecamp.org/news/fetch-data-react/
fetch(
"https://gitlab.stud.idi.ntnu.no/api/v4/projects/11882/repository/commits",
{
......@@ -24,21 +25,26 @@ function commitView() {
})
.then((data) => {
console.log(data);
setData(data);
setCommits(data);
})
.catch((error) => {
console.error("Error fetching data: ", error);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// data.map((object: { title: string; id: number }) => (
// <Commit title={object.title} date={object.id} />
// ));
return (
<div className="commits">
<h3>Commits</h3>
<Commit title={"Updated homepage"} date={13.09} />
<Commit title={"Testesen"} date={14.09} />
{commits
? commits.map((commit: { message: string; created_at: number }) => (
<Commit
key="{commit.id}"
title={commit.message}
date={commit.created_at}
/>
))
: "Ingen"}
</div>
);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment