Skip to content

Commit 274a7f4

Browse files
puggued in actual API
1 parent 027f235 commit 274a7f4

File tree

20 files changed

+149
-138
lines changed

20 files changed

+149
-138
lines changed

client/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vercel

client/src/App.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ function App({ auth, getAdminPrivilages }) {
2121
useEffect(() => {
2222
store.dispatch(loadUser());
2323
getAdminPrivilages(true);
24+
25+
// eslint-disable-next-line
2426
}, []);
2527

2628
useEffect(() => {
2729
getAdminPrivilages(true);
30+
31+
// eslint-disable-next-line
2832
}, [auth.isAuthenticated]);
2933

3034
return (

client/src/actions/authAction.js

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,79 @@
1+
import Axios from "axios";
2+
import { API } from "..";
3+
import setAuthToken from "../utils/setAuthToken";
4+
import { setAlert } from "./alertAction";
15
import {
2-
REGISTER_SUCCESS,
3-
REGISTER_FAILURE,
4-
LOAD_USER,
5-
AUTH_ERROR,
6-
LOGIN_SUCCESS,
7-
LOGIN_FAILURE,
8-
LOGOUT,
9-
} from './types';
10-
11-
import Axios from 'axios';
12-
import setAuthToken from '../utils/setAuthToken';
13-
import { setAlert } from './alertAction';
6+
AUTH_ERROR,
7+
LOAD_USER,
8+
LOGIN_FAILURE,
9+
LOGIN_SUCCESS,
10+
LOGOUT,
11+
REGISTER_FAILURE,
12+
REGISTER_SUCCESS,
13+
} from "./types";
1414

1515
// Load user
1616
export const loadUser = () => async (dispatch) => {
17-
if (localStorage.getItem('token')) {
18-
setAuthToken(localStorage.getItem('token'));
19-
}
17+
if (localStorage.getItem("token")) {
18+
setAuthToken(localStorage.getItem("token"));
19+
}
2020

21-
try {
22-
const res = await Axios.get('/api/auth');
23-
dispatch({ type: LOAD_USER, payload: res.data });
24-
} catch (err) {
25-
dispatch({ type: AUTH_ERROR });
26-
}
21+
try {
22+
const res = await Axios.get(`${API}/api/auth`);
23+
dispatch({ type: LOAD_USER, payload: res.data });
24+
} catch (err) {
25+
dispatch({ type: AUTH_ERROR });
26+
}
2727
};
2828

2929
// Register user
3030
export const register = (formData) => async (dispatch) => {
31-
const config = {
32-
headers: {
33-
'Content-Type': 'application/json',
34-
},
35-
};
36-
try {
37-
const res = await Axios.post('/api/user', formData, config);
38-
dispatch({ type: REGISTER_SUCCESS, payload: res.data });
31+
const config = {
32+
headers: {
33+
"Content-Type": "application/json",
34+
},
35+
};
36+
try {
37+
const res = await Axios.post(`${API}/api/user`, formData, config);
38+
dispatch({ type: REGISTER_SUCCESS, payload: res.data });
3939

40-
// Load user after authentication
41-
dispatch(loadUser());
42-
} catch (err) {
43-
dispatch({ type: REGISTER_FAILURE });
40+
// Load user after authentication
41+
dispatch(loadUser());
42+
} catch (err) {
43+
dispatch({ type: REGISTER_FAILURE });
4444

45-
// Get errors array from backends
46-
const errors = err.response.data.errors;
47-
if (errors) {
48-
errors.forEach((error) => dispatch(setAlert(error.msg)));
49-
}
45+
// Get errors array from backends
46+
const errors = err.response.data.errors;
47+
if (errors) {
48+
errors.forEach((error) => dispatch(setAlert(error.msg)));
5049
}
50+
}
5151
};
5252

5353
// Login user
5454
export const login = (formData) => async (dispatch) => {
55-
const config = {
56-
headers: {
57-
'Content-Type': 'application/json',
58-
},
59-
};
60-
try {
61-
const res = await Axios.post('/api/auth', formData, config);
62-
dispatch({ type: LOGIN_SUCCESS, payload: res.data });
55+
const config = {
56+
headers: {
57+
"Content-Type": "application/json",
58+
},
59+
};
60+
try {
61+
const res = await Axios.post(`${API}/api/auth`, formData, config);
62+
dispatch({ type: LOGIN_SUCCESS, payload: res.data });
6363

64-
// Load user after authentication
65-
dispatch(loadUser());
66-
} catch (err) {
67-
dispatch({ type: LOGIN_FAILURE });
64+
// Load user after authentication
65+
dispatch(loadUser());
66+
} catch (err) {
67+
dispatch({ type: LOGIN_FAILURE });
6868

69-
// Get errors array from backends
70-
const errors = err.response.data.errors;
71-
if (errors) {
72-
errors.forEach((error) => dispatch(setAlert(error.msg)));
73-
}
69+
// Get errors array from backends
70+
const errors = err.response.data.errors;
71+
if (errors) {
72+
errors.forEach((error) => dispatch(setAlert(error.msg)));
7473
}
74+
}
7575
};
7676

7777
export const logout = () => (dispatch) => {
78-
dispatch({ type: LOGOUT });
78+
dispatch({ type: LOGOUT });
7979
};
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { COMMENT_TOAST, GET_COMMENTS, POST_COMMENT } from "./types";
21
import Axios from "axios";
2+
import { API } from "..";
3+
import { COMMENT_TOAST, GET_COMMENTS, POST_COMMENT } from "./types";
34

45
export const postComment = (msg, user_id, post_id) => async (dispatch) => {
56
const config = {
@@ -10,7 +11,7 @@ export const postComment = (msg, user_id, post_id) => async (dispatch) => {
1011
try {
1112
dispatch({ type: POST_COMMENT, payload: true });
1213
await Axios.put(
13-
`/api/post/comment/${user_id}/${post_id}`,
14+
`${API}/api/post/comment/${user_id}/${post_id}`,
1415
{ comment_msg: msg },
1516
config
1617
);
@@ -19,14 +20,12 @@ export const postComment = (msg, user_id, post_id) => async (dispatch) => {
1920
setTimeout(() => {
2021
dispatch({ type: COMMENT_TOAST, payload: false });
2122
}, 5000);
22-
} catch (err) {
23-
}
23+
} catch (err) {}
2424
};
2525

2626
export const getComments = (post_id) => async (dispatch) => {
2727
try {
28-
const res = await Axios.get(`/api/post/comment/all/${post_id}`);
28+
const res = await Axios.get(`${API}/api/post/comment/all/${post_id}`);
2929
dispatch({ type: GET_COMMENTS, payload: res.data });
30-
} catch (err) {
31-
}
30+
} catch (err) {}
3231
};
Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1+
import axios from "axios";
2+
import { API } from "..";
13
import {
2-
GET_POST,
3-
SET_CURRENT_POST,
4+
CLEAN_POST_ACTION,
45
CLEAR_POST,
5-
UPLOAD_POST,
6-
GET_USER_POSTS,
6+
CLEAR_POST_ID,
77
DELETE_POST,
8-
LIKE_POST,
9-
TOGGLE_SAVE_POST,
10-
GET_SAVED_POST,
118
GET_LIKED_POST,
9+
GET_POST,
1210
GET_POST_ID,
13-
CLEAR_POST_ID,
14-
SET_LOADING_POST_TRUE,
15-
RESET_IMAGE_UPLOAD,
16-
CLEAN_POST_ACTION,
11+
GET_SAVED_POST,
12+
GET_USER_POSTS,
13+
LIKE_POST,
1714
REALLY_GET_ALL_POSTS,
15+
RESET_IMAGE_UPLOAD,
1816
SAVE_POST_TOAST,
17+
SET_CURRENT_POST,
18+
SET_LOADING_POST_TRUE,
19+
TOGGLE_SAVE_POST,
20+
UPLOAD_POST,
1921
} from "../actions/types";
20-
import axios from "axios";
2122
import { loadUser } from "./authAction";
2223

2324
export const getPost = (post_id) => async (dispatch) => {
2425
try {
2526
if (post_id !== undefined) {
26-
const url = `/api/post/${post_id}`;
27+
const url = `${API}/api/post/${post_id}`;
2728
dispatch({ type: SET_LOADING_POST_TRUE });
2829
const res = await axios.get(url);
2930
dispatch({ type: GET_POST, payload: res.data }); // * this will fetch a single post given the post id
3031
}
31-
} catch (err) {
32-
}
32+
} catch (err) {}
3333
};
3434

3535
export const setCurrentPost = (post_id) => (dispatch) => {
@@ -49,95 +49,86 @@ export const uploadPost = (post, post_id) => async (dispatch) => {
4949
try {
5050
if (post_id !== undefined) {
5151
const res = await axios.post(
52-
`/api/post/content/${post_id}`,
52+
`${API}/api/post/content/${post_id}`,
5353
post,
5454
config
5555
);
5656
dispatch({ type: UPLOAD_POST, payload: res.data });
5757
dispatch(loadUser());
5858
}
59-
} catch (err) {
60-
}
59+
} catch (err) {}
6160
};
6261

6362
// ? Extension of above
6463
export const uploadImage = (fData) => async (dispatch) => {
6564
try {
6665
dispatch({ type: RESET_IMAGE_UPLOAD });
67-
const res = await axios.post("/api/upload", fData);
66+
const res = await axios.post(`${API}/api/upload`, fData);
6867
dispatch({ type: GET_POST_ID, payload: res.data._id });
69-
} catch (err) {
70-
}
68+
} catch (err) {}
7169
};
7270

7371
export const getUserPosts = (user_id) => async (dispatch) => {
7472
try {
7573
if (user_id !== undefined) {
76-
const res = await axios.get(`/api/post/all/${user_id}`);
74+
const res = await axios.get(`${API}/api/post/all/${user_id}`);
7775
dispatch({ type: GET_USER_POSTS, payload: res.data });
7876
}
79-
} catch (err) {
80-
}
77+
} catch (err) {}
8178
};
8279

8380
export const deletePost = (post_id) => async (dispatch) => {
8481
try {
8582
if (post_id !== undefined) {
86-
const res = await axios.delete(`/api/post/${post_id}`);
83+
const res = await axios.delete(`${API}/api/post/${post_id}`);
8784
dispatch({ type: DELETE_POST, payload: res.data });
8885
}
89-
} catch (err) {
90-
}
86+
} catch (err) {}
9187
};
9288

