Skip to content

Commit

Permalink
feat(use-redux): add config
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-well committed Feb 19, 2019
1 parent 516ded1 commit b02822b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config.js
@@ -0,0 +1,3 @@
global.myBlog = {
apiServer:'http://localhost:3300',
};
3 changes: 2 additions & 1 deletion src/actions/authenAction.js
@@ -1,9 +1,10 @@
import '../../config';
import history from '../history';
import { showAlert, toggleCloseAlertIcon } from '../actions/alertAction';

export const login = (data) => (dispatch, action) => {
dispatch(startRequest);
return fetch(`http://localhost:3300/api/auth/login`, {
return fetch(`${global.myBlog.apiServer}/api/auth/login`, {
method: 'POST',
mode: 'cors',
body: JSON.stringify(data),
Expand Down
3 changes: 2 additions & 1 deletion src/actions/deleteArticleAction.js
@@ -1,11 +1,12 @@
import '../../config';
import { switchMainContentAction } from '../actions/switchMainContentAction';
import { fetchArticlesByCategoryId } from '../actions/getCategoriesAction';
import { showAlert } from '../actions/alertAction';


export const toggleDeleteIcon = (data) => (dispatch, action) => {
dispatch(startDelete);
return fetch(`http://localhost:3300/api/articles/${data.id}?access_token=${data.access_token}`, {
return fetch(`${global.myBlog.apiServer}/api/articles/${data.id}?access_token=${data.access_token}`, {
method: 'DELETE',
mode: 'cors',
headers: new Headers({
Expand Down
7 changes: 4 additions & 3 deletions src/actions/getArticleAction.js
@@ -1,6 +1,7 @@
import '../../config';
export const fetchArticle = (id, access_token) => (dispatch, action) => {
dispatch(requestArticle);
return fetch(`http://localhost:3300/api/articles/${id}?access_token=${access_token}`)
return fetch(`${global.myBlog.apiServer}/api/articles/${id}?access_token=${access_token}`)
.then(response => response.json())
.then(json => {
dispatch(reciveArticle(json));
Expand All @@ -9,7 +10,7 @@ export const fetchArticle = (id, access_token) => (dispatch, action) => {
}

export const requestArticle = {
type: 'START_REQUEST_ARTICLE'
type: 'START_REQUEST_ARTICLE',
}

export const reciveArticle = (json) => ({
Expand All @@ -20,5 +21,5 @@ export const reciveArticle = (json) => ({

export const fetchError = (error) => ({
type: 'FETCH_ARTICLE_ERROR',
message: error
message: error,
})
3 changes: 2 additions & 1 deletion src/actions/getArticleListAction.js
@@ -1,6 +1,7 @@
import '../../config';
export const fetchArticles = (category_id) => (dispatch, action) => {
dispatch(requestArticles);
return fetch(`http://localhost:3300/api/categories/${category_id}/articles`)
return fetch(`${global.myBlog.apiServer}/api/categories/${category_id}/articles`)
.then(response => response.json())
.then(json => {
dispatch(receivePost(json));
Expand Down
3 changes: 2 additions & 1 deletion src/actions/getCategoriesAction.js
@@ -1,6 +1,7 @@
import '../../config';
export const fetchCategories = () => (dispathch, action) => {
dispathch(requestCategories);
return fetch('http://localhost:3300/api/categories')
return fetch(`${global.myBlog.apiServer}/api/categories`)
.then(response => response.json())
.then(json => {
dispathch(receiveCategories(json));
Expand Down
5 changes: 3 additions & 2 deletions src/actions/newArticleAction.js
@@ -1,3 +1,4 @@
import '../../config';
import history from '../history';
import { fetchArticle } from './getArticleAction';
import { switchMainContentAction } from './switchMainContentAction';
Expand Down Expand Up @@ -42,7 +43,7 @@ export const togglePublishIcon = {
// post create
export const createArticle = ({...data}) => (dispatch, action) => {
dispatch(startPostArticle)
return fetch(`http://localhost:3300/api/articles`, {
return fetch(`${global.myBlog.apiServer}/api/articles`, {
method: 'POST',
mode: 'cors',
body: JSON.stringify(data),
Expand All @@ -67,7 +68,7 @@ export const createArticle = ({...data}) => (dispatch, action) => {

export const updateArticle = ({...data}) => (dispatch, action) => {
dispatch(startPostArticle)
return fetch(`http://localhost:3300/api/articles/${data.id}`, {
return fetch(`${global.myBlog.apiServer}/api/articles/${data.id}`, {
method: 'PUT',
mode: 'cors',
body: JSON.stringify(data),
Expand Down

0 comments on commit b02822b

Please sign in to comment.