Skip to content

Commit

Permalink
getUserProfile 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
shing100 committed Oct 22, 2018
1 parent 88d12e7 commit a7ea0eb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
7 changes: 4 additions & 3 deletions frontend/src/components/Profile/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { connect } from "react-redux";
import { actionCreators as photoActions } from "redux/modules/photos";
import { actionCreators as userActions } from "redux/modules/users";
import Container from "./container";

const mapStateToProps = (state, ownProps) => {
Expand All @@ -10,9 +10,10 @@ const mapStateToProps = (state, ownProps) => {
}

const mapDispatchToProps = (dispatch, ownProps) => {
const username = localStorage.getItem('username')
return {
getFeed: () => {
dispatch(photoActions.getFeed())
getUserProfile: () => {
dispatch(userActions.getUserProfile(username))
}
}
}
Expand Down
30 changes: 29 additions & 1 deletion frontend/src/redux/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const FOLLOW_USER = "FOLLOW_USER";
const UNFOLLOW_USER = "UNFOLLOW_USER";
const SET_IMAGE_LIST = "SET_IMAGE_LIST";
const SET_NOTIFICATION_LIST = "SET_NOTIFICATION_LIST";
const SET_USER_PROFILE = "SET_USER_PROFILE";

// action creators

Expand Down Expand Up @@ -68,6 +69,13 @@ const setNotificationList = (notificationList) => {
}
}

const setUserProfile = (username) => {
return {
type: SET_USER_PROFILE,
username
}
}

// API actions

const facebookLogin = (access_token) => {
Expand Down Expand Up @@ -288,6 +296,25 @@ const searchImages = (token, searchTerm) => {
.then(json => json)
}

const getUserProfile = (token, username) => {
return (dispatch, getState) => {
const { user: { token } } = getState();
fetch(`/users/${username}/`, {
method: "GET",
headers: {
Authorization: `JWT ${token}`,
}
})
.then(response => {
if(response.status === 401) {
return 401;
}
return response.json()
})
.then(json => json)
}
}

// intiial state

const initialState = {
Expand Down Expand Up @@ -410,7 +437,8 @@ const actionCreators = {
unfollowUser,
getExplore,
searchByTerm,
getNotification
getNotification,
getUserProfile
}

export { actionCreators };
Expand Down

0 comments on commit a7ea0eb

Please sign in to comment.