-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ft-bookmark-#164350372] implement bookmark functionality
- Loading branch information
Isaiah Afolayan
authored and
Isaiah Afolayan
committed
Mar 3, 2019
1 parent
27fee6d
commit 6095460
Showing
12 changed files
with
188 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,33 @@ | ||
import { toast } from 'react-toastify'; | ||
import { createBookmark, removeBookmark } from '../../helpers/axiosHelper/bookmark'; | ||
import actionTypes from '../readArticleAction/actionTypes'; | ||
|
||
const { TOGGLE_ARTICLE_BOOKMARK } = actionTypes; | ||
|
||
export const bookmarkSuccess = () => ({ | ||
type: TOGGLE_ARTICLE_BOOKMARK | ||
}); | ||
|
||
export const bookmarkedAction = bookmarkDetail => async (dispatch) => { | ||
try { | ||
const response = await createBookmark(bookmarkDetail); | ||
dispatch(bookmarkSuccess()); | ||
toast.success(response.data.message); | ||
} catch (error) { | ||
toast.error(error.response.data.message); | ||
} | ||
}; | ||
|
||
export const removeBookmarkSuccess = () => ({ | ||
type: TOGGLE_ARTICLE_BOOKMARK | ||
}); | ||
|
||
export const removeBookmarkAction = bookmarkDetail => async (dispatch) => { | ||
try { | ||
const response = await removeBookmark(bookmarkDetail); | ||
dispatch(removeBookmarkSuccess()); | ||
toast.success(response.data.message); | ||
} catch (error) { | ||
toast.error(error.response.data.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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
const actionTypes = { | ||
READ_ARTICLE_LOADING: 'READ_ARTICLE_LOADING', | ||
READ_ARTICLE_SUCCESS: 'READ_ARTICLE_SUCCESS', | ||
READ_ARTICLE_FAILURE: 'READ_ARTICLE_FAILURE' | ||
READ_ARTICLE_FAILURE: 'READ_ARTICLE_FAILURE', | ||
TOGGLE_ARTICLE_BOOKMARK: 'TOGGLE_ARTICLE_BOOKMARK' | ||
}; | ||
|
||
export default actionTypes; |
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
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
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
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,29 @@ | ||
import axios from 'axios'; | ||
import { API_BASE_URL } from '../../constants'; | ||
|
||
const options = { | ||
headers: { | ||
authorization: localStorage.getItem('authentication') | ||
} | ||
}; | ||
|
||
const createBookmark = async (bookmarkDetail) => { | ||
const response = await axios.post(`${API_BASE_URL}/articles/bookmark`, bookmarkDetail, options); | ||
return response; | ||
}; | ||
|
||
const removeBookmark = async (bookmarkDetail) => { | ||
const response = await axios({ | ||
method: 'DELETE', | ||
url: `${API_BASE_URL}/articles/bookmark`, | ||
data: bookmarkDetail, | ||
headers: options.headers | ||
}); | ||
return response; | ||
}; | ||
|
||
|
||
export { | ||
createBookmark, | ||
removeBookmark | ||
}; |
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,29 @@ | ||
import axios from 'axios'; | ||
import { API_BASE_URL } from '../constants' | ||
|
||
const options = { | ||
headers: { | ||
authorization: localStorage.getItem('authentication') | ||
} | ||
}; | ||
|
||
const createBookmark = async (bookmarkDetail) => { | ||
const response = await axios.post(`${API_BASE_URL}/articles/bookmark`, bookmarkDetail, options); | ||
return response; | ||
}; | ||
|
||
const removeBookmark = async (bookmarkDetail) => { | ||
const response = await axios({ | ||
method: 'DELETE', | ||
url: `${API_BASE_URL}/articles/bookmark`, | ||
data: bookmarkDetail, | ||
headers: options.headers | ||
}); | ||
return response; | ||
}; | ||
|
||
|
||
export { | ||
createBookmark, | ||
removeBookmark | ||
}; |
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
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
Oops, something went wrong.