Commit 31a70dee authored by David Haynes's avatar David Haynes 🙆

PoC calling Go API w/ session auth if present

- render some info about golinks if we have the ability to, otherwise don't render
parent 0292219d
Pipeline #2981 passed with stage
in 55 seconds
import React from "react";
class GolinksList extends React.Component {
constructor(props) {
super(props);
this.state = {
error: null,
isLoaded: false,
golinks: []
};
}
componentDidMount() {
if (window.django.user.is_authenticated == "True") {
fetch("/api/golinks")
.then(res => res.json())
.then(
result => {
this.setState({
isLoaded: true,
golinks: result
});
},
// Note: it's important to handle errors here
// instead of a catch() block so that we don't swallow
// exceptions from actual bugs in components.
error => {
this.setState({
isLoaded: true,
error
});
}
);
}
}
render() {
const { error, isLoaded, golinks } = this.state;
if (error) {
return <div>Error: {error.message}</div>;
} else if (!isLoaded) {
if (window.django.user.is_authenticated == "True") {
return <div>Loading...</div>;
} else {
return <div />;
}
} else {
return (
<div>
{golinks.map(golink => (
<h1 key={golink.short}>{golink.short}</h1>
))}
</div>
);
}
}
}
export default GolinksList;
......@@ -4,5 +4,12 @@ import "masonstrap/build/js/masonstrap.min.js";
import React from "react";
import ReactDOM from "react-dom";
import AuthButton from "./AuthButton.jsx";
import Golinkslist from "./GolinksList.jsx";
ReactDOM.render(<AuthButton />, document.getElementById("root"));
ReactDOM.render(
<div>
<AuthButton />
<Golinkslist />
</div>,
document.getElementById("root")
);
Markdown is supported
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