9389
export const savePost = (post_id) => async (dispatch) => {
9490
try {
9591
if (post_id !== undefined) {
96-
const res = await axios.post(`/api/save/${post_id}`);
92+
const res = await axios.post(`${API}/api/save/${post_id}`);
9793
dispatch({ type: TOGGLE_SAVE_POST, payload: res.data });
9894
dispatch({ type: SAVE_POST_TOAST, payload: true });
9995
setTimeout(() => {
10096
dispatch({ type: SAVE_POST_TOAST, payload: false });
10197
}, 5000);
10298
}
103-
} catch (err) {
104-
}
99+
} catch (err) {}
105100
};
106101

107102
export const getSavedPosts = () => async (dispatch) => {
108103
try {
109-
const res = await axios.get("/api/save");
104+
const res = await axios.get(`${API}/api/save`);
110105
dispatch({ type: GET_SAVED_POST, payload: res.data });
111-
} catch (err) {
112-
}
106+
} catch (err) {}
113107
};
114108

115109
export const likePost = (post_id) => async (dispatch) => {
116110
try {
117111
if (post_id !== undefined) {
118-
const res = await axios.put(`/api/post/like/${post_id}`);
112+
const res = await axios.put(`${API}/api/post/like/${post_id}`);
119113
dispatch({ type: LIKE_POST, payload: res.data });
120114
}
121-
} catch (err) {
122-
}
115+
} catch (err) {}
123116
};
124117

