DebugRead.jsx 1.76 KB
Newer Older
1 2
import React from "react";
import { GetAllGoLinks } from "../../Utils";
3
import { Button, Card, CardBody, CardTitle, Table } from "reactstrap";
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

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>
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
        <Card>
          <CardBody>
            <CardTitle className="d-flex">
              Read{" "}
              <Button
                className="ml-auto"
                onClick={this.refreshGoLinks}
                outline
                color="primary"
              >
                Refresh
              </Button>
            </CardTitle>

            <Table>
              <thead>
                <tr>
                  <th>short</th>
                  <th>destination</th>
                  <th>expires</th>
                </tr>
              </thead>
              <tbody>
                {this.state.GoLinks.map(golink => (
                  <tr key={golink.short}>
                    <td>
                      <a href={`/${golink.short}`}> /{golink.short}</a>
                    </td>
                    <td>{golink.destination}</td>
                    <td>{golink.date_expires}</td>
                  </tr>
                ))}
              </tbody>
            </Table>
          </CardBody>
        </Card>
69 70 71 72 73 74
      </div>
    );
  }
}

export default DebugRead;