forked from newthuhole/hole_thu_frontend
add click to reply
This commit is contained in:
@@ -72,6 +72,7 @@ export class SafeTextarea extends Component {
|
|||||||
this.clear=this.clear.bind(this);
|
this.clear=this.clear.bind(this);
|
||||||
this.area_ref=React.createRef();
|
this.area_ref=React.createRef();
|
||||||
this.change_callback=props.on_change;
|
this.change_callback=props.on_change;
|
||||||
|
this.change_callback(this.state.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@@ -91,6 +92,17 @@ export class SafeTextarea extends Component {
|
|||||||
text: '',
|
text: '',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
set_and_focus(text) {
|
||||||
|
this.change_callback(text);
|
||||||
|
this.setState({
|
||||||
|
text: text,
|
||||||
|
},()=>{
|
||||||
|
this.area_ref.current.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
get() {
|
||||||
|
return this.state.text;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
17
src/Flows.js
17
src/Flows.js
@@ -143,6 +143,7 @@ class FlowSidebar extends PureComponent {
|
|||||||
this.color_picker=props.color_picker;
|
this.color_picker=props.color_picker;
|
||||||
this.show_pid=load_single_meta(this.props.show_sidebar,this.props.token);
|
this.show_pid=load_single_meta(this.props.show_sidebar,this.props.token);
|
||||||
this.syncState=props.sync_state||(()=>{});
|
this.syncState=props.sync_state||(()=>{});
|
||||||
|
this.reply_ref=React.createRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
set_variant(cid,variant) {
|
set_variant(cid,variant) {
|
||||||
@@ -252,6 +253,13 @@ class FlowSidebar extends PureComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do_reply(name,event) {
|
||||||
|
if(event.target.tagName.toLowerCase()!=='a') {
|
||||||
|
let text=this.reply_ref.current.get();
|
||||||
|
this.reply_ref.current.set_and_focus('Re '+name+': ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const star_brush=localStorage['STAR_BRUSH']==='on';
|
const star_brush=localStorage['STAR_BRUSH']==='on';
|
||||||
|
|
||||||
@@ -287,25 +295,30 @@ class FlowSidebar extends PureComponent {
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
<div onClick={(e)=>{this.do_reply('',e);}}>
|
||||||
<FlowItem info={this.state.info} attention={this.state.attention} img_clickable={true}
|
<FlowItem info={this.state.info} attention={this.state.attention} img_clickable={true}
|
||||||
color_picker={this.color_picker} show_pid={this.show_pid} replies={this.state.replies}
|
color_picker={this.color_picker} show_pid={this.show_pid} replies={this.state.replies}
|
||||||
set_variant={(variant)=>{this.set_variant(null,variant);}}
|
set_variant={(variant)=>{this.set_variant(null,variant);}}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
{(this.props.deletion_detect && parseInt(this.state.info.reply)>this.state.replies.length) &&
|
{(this.props.deletion_detect && parseInt(this.state.info.reply)>this.state.replies.length) &&
|
||||||
<div className="box box-tip flow-item box-danger">
|
<div className="box box-tip flow-item box-danger">
|
||||||
{parseInt(this.state.info.reply)-this.state.replies.length} 条回复被删除
|
{parseInt(this.state.info.reply)-this.state.replies.length} 条回复被删除
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
{this.state.replies.map((reply)=>(
|
{this.state.replies.map((reply)=>(
|
||||||
<LazyLoad key={reply.cid} offset={500} height="5em" overflow={true} once={true}>
|
<LazyLoad key={reply.cid} offset={1500} height="5em" overflow={true} once={true}>
|
||||||
|
<div onClick={(e)=>{this.do_reply(reply.name,e);}}>
|
||||||
<Reply
|
<Reply
|
||||||
info={reply} color_picker={this.color_picker} show_pid={this.show_pid}
|
info={reply} color_picker={this.color_picker} show_pid={this.show_pid}
|
||||||
set_variant={(variant)=>{this.set_variant(reply.cid,variant);}}
|
set_variant={(variant)=>{this.set_variant(reply.cid,variant);}}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
</LazyLoad>
|
</LazyLoad>
|
||||||
))}
|
))}
|
||||||
{!!this.props.token ?
|
{!!this.props.token ?
|
||||||
<ReplyForm pid={this.state.info.pid} token={this.props.token} on_complete={this.load_replies.bind(this)} /> :
|
<ReplyForm pid={this.state.info.pid} token={this.props.token}
|
||||||
|
area_ref={this.reply_ref} on_complete={this.load_replies.bind(this)} /> :
|
||||||
<div className="box box-tip flow-item">登录后可以回复树洞</div>
|
<div className="box box-tip flow-item">登录后可以回复树洞</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,6 +8,11 @@
|
|||||||
.reply-form {
|
.reply-form {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
.reply-sticky {
|
||||||
|
position: sticky;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.reply-form textarea {
|
.reply-form textarea {
|
||||||
resize: vertical;
|
resize: vertical;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ export class ReplyForm extends Component {
|
|||||||
loading_status: 'done',
|
loading_status: 'done',
|
||||||
};
|
};
|
||||||
this.on_change_bound=this.on_change.bind(this);
|
this.on_change_bound=this.on_change.bind(this);
|
||||||
this.area_ref=React.createRef();
|
this.area_ref=this.props.area_ref||React.createRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
on_change(value) {
|
on_change(value) {
|
||||||
@@ -234,7 +234,7 @@ export class ReplyForm extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<form onSubmit={this.on_submit.bind(this)} className="reply-form box">
|
<form onSubmit={this.on_submit.bind(this)} className={'reply-form box'+(this.state.text?' reply-sticky':'')}>
|
||||||
<SafeTextarea ref={this.area_ref} id={this.props.pid} on_change={this.on_change_bound} />
|
<SafeTextarea ref={this.area_ref} id={this.props.pid} on_change={this.on_change_bound} />
|
||||||
{this.state.loading_status==='loading' ?
|
{this.state.loading_status==='loading' ?
|
||||||
<button disabled="disabled">
|
<button disabled="disabled">
|
||||||
|
|||||||
Reference in New Issue
Block a user