125118
export const getLikedPosts = (user, post_id) => async (dispatch) => {
126119
try {
127120
if (user !== undefined && post_id !== undefined) {
128-
const res = await axios.get(`/api/post/${user}/${post_id}`);
121+
const res = await axios.get(`${API}/api/post/${user}/${post_id}`);
129122
dispatch({ type: GET_LIKED_POST, payload: res.data });
130123
}
131-
} catch (err) {
132-
}
124+
} catch (err) {}
133125
};
134126

135127
export const reallyGetAllPosts = (userId) => async (dispatch) => {
136128
try {
137-
const res = await axios.get(`/api/post/real-all/${userId}`);
129+
const res = await axios.get(`${API}/api/post/real-all/${userId}`);
138130
dispatch({ type: REALLY_GET_ALL_POSTS, payload: res.data });
139-
} catch (error) {
140-
}
131+
} catch (error) {}
141132
};
142133

143134
export const clearPostID = () => (dispatch) => {
@@ -150,8 +141,7 @@ export const cleanGetPostAction = () => (dispatch) => {
150141

151142
export const fetchPopularPosts = () => async (dispatch) => {
152143
try {
153-
const res = await axios.get("/api/post/5fc4c6a6cf07d202383aadcf");
144+
await axios.get(`${API}/api/post/5fc4c6a6cf07d202383aadcf`);
154145
// dispatch({ type: , payload: res.data });
155-
} catch (err) {
156-
}
146+
} catch (err) {}
157147
};

0 commit comments

Comments
 (0)