diff --git a/src/components/AnswerKeyForm/index.js b/src/components/AnswerKeyForm/index.js index eb9f6b8..abd823b 100644 --- a/src/components/AnswerKeyForm/index.js +++ b/src/components/AnswerKeyForm/index.js @@ -1,6 +1,7 @@ import React from 'react'; import './index.css'; import QuestionsRow from './QuestionsRow'; +import API from '../../lib/API'; class AnswerKeyForm extends React.Component { constructor(props) { @@ -77,16 +78,7 @@ class AnswerKeyForm extends React.Component { answers: this.state.answers.slice(), }; - const result = fetch( - 'https://bzwy0j344j.execute-api.us-east-2.amazonaws.com/dev/courses', - { - method: 'POST', - mode: 'cors', - cache: 'no-cache', - headers: {'Content-Type': 'application/json; charset=utf-8'}, - body: JSON.stringify(payload), - } - ).then(res => res.json()); + const result = API.answerKeys.create(payload); console.log(result); } diff --git a/src/components/AnswerKeyList/index.js b/src/components/AnswerKeyList/index.js index 3a5633c..5274fbd 100644 --- a/src/components/AnswerKeyList/index.js +++ b/src/components/AnswerKeyList/index.js @@ -1,10 +1,54 @@ import React from 'react'; +import API from '../../lib/API'; +import {Link} from 'react-router-dom'; class AnswerKeyList extends React.Component { + constructor(props) { + super(props); + + this.api = new API(); + this.state = { + courses: new Array(0), + }; + + this.api.answerKeys.list().then(r => this.setState({courses: r.courses})); + } + + getCreatedAt(unixEpoch) { + if (!unixEpoch) { + return ''; + } + + const date = new Date(); + date.setTime(unixEpoch); + + return date.getMonth() + '/' + date.getDate() + '/' + date.getFullYear(); + } + render() { + const courseRows = this.state.courses.map((course, index) => ( + + {course.name} + {this.getCreatedAt(course.created_at)} + + edit + + + )); + return (

Answer Keys

+ + + + + + + + + {courseRows} +
Course nameCreated 
); } diff --git a/src/components/App.js b/src/components/App.js index 9d57f66..ea12f63 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -8,16 +8,16 @@ import {BrowserRouter as Router, Route} from 'react-router-dom'; class App extends Component { render() { return ( -
- - + +
+
- -
+
+ ); } } diff --git a/src/components/NavBar/index.js b/src/components/NavBar/index.js index 7a1480c..e1270c6 100644 --- a/src/components/NavBar/index.js +++ b/src/components/NavBar/index.js @@ -1,5 +1,6 @@ import React, {Component} from 'react'; import './index.css'; +import {Link} from 'react-router-dom'; class Header extends Component { render() { @@ -8,7 +9,9 @@ class Header extends Component {