Commit cc7be883 authored by janickess's avatar janickess
Browse files

Added connection to API (#2)

parent 6397b1e1
import React from "react";
import "./App.css";
import CommitView from "./components/commitView";
function App() {
return (
<div className="App">
<header className="App-header">
<h1>Gitlab statistikk</h1>
</header>
<section>
<h3>Issues</h3>
<p>Legg inn det under her :)</p>
</section>
<CommitView />
</div>
<>
<head>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<div className="App">
<header className="App-header">
<h1>Gitlab statistikk</h1>
</header>
<section>
<h3>Issues</h3>
<p>Legg inn det under her :)</p>
</section>
<CommitView />
</div>
</>
);
}
......
......@@ -6,20 +6,10 @@ type commitProps = {
};
function commit({ title, date }: commitProps) {
return (
<>
<head>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<div className="panel panel-default">
<div className="panel-heading">{title}</div>
<div className="panel-body">{date}</div>
</div>
</>
<div className="panel panel-default">
<div className="panel-heading">{title}</div>
<div className="panel-body">{date}</div>
</div>
);
}
......
import { useEffect, useState } from "react";
import Commit from "./commit";
function commitView() {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [data, setData] = useState(null);
let token = "YURNVX7jHALBGSGgz_Xa";
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
fetch(
"https://gitlab.stud.idi.ntnu.no/api/v4/projects/11882/repository/commits",
{
headers: {
Authorization: `Bearer ${token}`,
method: "GET",
},
}
)
.then((response) => {
if (response.ok) {
return response.json();
}
throw response;
})
.then((data) => {
console.log(data);
setData(data);
})
.catch((error) => {
console.error("Error fetching data: ", error);
});
}, []);
// data.map((object: { title: string; id: number }) => (
// <Commit title={object.title} date={object.id} />
// ));
return (
<div className="commits">
<h3>Commits</h3>
......
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