|
|
@ -1,9 +1,11 @@ |
|
|
|
import React, {Component} from 'react'; |
|
|
|
import React, {Component} from 'react'; |
|
|
|
import {Time, CenteredLine} from './Common.js'; |
|
|
|
import {Time, CenteredLine} from './Common.js'; |
|
|
|
import './Flows.css'; |
|
|
|
import './Flows.css'; |
|
|
|
|
|
|
|
import LazyLoad from 'react-lazyload'; |
|
|
|
|
|
|
|
|
|
|
|
const IMAGE_BASE='http://www.pkuhelper.com/services/pkuhole/images/'; |
|
|
|
const IMAGE_BASE='http://www.pkuhelper.com/services/pkuhole/images/'; |
|
|
|
const AUDIO_BASE='http://www.pkuhelper.com/services/pkuhole/audios/'; |
|
|
|
const AUDIO_BASE='http://www.pkuhelper.com/services/pkuhole/audios/'; |
|
|
|
|
|
|
|
const SEARCH_PAGESIZE=50; |
|
|
|
|
|
|
|
|
|
|
|
function Reply(props) { |
|
|
|
function Reply(props) { |
|
|
|
return ( |
|
|
|
return ( |
|
|
@ -20,7 +22,7 @@ function Reply(props) { |
|
|
|
function ReplyPlaceholder(props) { |
|
|
|
function ReplyPlaceholder(props) { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="box"> |
|
|
|
<div className="box"> |
|
|
|
正在加载 {props.count} 条回复 |
|
|
|
加载中 |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
@ -29,8 +31,8 @@ function FlowItem(props) { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="flow-item box"> |
|
|
|
<div className="flow-item box"> |
|
|
|
<div className="box-header"> |
|
|
|
<div className="box-header"> |
|
|
|
{parseInt(props.info.likenum, 10) && <span className="box-header-badge">{props.info.likenum}★</span>} |
|
|
|
{!!parseInt(props.info.likenum, 10) && <span className="box-header-badge">{props.info.likenum}★</span>} |
|
|
|
{parseInt(props.info.reply, 10) && <span className="box-header-badge">{props.info.reply} 回复</span>} |
|
|
|
{!!parseInt(props.info.reply, 10) && <span className="box-header-badge">{props.info.reply} 回复</span>} |
|
|
|
<span className="box-id">#{props.info.pid}</span> |
|
|
|
<span className="box-id">#{props.info.pid}</span> |
|
|
|
<Time stamp={props.info.timestamp} /> |
|
|
|
<Time stamp={props.info.timestamp} /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -49,15 +51,20 @@ class FlowItemRow extends Component { |
|
|
|
reply_loading: false, |
|
|
|
reply_loading: false, |
|
|
|
}; |
|
|
|
}; |
|
|
|
this.info=props.info; |
|
|
|
this.info=props.info; |
|
|
|
if(parseInt(props.info.reply,10)) { |
|
|
|
} |
|
|
|
this.state.reply_loading=true; |
|
|
|
|
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
|
|
|
|
if(parseInt(this.info.reply,10)) { |
|
|
|
|
|
|
|
this.setState({ |
|
|
|
|
|
|
|
reply_loading: true, |
|
|
|
|
|
|
|
}); |
|
|
|
this.load_replies(); |
|
|
|
this.load_replies(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
load_replies() { |
|
|
|
load_replies() { |
|
|
|
console.log('fetching reply',this.info.pid); |
|
|
|
console.log('fetching reply',this.info.pid); |
|
|
|
fetch('http://www.pkuhelper.com:10301/pkuhelper/../services/pkuhole/api.php?action=getcomment&pid='+this.info.pid) |
|
|
|
fetch('http://www.pkuhelper.com:10301/services/pkuhole/api.php?action=getcomment&pid='+this.info.pid) |
|
|
|
.then((res)=>res.json()) |
|
|
|
.then((res)=>res.json()) |
|
|
|
.then((json)=>{ |
|
|
|
.then((json)=>{ |
|
|
|
if(json.code!==0) |
|
|
|
if(json.code!==0) |
|
|
@ -80,7 +87,7 @@ class FlowItemRow extends Component { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
)}}> |
|
|
|
)}}> |
|
|
|
<FlowItem info={this.info} /> |
|
|
|
<FlowItem info={this.info} /> |
|
|
|
{this.state.reply_loading && <ReplyPlaceholder count={this.info.reply} />} |
|
|
|
{!!this.state.reply_loading && <ReplyPlaceholder count={this.info.reply} />} |
|
|
|
{this.state.replies.map((reply)=><Reply info={reply} key={reply.cid} />)} |
|
|
|
{this.state.replies.map((reply)=><Reply info={reply} key={reply.cid} />)} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
@ -91,7 +98,11 @@ function FlowChunk(props) { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="flow-chunk"> |
|
|
|
<div className="flow-chunk"> |
|
|
|
<CenteredLine text={props.title} /> |
|
|
|
<CenteredLine text={props.title} /> |
|
|
|
{props.list.map((info)=><FlowItemRow key={info.pid} info={info} callback={props.callback} />)} |
|
|
|
{props.list.map((info)=>( |
|
|
|
|
|
|
|
<LazyLoad key={info.pid} offset={500} height="15em"> |
|
|
|
|
|
|
|
<FlowItemRow info={info} callback={props.callback} /> |
|
|
|
|
|
|
|
</LazyLoad> |
|
|
|
|
|
|
|
))} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
@ -100,7 +111,8 @@ export class Flow extends Component { |
|
|
|
constructor(props) { |
|
|
|
constructor(props) { |
|
|
|
super(props); |
|
|
|
super(props); |
|
|
|
this.state={ |
|
|
|
this.state={ |
|
|
|
mode: props.mode, |
|
|
|
mode: props.search_text===null ? 'list' : 'search', |
|
|
|
|
|
|
|
search_param: props.search_text, |
|
|
|
loaded_pages: 0, |
|
|
|
loaded_pages: 0, |
|
|
|
chunks: [], |
|
|
|
chunks: [], |
|
|
|
loading: false, |
|
|
|
loading: false, |
|
|
@ -113,11 +125,8 @@ export class Flow extends Component { |
|
|
|
throw new Error('bad page'); |
|
|
|
throw new Error('bad page'); |
|
|
|
if(page===this.state.loaded_pages+1) { |
|
|
|
if(page===this.state.loaded_pages+1) { |
|
|
|
console.log('fetching page',page); |
|
|
|
console.log('fetching page',page); |
|
|
|
this.setState((prev,props)=>({ |
|
|
|
if(this.state.mode==='list') { |
|
|
|
loaded_pages: prev.loaded_pages+1, |
|
|
|
fetch('http://www.pkuhelper.com:10301/services/pkuhole/api.php?action=getlist&p='+page) |
|
|
|
loading: true, |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
fetch('http://www.pkuhelper.com:10301/pkuhelper/../services/pkuhole/api.php?action=getlist&p='+page) |
|
|
|
|
|
|
|
.then((res)=>res.json()) |
|
|
|
.then((res)=>res.json()) |
|
|
|
.then((json)=>{ |
|
|
|
.then((json)=>{ |
|
|
|
if(json.code!==0) |
|
|
|
if(json.code!==0) |
|
|
@ -134,6 +143,31 @@ export class Flow extends Component { |
|
|
|
console.trace(err); |
|
|
|
console.trace(err); |
|
|
|
alert('load failed'); |
|
|
|
alert('load failed'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} else if(this.state.mode==='search') { |
|
|
|
|
|
|
|
fetch( |
|
|
|
|
|
|
|
'http://www.pkuhelper.com:10301/services/pkuhole/api.php?action=search'+ |
|
|
|
|
|
|
|
'&pagesize='+SEARCH_PAGESIZE*page+ |
|
|
|
|
|
|
|
'&keywords='+encodeURIComponent(this.state.search_param) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.then((res)=>res.json()) |
|
|
|
|
|
|
|
.then((json)=>{ |
|
|
|
|
|
|
|
if(json.code!==0) |
|
|
|
|
|
|
|
throw new Error(json.code); |
|
|
|
|
|
|
|
const finished=json.data.length<SEARCH_PAGESIZE; |
|
|
|
|
|
|
|
this.setState((prev,props)=>({ |
|
|
|
|
|
|
|
chunks: [{ |
|
|
|
|
|
|
|
title: 'Result for "'+this.state.search_param+'"', |
|
|
|
|
|
|
|
data: json.data, |
|
|
|
|
|
|
|
mode: finished ? 'search_finished' : 'search', |
|
|
|
|
|
|
|
}], |
|
|
|
|
|
|
|
loading: false, |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.setState((prev,props)=>({ |
|
|
|
|
|
|
|
loaded_pages: prev.loaded_pages+1, |
|
|
|
|
|
|
|
loading: true, |
|
|
|
|
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -161,7 +195,7 @@ export class Flow extends Component { |
|
|
|
{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} callback={this.props.callback} /> |
|
|
|
))} |
|
|
|
))} |
|
|
|
<CenteredLine text={this.state.loading ? 'Loading More...' : '© xmcp'} /> |
|
|
|
<CenteredLine text={this.state.loading ? 'Loading...' : '© xmcp'} /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|