import React, {Component} from 'react';
import {Time, CenteredLine} from './Common.js';
import './Flows.css';
const IMAGE_BASE='http://www.pkuhelper.com/services/pkuhole/images/';
const AUDIO_BASE='http://www.pkuhelper.com/services/pkuhole/audios/';
function Reply(props) {
return (
#{props.info.cid}
{props.info.text}
);
}
function ReplyPlaceholder(props) {
return (
正在加载 {props.count} 条回复
);
}
function FlowItem(props) {
return (
{parseInt(props.info.likenum, 10) && {props.info.likenum}★}
{parseInt(props.info.reply, 10) && {props.info.reply} 回复}
#{props.info.pid}
{props.info.text}
{props.info.type==='image' ?

: null}
{props.info.type==='audio' ?
: null}
);
}
class FlowItemRow extends Component {
constructor(props) {
super(props);
this.state={
replies: [],
reply_loading: false,
};
this.info=props.info;
if(parseInt(props.info.reply,10)) {
this.state.reply_loading=true;
this.load_replies();
}
}
load_replies() {
console.log('fetching reply',this.info.pid);
fetch('http://www.pkuhelper.com:10301/pkuhelper/../services/pkuhole/api.php?action=getcomment&pid='+this.info.pid)
.then((res)=>res.json())
.then((json)=>{
if(json.code!==0)
throw new Error(json.code);
this.setState({
replies: json.data.slice(0,10),
reply_loading: false,
});
});
}
render() {
// props.do_show_details
return (
{this.props.callback(
'帖子详情',
{this.state.replies.map((reply)=>)}
)}}>
{this.state.reply_loading &&
}
{this.state.replies.map((reply)=>
)}
);
}
}
function FlowChunk(props) {
return (
{props.list.map((info)=>)}
);
}
export class Flow extends Component {
constructor(props) {
super(props);
this.state={
mode: props.mode,
loaded_pages: 0,
chunks: [],
loading: false,
};
setTimeout(this.load_page.bind(this,1), 0);
}
load_page(page) {
if(page>this.state.loaded_pages+1)
throw new Error('bad page');
if(page===this.state.loaded_pages+1) {
console.log('fetching page',page);
this.setState((prev,props)=>({
loaded_pages: prev.loaded_pages+1,
loading: true,
}));
fetch('http://www.pkuhelper.com:10301/pkuhelper/../services/pkuhole/api.php?action=getlist&p='+page)
.then((res)=>res.json())
.then((json)=>{
if(json.code!==0)
throw new Error(json.code);
this.setState((prev,props)=>({
chunks: prev.chunks.concat([{
title: 'Page '+page,
data: json.data,
}]),
loading: false,
}));
})
.catch((err)=>{
console.trace(err);
alert('load failed');
});
}
}
on_scroll(event) {
if(event.target===document) {
//console.log(event);
const avail=document.body.scrollHeight-window.scrollY-window.innerHeight;
if(avail
{this.state.chunks.map((chunk)=>(
))}
);
}
}