Next Level:
{this.props.levels[completedLevels] &&
@@ -100,7 +101,7 @@ const mapState = (state) => ({
const mapDispatch = (dispatch) => ({
getUser: (id) => dispatch(fetchUser(id)),
getLevels: () => dispatch(fetchLevels()),
- getFriends: (id) => dispatch(fetchFriends(id))
+ getFriends: (user) => dispatch(fetchFriends(user))
});
export default connect(mapState, mapDispatch)(Profile);
diff --git a/client/store/level.js b/client/store/level.js
index be61ebf..8d4e6bc 100644
--- a/client/store/level.js
+++ b/client/store/level.js
@@ -50,7 +50,6 @@ export const nextLevel = (id) => async (dispatch) => {
});
dispatch(setLevel(data));
return data;
- //changeCode(data.startingJS);
} catch (levelError) {
console.log('These are not the ducks you are looking for', levelError);
}
diff --git a/client/store/user.js b/client/store/user.js
index 8fa4746..e1b9c5f 100644
--- a/client/store/user.js
+++ b/client/store/user.js
@@ -52,12 +52,15 @@ export const verifyUser = (id, enteredPass) => async () =>{
}
}
-export const fetchFriends = (id) => async (dispatch) => {
+export const fetchFriends = (user) => async (dispatch) => {
try {
- const token = window.localStorage.getItem('token');
- const { data } = await axios.get(`/api/users/${id}/friends`, { headers: { authorization: token } });
- console.log('friends:', data)
- dispatch(setFriends(data));
+ const token = window.localStorage.getItem('token');
+ // const user = await axios.get(`/api/users/${id}`, { headers: { authorization: token } });
+ const budArray = await axios.get(`/api/users/${user.id}/friends`, { headers: { authorization: token } });
+ console.log('user: ', user)
+ // user.data.friends = budArray.data;
+ console.log('friends: ', budArray.data)
+ dispatch(setFriends(budArray.data));
} catch (e) {
console.log(e)
}
@@ -70,7 +73,7 @@ export default function( state = {}, action ) {
case SET_USER:
return action.user;
case SET_FRIENDS:
- return action.friends
+ return {...user, friends: action.friends }
default:
return state
}
diff --git a/server/api/users.js b/server/api/users.js
index b794aef..f60d4b5 100644
--- a/server/api/users.js
+++ b/server/api/users.js
@@ -53,7 +53,7 @@ router.put('/update/:id', requireToken, userIsUser, async (req, res, next) => {
router.get('/:id/friends', requireToken, async(req, res, next) => {
try {
- // doesn't work
+ // doesn't work OR DOES IT???
const friends = await req.user.getFriends()
res.json(friends)
} catch (err) {