diff --git a/src/App.js b/src/App.js index b477422..1e86f1b 100644 --- a/src/App.js +++ b/src/App.js @@ -1,6 +1,13 @@ import React from 'react' import axios from 'axios' +import { + createArticle, + updateArticle, + deleteArticle, + selectArticle, +} from './controllers/articles' + import { createTask, updateTask, @@ -20,6 +27,8 @@ import { updateProfile } from './controllers/profile' import { About, + Articles, + UpdateArticle, Tasks, UpdateTask, Profile, @@ -39,6 +48,7 @@ const defaultState = { component: 'projects', // TODO try to get rid of: search: '', + newArticle: '', newTask: '', newProject: '', project: {}, @@ -52,6 +62,10 @@ class App extends React.Component { this.handleChange = this.handleChange.bind(this) this.handleSubmit = this.handleSubmit.bind(this) + this.createArticle = createArticle.bind(this) + this.updateArticle = updateArticle.bind(this) + this.deleteArticle = deleteArticle.bind(this) + this.createTask = createTask.bind(this) this.updateTask = updateTask.bind(this) this.deleteTask = deleteTask.bind(this) @@ -62,10 +76,21 @@ class App extends React.Component { this.updateProfile = updateProfile.bind(this) + this.selectArticle = selectArticle.bind(this) this.selectTask = selectTask.bind(this) this.selectProject = selectProject.bind(this) } + async fetchArticles() { + try { + const { data } = await axios.get(API + '/api/articles') + return data + } catch (error) { + console.log(error) + this.setState({ error }) + } + } + async fetchTasks() { try { const { data } = await axios.get(API + '/api/tasks') @@ -87,9 +112,10 @@ class App extends React.Component { } async fetchData() { + const articles = await this.fetchArticles() const tasks = await this.fetchTasks() const projects = await this.fetchProjects() - await this.setState({ loading: false, tasks, projects }) + await this.setState({ loading: false, articles, tasks, projects }) } componentDidMount() { @@ -139,6 +165,26 @@ class App extends React.Component { /> ) } + renderArticles() { + return ( + ) + } + renderUpdateArticle() { + return ( + ) + } renderProjects() { return ( +

Articles

+
    + {props.articles && + props.articles.map(article => ( +
  • + + +
  • + ))} + +
  • +
    + + +
    +
  • +
+ + ) +} + +export default Articles diff --git a/src/components/index.js b/src/components/index.js index 789fd86..c97176a 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -1,5 +1,7 @@ export { default as Navbar } from './navbar' export { default as About } from './about' +export { default as Articles } from './articles' +export { default as UpdateArticle } from './update-article' export { default as Tasks } from './tasks' export { default as UpdateTask } from './update-task' export { default as Profile } from './profile' diff --git a/src/components/navbar.js b/src/components/navbar.js index 794ea42..4275efe 100644 --- a/src/components/navbar.js +++ b/src/components/navbar.js @@ -23,13 +23,23 @@ function Navbar(props) {