From 16ca7f444c29b1379e49770ef76e20d7eaf9a821 Mon Sep 17 00:00:00 2001 From: xmcp Date: Fri, 24 Aug 2018 22:24:23 +0800 Subject: [PATCH] add toggle attention --- src/Flows.css | 3 --- src/Flows.js | 49 ++++++++++++++++++++++++++++++++++++++++++++--- src/UserAction.js | 3 +++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/Flows.css b/src/Flows.css index a5d2628..5c59a70 100644 --- a/src/Flows.css +++ b/src/Flows.css @@ -93,9 +93,6 @@ cursor: default; transition: margin-left 200ms ease-out; } -.left-container .flow-item-row:hover { - margin-left: -10px; -} .flow-item-row p.img { text-align: center; diff --git a/src/Flows.js b/src/Flows.js index 783609c..b023a20 100644 --- a/src/Flows.js +++ b/src/Flows.js @@ -116,6 +116,35 @@ class FlowItemRow extends PureComponent { }); } + toggle_attention(callback) { + let data=new URLSearchParams(); + const next_attention=!this.state.attention; + data.append('token', this.props.token); + data.append('pid', this.state.info.pid); + data.append('switch', next_attention ? '1' : '0'); + fetch(API_BASE+'/api.php?action=attention', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: data, + }) + .then((res)=>res.json()) + .then((json)=>{ + if(json.code!==0 && (!json.msg || json.msg!=='已经关注过辣')) + throw new Error(json); + + this.setState({ + attention: next_attention, + }, callback); + }) + .catch((e)=>{ + alert('设置关注失败'); + console.trace(e); + callback(); + }); + } + show_sidebar() { this.props.show_sidebar( '帖子详情', @@ -123,13 +152,27 @@ class FlowItemRow extends PureComponent {
{ this.props.show_sidebar('帖子详情',

加载中……

); - this.load_replies(this.show_sidebar); + this.load_replies(this.show_sidebar.bind(this)); }}>刷新回复
+ {this.props.token && + +  /  + { + this.props.show_sidebar('帖子详情',

加载中……

); + this.toggle_attention(this.show_sidebar.bind(this)); + }}> + {this.state.attention ? + 已关注 : + 未关注 + } +
+
+ }
{this.state.replies.map((reply)=>( - - + + ))} diff --git a/src/UserAction.js b/src/UserAction.js index 702e11a..1306113 100644 --- a/src/UserAction.js +++ b/src/UserAction.js @@ -30,6 +30,9 @@ export class LoginForm extends Component { data.append('password', this.password_ref.current.value); fetch(LOGIN_BASE+'/login.php?platform=hole_xmcp_ml', { method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, body: data, }) .then((res)=>res.json())