refactor
This commit is contained in:
14
src/App.js
14
src/App.js
@@ -9,11 +9,12 @@ class App extends Component {
|
|||||||
this.state={
|
this.state={
|
||||||
sidebar_title: null,
|
sidebar_title: null,
|
||||||
sidebar_content: null,
|
sidebar_content: null,
|
||||||
|
mode: 'list', // list, single, search
|
||||||
search_text: null,
|
search_text: null,
|
||||||
flow_render_key: +new Date(),
|
flow_render_key: +new Date(),
|
||||||
};
|
};
|
||||||
this.show_sidebar_bound=this.show_sidebar.bind(this);
|
this.show_sidebar_bound=this.show_sidebar.bind(this);
|
||||||
this.set_search_text_bound=this.set_search_text.bind(this);
|
this.set_mode_bound=this.set_mode.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
show_sidebar(title,content) {
|
show_sidebar(title,content) {
|
||||||
@@ -23,9 +24,10 @@ class App extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
set_search_text(text) {
|
set_mode(mode,search_text) {
|
||||||
this.setState({
|
this.setState({
|
||||||
search_text: text,
|
mode: mode,
|
||||||
|
search_text: search_text,
|
||||||
flow_render_key: +new Date(),
|
flow_render_key: +new Date(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -36,10 +38,10 @@ class App extends Component {
|
|||||||
<div className="bg-img" style={{
|
<div className="bg-img" style={{
|
||||||
backgroundImage: 'url('+(localStorage['REPLACE_ERIRI_WITH_URL'] || 'static/eriri_bg.jpg')+')'
|
backgroundImage: 'url('+(localStorage['REPLACE_ERIRI_WITH_URL'] || 'static/eriri_bg.jpg')+')'
|
||||||
}} />
|
}} />
|
||||||
<Title callback={this.show_sidebar_bound} set_search_text={this.set_search_text_bound} />
|
<Title show_sidebar={this.show_sidebar_bound} set_mode={this.set_mode_bound} />
|
||||||
<div className="left-container">
|
<div className="left-container">
|
||||||
<Flow key={this.state.flow_render_key}
|
<Flow key={this.state.flow_render_key} show_sidebar={this.show_sidebar_bound}
|
||||||
callback={this.show_sidebar_bound} search_text={this.state.search_text}
|
mode={this.state.mode} search_text={this.state.search_text}
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -38,14 +38,14 @@ export function TitleLine(props) {
|
|||||||
|
|
||||||
export class HighlightedText extends PureComponent {
|
export class HighlightedText extends PureComponent {
|
||||||
render() {
|
render() {
|
||||||
let parts=[].concat.apply([], props.text.split(PID_RE).map((p)=>p.split(NICKNAME_RE)));
|
let parts=[].concat.apply([], this.props.text.split(PID_RE).map((p)=>p.split(NICKNAME_RE)));
|
||||||
return (
|
return (
|
||||||
<Linkify properties={{target: '_blank'}}>
|
<Linkify properties={{target: '_blank'}}>
|
||||||
<pre>
|
<pre>
|
||||||
{parts.map((p,idx)=>(
|
{parts.map((p,idx)=>(
|
||||||
<span key={idx}>{
|
<span key={idx}>{
|
||||||
PID_RE.test(p) ? <a href={'##'+p} target="_blank">{p}</a> :
|
PID_RE.test(p) ? <a href={'##'+p} target="_blank">{p}</a> :
|
||||||
NICKNAME_RE.test(p) ? <span style={{backgroundColor: props.color_picker.get(p)}}>{p}</span> :
|
NICKNAME_RE.test(p) ? <span style={{backgroundColor: this.props.color_picker.get(p)}}>{p}</span> :
|
||||||
p
|
p
|
||||||
}</span>
|
}</span>
|
||||||
))}
|
))}
|
||||||
|
|||||||
14
src/Flows.js
14
src/Flows.js
@@ -99,12 +99,12 @@ class FlowItemRow extends PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
show_sidebar() {
|
show_sidebar() {
|
||||||
this.props.callback(
|
this.props.show_sidebar(
|
||||||
'帖子详情',
|
'帖子详情',
|
||||||
<div className="flow-item-row sidebar-flow-item">
|
<div className="flow-item-row sidebar-flow-item">
|
||||||
<div className="box box-tip">
|
<div className="box box-tip">
|
||||||
<a onClick={()=>{
|
<a onClick={()=>{
|
||||||
this.props.callback('帖子详情',<p className="box box-tip">加载中……</p>);
|
this.props.show_sidebar('帖子详情',<p className="box box-tip">加载中……</p>);
|
||||||
this.load_replies(this.show_sidebar);
|
this.load_replies(this.show_sidebar);
|
||||||
}}>更新回复</a>
|
}}>更新回复</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -149,7 +149,7 @@ function FlowChunk(props) {
|
|||||||
<TitleLine text={props.title} />
|
<TitleLine text={props.title} />
|
||||||
{props.list.map((info)=>(
|
{props.list.map((info)=>(
|
||||||
<LazyLoad key={info.pid} offset={500} height="15em" once={true} >
|
<LazyLoad key={info.pid} offset={500} height="15em" once={true} >
|
||||||
<FlowItemRow info={info} callback={props.callback} />
|
<FlowItemRow info={info} show_sidebar={props.show_sidebar} />
|
||||||
</LazyLoad>
|
</LazyLoad>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -160,11 +160,7 @@ export class Flow extends PureComponent {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state={
|
this.state={
|
||||||
mode: (
|
mode: props.mode,
|
||||||
props.search_text===null ? 'list' :
|
|
||||||
props.search_text.charAt(0)==='#' ? 'single' :
|
|
||||||
'search'
|
|
||||||
),
|
|
||||||
search_param: props.search_text,
|
search_param: props.search_text,
|
||||||
loaded_pages: 0,
|
loaded_pages: 0,
|
||||||
chunks: [],
|
chunks: [],
|
||||||
@@ -294,7 +290,7 @@ export class Flow extends PureComponent {
|
|||||||
return (
|
return (
|
||||||
<div className="flow-container">
|
<div className="flow-container">
|
||||||
{this.state.chunks.map((chunk)=>(
|
{this.state.chunks.map((chunk)=>(
|
||||||
<FlowChunk title={chunk.title} list={chunk.data} key={chunk.title} callback={this.props.callback} />
|
<FlowChunk title={chunk.title} list={chunk.data} key={chunk.title} show_sidebar={this.props.show_sidebar} />
|
||||||
))}
|
))}
|
||||||
{this.state.loading_status==='failed' &&
|
{this.state.loading_status==='failed' &&
|
||||||
<div className="box box-tip">
|
<div className="box box-tip">
|
||||||
|
|||||||
21
src/Title.js
21
src/Title.js
@@ -45,7 +45,11 @@ class ControlBar extends PureComponent {
|
|||||||
this.state={
|
this.state={
|
||||||
search_text: '',
|
search_text: '',
|
||||||
};
|
};
|
||||||
this.set_search_text=props.set_search_text;
|
this.set_mode=props.set_mode;
|
||||||
|
|
||||||
|
this.on_change_bound=this.on_change.bind(this);
|
||||||
|
this.on_keypress_bound=this.on_keypress.bind(this);
|
||||||
|
this.do_refresh_bound=this.do_refresh.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@@ -54,7 +58,7 @@ class ControlBar extends PureComponent {
|
|||||||
this.setState({
|
this.setState({
|
||||||
search_text: text,
|
search_text: text,
|
||||||
});
|
});
|
||||||
this.set_search_text(text);
|
this.set_mode(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +70,7 @@ class ControlBar extends PureComponent {
|
|||||||
|
|
||||||
on_keypress(event) {
|
on_keypress(event) {
|
||||||
if(event.key==='Enter')
|
if(event.key==='Enter')
|
||||||
this.set_search_text(this.state.search_text||null);
|
this.set_mode('search',this.state.search_text||null);
|
||||||
}
|
}
|
||||||
|
|
||||||
do_refresh() {
|
do_refresh() {
|
||||||
@@ -74,20 +78,19 @@ class ControlBar extends PureComponent {
|
|||||||
this.setState({
|
this.setState({
|
||||||
search_text: '',
|
search_text: '',
|
||||||
});
|
});
|
||||||
this.set_search_text(null);
|
this.set_mode('list',null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="control-bar">
|
<div className="control-bar">
|
||||||
<a className="refresh-btn" onClick={this.do_refresh.bind(this)}>最新树洞</a>
|
<a className="refresh-btn" onClick={this.do_refresh_bound}>最新树洞</a>
|
||||||
|
|
||||||
<input value={this.state.search_text} placeholder="搜索 或 #PID"
|
<input value={this.state.search_text} placeholder="搜索 或 #PID"
|
||||||
onChange={this.on_change.bind(this)} onKeyPress={this.on_keypress.bind(this)}
|
onChange={this.on_change_bound} onKeyPress={this.on_keypress_bound}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<a onClick={()=>{this.props.callback(
|
<a onClick={()=>{this.props.show_sidebar(
|
||||||
'关于 P大树洞(非官方) 网页版',
|
'关于 P大树洞(非官方) 网页版',
|
||||||
HELP_TEXT
|
HELP_TEXT
|
||||||
)}}>Help</a>
|
)}}>Help</a>
|
||||||
@@ -101,7 +104,7 @@ export function Title(props) {
|
|||||||
<div className="title-bar">
|
<div className="title-bar">
|
||||||
<div className="aux-margin">
|
<div className="aux-margin">
|
||||||
<p className="title centered-line">P大树洞</p>
|
<p className="title centered-line">P大树洞</p>
|
||||||
<ControlBar callback={props.callback} set_search_text={props.set_search_text} />
|
<ControlBar show_sidebar={props.show_sidebar} set_mode={props.set_mode} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user