diff --git a/src/Common.js b/src/Common.js index 303455c..fe03856 100644 --- a/src/Common.js +++ b/src/Common.js @@ -119,4 +119,41 @@ export function PromotionBar(props) { 用 Safari 将本网站 添加到主屏幕 更好用 ) : null; +} + +export class ClickHandler extends PureComponent { + constructor(props) { + super(props); + this.state={ + moved: false, + }; + this.on_begin_bound=this.on_begin.bind(this); + this.on_move_bound=this.on_move.bind(this); + this.on_end_bound=this.on_end.bind(this); + } + + on_begin() { + this.setState({ + moved: false, + }); + } + on_move() { + this.setState({ + moved: true, + }); + } + on_end(event) { + if(!this.state.moved) + this.props.callback(event); + } + + render() { + return ( +
+ {this.props.children} +
+ ) + } } \ No newline at end of file diff --git a/src/Flows.js b/src/Flows.js index 959d519..a082e2e 100644 --- a/src/Flows.js +++ b/src/Flows.js @@ -1,7 +1,7 @@ import React, {Component, PureComponent} from 'react'; import copy from 'copy-to-clipboard'; import {ColorPicker} from './color_picker'; -import {format_time, Time, TitleLine, HighlightedText} from './Common'; +import {format_time, Time, TitleLine, HighlightedText, ClickHandler} from './Common'; import './Flows.css'; import LazyLoad from 'react-lazyload'; import {AudioWidget} from './AudioWidget'; @@ -254,7 +254,7 @@ class FlowSidebar extends PureComponent { } show_reply_bar(name,event) { - if(event.target.tagName.toLowerCase()!=='a') { + if(this.reply_ref.current && event.target.tagName.toLowerCase()!=='a') { let text=this.reply_ref.current.get(); if(/^\s*(Re (洞主|\b[A-Z][a-z]+){0,2}:)?\s*$/.test(text)) // text is nearly empty so we can replace it this.reply_ref.current.set('Re '+name+': '); @@ -296,12 +296,12 @@ class FlowSidebar extends PureComponent { } -
{this.show_reply_bar('',e);}}> + {this.show_reply_bar('',e);}}> {this.set_variant(null,variant);}} /> -
+ {(this.props.deletion_detect && parseInt(this.state.info.reply)>this.state.replies.length) &&
{parseInt(this.state.info.reply)-this.state.replies.length} 条回复被删除 @@ -309,12 +309,12 @@ class FlowSidebar extends PureComponent { } {this.state.replies.map((reply)=>( -
{this.show_reply_bar(reply.name,e);}}> + {this.show_reply_bar(reply.name,e);}}> {this.set_variant(reply.cid,variant);}} /> -
+
))} {!!this.props.token ? @@ -322,6 +322,7 @@ class FlowSidebar extends PureComponent { area_ref={this.reply_ref} on_complete={this.load_replies.bind(this)} /> :
登录后可以回复树洞
} +
) }