Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
7192422b39
@ -1,87 +1,87 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom";
|
import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom";
|
||||||
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
class UserSection extends Component {
|
class UserSection extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*点击关注或者取消关注*/
|
/*点击关注或者取消关注*/
|
||||||
AboutFocus(){
|
AboutFocus(){
|
||||||
const { author_info } = this.props
|
const { author_info } = this.props
|
||||||
/*http://localhost:3000/api/v1/users/155/watch?object_id=156&object_type=user*/
|
/*http://localhost:3000/api/v1/users/155/watch?object_id=156&object_type=user*/
|
||||||
|
|
||||||
// const focusUrl = `/api/v1/users/${author_info.user_id}/${this.props.author_info.watched ? 'unwatch' : 'watch'}?object_id=${author_info.user_id}&object_type=user`
|
// const focusUrl = `/api/v1/users/${author_info.user_id}/${this.props.author_info.watched ? 'unwatch' : 'watch'}?object_id=${author_info.user_id}&object_type=user`
|
||||||
|
|
||||||
// axios.get(focusUrl,{
|
// axios.get(focusUrl,{
|
||||||
// })
|
// })
|
||||||
// .then((response) => {
|
// .then((response) => {
|
||||||
// const status = response.data.status;
|
// const status = response.data.status;
|
||||||
// console.log(status);
|
// console.log(status);
|
||||||
// if(status == 1){
|
// if(status == 1){
|
||||||
// const new_author_info = Object.assign({}, this.props.author_info)
|
// const new_author_info = Object.assign({}, this.props.author_info)
|
||||||
// new_author_info.watched = !new_author_info.watched
|
// new_author_info.watched = !new_author_info.watched
|
||||||
// this.props.initForumState({author_info: new_author_info})
|
// this.props.initForumState({author_info: new_author_info})
|
||||||
// }
|
// }
|
||||||
// }).catch((error) => {
|
// }).catch((error) => {
|
||||||
// console.log(error)
|
// console.log(error)
|
||||||
// })
|
// })
|
||||||
|
|
||||||
let url=`/users/${author_info.user_id}/watch.json`;
|
let url=`/users/${author_info.user_id}/watch.json`;
|
||||||
// 取消关注
|
// 取消关注
|
||||||
if(author_info.watched){
|
if(author_info.watched){
|
||||||
axios.delete(url).then((result)=>{
|
axios.delete(url).then((result)=>{
|
||||||
if(result){
|
if(result){
|
||||||
const new_author_info = Object.assign({}, this.props.author_info)
|
const new_author_info = Object.assign({}, this.props.author_info)
|
||||||
new_author_info.watched = !new_author_info.watched
|
new_author_info.watched = !new_author_info.watched
|
||||||
this.props.initForumState({author_info: new_author_info})
|
this.props.initForumState({author_info: new_author_info})
|
||||||
}
|
}
|
||||||
}).catch((error)=>{
|
}).catch((error)=>{
|
||||||
console.log(error)
|
console.log(error)
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
// 关注
|
// 关注
|
||||||
axios.post(url).then((result)=>{
|
axios.post(url).then((result)=>{
|
||||||
if(result){
|
if(result){
|
||||||
const new_author_info = Object.assign({}, this.props.author_info)
|
const new_author_info = Object.assign({}, this.props.author_info)
|
||||||
new_author_info.watched = !new_author_info.watched
|
new_author_info.watched = !new_author_info.watched
|
||||||
this.props.initForumState({author_info: new_author_info})
|
this.props.initForumState({author_info: new_author_info})
|
||||||
}
|
}
|
||||||
}).catch((error)=>{
|
}).catch((error)=>{
|
||||||
console.log(error);
|
console.log(error);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { match, history, author_info , current_user } = this.props
|
const { match, history, author_info , current_user } = this.props
|
||||||
if (!author_info || !current_user) {
|
if (!author_info || !current_user) {
|
||||||
return <div className="edu-back-white" id="forum_index_list"></div>
|
return <div className="edu-back-white" id="forum_index_list"></div>
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="edu-back-white padding40-20 edu-txt-center">
|
<div className="edu-back-white padding40-20 edu-txt-center">
|
||||||
<a href={`/users/${author_info.login}`} target="_blank"><img src={`/images/${author_info.image_url}`} width="90" height="90" className="radius mb5"/></a>
|
<a href={`/users/${author_info.login}`} target="_blank"><img src={`/images/${author_info.image_url}`} width="90" height="90" className="radius mb5"/></a>
|
||||||
<p className="font-20 userPrivateName">{author_info.username}</p>
|
<p className="font-20 userPrivateName">{author_info.username}</p>
|
||||||
<p className="color-grey-9 userPrivatePost">{author_info.identity}</p>
|
<p className="color-grey-9 userPrivatePost">{author_info.identity}</p>
|
||||||
{ author_info.user_id !== current_user.user_id &&
|
{ author_info.user_id !== current_user.user_id &&
|
||||||
<p className="clearfix mt30">
|
<p className="clearfix mt30">
|
||||||
<a href="javascript:void(0)" className="fl font-16 mr10 user_default_btn edu-blueback-btn" onClick={()=>{this.AboutFocus()}}>{ author_info.watched == true ? "取消关注" : "关注" }</a>
|
<a href="javascript:void(0)" className="fl font-16 mr10 user_default_btn edu-blueback-btn" onClick={()=>{this.AboutFocus()}}>{ author_info.watched == true ? "取消关注" : "关注" }</a>
|
||||||
<a href={`/users/${current_user.login}/message_detail?user_id=${author_info.user_id}`} className="fr font-16 user_default_btn user_private_btn" target="_blank">私信</a>
|
<a href={`/messages/${current_user.login}/message_detail?target_ids=${author_info.user_id}`} className="fr font-16 user_default_btn user_private_btn" target="_blank">私信</a>
|
||||||
</p> }
|
</p> }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default UserSection;
|
export default UserSection;
|
||||||
|
Loading…
Reference in new issue