Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

full working #195

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
full
  • Loading branch information
serjt12 committed Jan 25, 2018
commit 4bb1d691d3b45d9bbbb5abb4840719b94c3f5735
19 changes: 7 additions & 12 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ export const CREATE_POST = "create_posts";
export const FETCH_POST = "fetch_post";
export const DELETE_POST = "delete_post";



const ROOT_URL = "https://reduxblog.herokuapp.com/api";
const API_KEY = "?key=mykey4445";
const url = `${ROOT_URL}/posts${API_KEY}`;


export function fetchPosts() {

const request = axios.get(url);

return {
Expand All @@ -22,17 +18,15 @@ export function fetchPosts() {
};
}


export function createPost(values, callback){
const request = axios.post(url, values)
.then(() => callback());
export function createPost(values, callback) {
const request = axios.post(url, values).then(() => callback());
return {
type: CREATE_POST,
payload: request
};
}

export function fetchPost(id){
export function fetchPost(id) {
const request = axios.get(`${ROOT_URL}/posts/${id}${API_KEY}`);

return {
Expand All @@ -42,10 +36,11 @@ export function fetchPost(id){
}

export function deletePost(id, callback) {
const request = axios.delete(`${ROOT_URL}/posts/${id}${API_KEY}`)
.then(() => callback());
const request = axios
.delete(`${ROOT_URL}/posts/${id}${API_KEY}`)
.then(() => callback());
return {
type: DELETE_POST,
payload: id
};
}
}
3 changes: 1 addition & 2 deletions src/components/posts_show.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Component } from "react";
import { connect } from "react-redux";
import { fetchPost } from "../actions";
import { deletePost } from "../actions";
import { fetchPost, deletePost } from "../actions";
import { Link } from "react-router-dom";

class PostsShow extends Component {
Expand Down