-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbbee51
commit 526ecc3
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const BLOG_FETCH_REQUEST = "BLOG_FETCH_REQUEST" | ||
export const BLOG_FETCH_SUCCESS = "BLOG_FETCH_SUCCESS" | ||
export const BLOG_FETCH_FAIL = "BLOG_FETCH_FAIL" | ||
|
||
export const BLOG_CREATE = "BLOG_CREATE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import axios from "axios" | ||
import { BLOG_FETCH_FAIL, BLOG_FETCH_REQUEST, BLOG_FETCH_SUCCESS } from "../../constants/blogConstant" | ||
// @ GET blogs | ||
export const fetchBlogs = () => async (dispatch) => { | ||
try { | ||
dispatch({ type:BLOG_FETCH_REQUEST}) | ||
|
||
const { data } = await axios.get(`/api/blogs`) | ||
|
||
dispatch({ | ||
type: BLOG_FETCH_SUCCESS, | ||
payload: data | ||
}) | ||
|
||
} catch (error) { | ||
console.log(error); | ||
dispatch({ | ||
type: BLOG_FETCH_FAIL, | ||
payload: error.response && error.response.data.message ? error.response.data.message : error.message | ||
}) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { BLOG_FETCH_FAIL, BLOG_FETCH_REQUEST, BLOG_FETCH_SUCCESS } from "../../constants/blogConstant" | ||
|
||
export const blogListReducer = ( blogs=[], action) => { | ||
switch (action.type) { | ||
case BLOG_FETCH_REQUEST: | ||
return { loading: true, blogs: [] } | ||
|
||
case BLOG_FETCH_SUCCESS: | ||
return { loading: false, blogs: action.payload} | ||
|
||
case BLOG_FETCH_FAIL: | ||
return { loading: false, error: action.payload } | ||
|
||
default: | ||
return blogs | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters