Commit b74653e6 authored by David Haynes's avatar David Haynes 🙆

Abstracted DebugRead into it's own component

- added refresh button to allow for.. just that
parent 45271a66
Pipeline #3569 passed with stage
in 1 minute and 2 seconds
import React from "react";
import { GetAllGoLinks } from "../../Utils";
import { Button } from "reactstrap";
class DebugRead extends React.Component {
constructor(props) {
super(props);
this.state = {
GoLinks: [],
error: null
};
// This binding is necessary to make `this` work in the callback
this.refreshGoLinks = this.refreshGoLinks.bind(this);
}
async refreshGoLinks() {
GetAllGoLinks()
.then(data =>
this.setState({
GoLinks: data
})
)
.catch(reason => this.setState({ error: reason }));
}
async componentDidMount() {
this.refreshGoLinks();
}
render() {
return (
<div>
<Button onClick={this.refreshGoLinks} color="primary">
Refresh
</Button>{" "}
{this.state.GoLinks.map(golink => (
<li key={golink.short}>
<a href={`/${golink.short}`}> /{golink.short}</a> |{" "}
{golink.destination}
</li>
))}
</div>
);
}
}
export default DebugRead;
import AuthButton from "./AuthButton"; import AuthButton from "./AuthButton";
import DebugRead from "./DebugRead";
export { AuthButton }; export { AuthButton, DebugRead };
import React from "react"; import React from "react";
import { Formik, Field, Form, ErrorMessage } from "formik"; import { Formik, Field, Form, ErrorMessage } from "formik";
import * as Yup from "yup"; import * as Yup from "yup";
import { PageTemplate } from "Components"; import { PageTemplate, DebugRead } from "Components";
import { GetAllGoLinks } from "../../Utils";
const SignupSchema = Yup.object().shape({ const SignupSchema = Yup.object().shape({
password: Yup.string() password: Yup.string()
...@@ -16,17 +15,7 @@ const SignupSchema = Yup.object().shape({ ...@@ -16,17 +15,7 @@ const SignupSchema = Yup.object().shape({
class DebugCRUD extends React.Component { class DebugCRUD extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { AllGoLinks: [], error: null }; this.state = {};
}
async componentDidMount() {
GetAllGoLinks()
.then(data =>
this.setState({
AllGoLinks: data
})
)
.catch(reason => this.setState({ error: reason }));
} }
render() { render() {
...@@ -59,13 +48,7 @@ class DebugCRUD extends React.Component { ...@@ -59,13 +48,7 @@ class DebugCRUD extends React.Component {
/> />
<h3>Read</h3> <h3>Read</h3>
<DebugRead />
{this.state.AllGoLinks.map(golink => (
<li key={golink.short}>
<a href={`/${golink.short}`}> /{golink.short}</a> |{" "}
{golink.destination}
</li>
))}
<h3>Update</h3> <h3>Update</h3>
<Formik <Formik
......
import { AuthButton } from "./Molecules"; import { AuthButton, DebugRead } from "./Molecules";
import { NavBar } from "./Organisms"; import { NavBar } from "./Organisms";
import { HomePage, AboutPage, DhaynesPage, DebugCRUD } from "./Pages"; import { HomePage, AboutPage, DhaynesPage, DebugCRUD } from "./Pages";
import { PageTemplate } from "./Templates"; import { PageTemplate } from "./Templates";
...@@ -6,6 +6,7 @@ import { PageTemplate } from "./Templates"; ...@@ -6,6 +6,7 @@ import { PageTemplate } from "./Templates";
export { export {
//Molecules //Molecules
AuthButton, AuthButton,
DebugRead,
//Organisms //Organisms
NavBar, NavBar,
//Pages //Pages
......
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