Commit 45f563f3 authored by Keith Charlene Tan Esmena's avatar Keith Charlene Tan Esmena
Browse files

(#1) Put data in state

parent c8971e57
......@@ -2,52 +2,37 @@ import React, { Component, useEffect, useState } from "react";
import { isUnparsedSource } from "typescript";
class Issue extends React.Component {
// constructor(props: any) {
// super(props);
// this.state = {
// id: 0,
// title: "",
// };
// }
constructor(props: any) {
super(props);
this.state = {
issues: [],
};
}
// constructor(props: any) {
// super(props);
// this.state = {
// issues: ["hey"],
// };
// }
componentDidMount() {
let token = "3Nhst8cnMWx5puz8KEzR";
// componentDidMount() {
// console.log("Hei");
// let token = "3Nhst8cnMWx5puz8KEzR";
// fetch("https://gitlab.stud.idi.ntnu.no/api/v4/projects/11882/issues", {
// headers: {
// Authorization: `Bearer ${token}`,
// method: "GET",
// },
// })
// .then((response) => {
// if (response.ok) {
// console.log("Hallo??");
// return response.json();
// }
// throw response;
// })
// .then((data) => {
// console.log(data);
// this.setState({ issues: data });
// })
// .catch((error) => {
// console.error("Error fetching data: ", error);
// });
// }
fetch("https://gitlab.stud.idi.ntnu.no/api/v4/projects/11882/issues", {
headers: {
Authorization: `Bearer ${token}`,
method: "GET",
},
})
.then((result) => result.json())
.then((issues) => this.setState({ issues }));
}
render() {
{
console.log(this.state);
}
return (
<div className="panel panel-default">
{/* <div className="panel-heading">{this.state.title}</div>
<div className="panel-body"></div>
<div>{this.state.id}</div> */}
{/* <ul>{this.state.issues}</ul> */}
{/* <p>{this.state.issues[0]}</p> */}
</div>
);
}
......
import React, { Component } from "react";
class IssueView extends React.Component<{}> {
state = {
issues: [],
};
componentDidMount() {
console.log("Hei");
let token = "3Nhst8cnMWx5puz8KEzR";
fetch("https://gitlab.stud.idi.ntnu.no/api/v4/projects/11882/issues", {
headers: {
Authorization: `Bearer ${token}`,
method: "GET",
},
})
.then((response) => {
if (response.ok) {
console.log("Hallo??");
return response.json();
}
throw response;
})
.then((data) => {
console.log(data);
this.setState({ issues: data });
})
.catch((error) => {
console.error("Error fetching data: ", error);
});
}
// state = {
// issues: [],
// };
// componentDidMount() {
// console.log("Hei");
// let token = "3Nhst8cnMWx5puz8KEzR";
// fetch("https://gitlab.stud.idi.ntnu.no/api/v4/projects/11882/issues", {
// headers: {
// Authorization: `Bearer ${token}`,
// method: "GET",
// },
// })
// .then((response) => {
// if (response.ok) {
// console.log("Hallo??");
// return response.json();
// }
// throw response;
// })
// .then((data) => {
// console.log(data);
// this.setState({ issues: data });
// })
// .catch((error) => {
// console.error("Error fetching data: ", error);
// });
// }
render() {
return (
......@@ -41,6 +41,9 @@ class IssueView extends React.Component<{}> {
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<div id="issueBox">{this.props.children}</div>
<div className="issues">
<h3>Issues</h3>
</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