xmcp 7 years ago
parent
commit
fdb88eef2e
  1. 9
      src/Common.js
  2. 12
      src/Flows.css
  3. 44
      src/Flows.js
  4. 2
      src/Sidebar.css
  5. 4
      src/UserAction.js
  6. 2
      src/index.css

9
src/Common.js

@ -18,14 +18,17 @@ function pad2(x) {
return x<10 ? '0'+x : ''+x;
}
export function format_time(time) {
return `${time.getMonth()+1}-${pad2(time.getDate())} ${time.getHours()}:${pad2(time.getMinutes())}:${pad2(time.getSeconds())}`;
}
export function Time(props) {
const time=new Date(props.stamp*1000);
return (
<span>
<TimeAgo date={time} formatter={chinese_format} />
&nbsp;
{time.getMonth()+1}-{time.getDate()}&nbsp;
{time.getHours()}:{pad2(time.getMinutes())}
{format_time(time)}
</span>
);
}
@ -102,7 +105,7 @@ export function PromotionBar(props) {
return is_ios ? (
<div className="box promotion-bar">
<span className="icon icon-about" />&nbsp;
Safari 将本网站 <b>添加到主屏幕</b>
Safari 将本网站 <b>添加到主屏幕</b>
</div>
) : null;
}

12
src/Flows.css

@ -113,6 +113,10 @@
}
}
.box-header {
font-size: small;
}
.flow-item-row p.img {
text-align: center;
}
@ -129,10 +133,6 @@
margin: 0 .5em;
}
.box-id {
opacity: .6;
}
.flow-item-dot {
position: relative;
top: calc(-.5em - 5px);
@ -144,3 +144,7 @@
background-color: orange;
box-shadow: 0 0 5px rgba(0,0,0,.4);
}
.box-content {
margin: .5em 0;
}

44
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 {Time, TitleLine, HighlightedText} from './Common';
import {format_time, Time, TitleLine, HighlightedText} from './Common';
import './Flows.css';
import LazyLoad from 'react-lazyload';
import {AudioWidget} from './AudioWidget';
@ -38,6 +38,7 @@ function load_single_meta(show_sidebar,token) {
<FlowSidebar
info={single.data} replies={replies.data} attention={replies.attention}
token={token} show_sidebar={show_sidebar} color_picker={color_picker}
deletion_detect={localStorage['DELETION_DETECT']==='on'}
/>
)
})
@ -62,15 +63,22 @@ function Reply(props) {
<code className="box-id">#{props.info.cid}</code>&nbsp;
<Time stamp={props.info.timestamp} />
</div>
<div className="box-content">
<HighlightedText text={props.info.text} color_picker={props.color_picker} show_pid={props.show_pid} />
</div>
</div>
);
}
function FlowItem(props) {
function copy_link(event) {
event.preventDefault();
copy(event.target.href);
copy(
`${event.target.href}\n`+
`${format_time(new Date(props.info.timestamp*1000))} ${props.info.likenum}${props.info.reply}回复)\n`+
`${props.info.text}${props.info.type==='image'?' [图片]':props.info.type==='audio'?' [语音]':''}\n`+
props.replies.map((r)=>(r.text)).join('\n')
);
}
return (
@ -93,6 +101,7 @@ function FlowItem(props) {
&nbsp;
<Time stamp={props.info.timestamp} />
</div>
<div className="box-content">
<HighlightedText text={props.info.text} color_picker={props.color_picker} show_pid={props.show_pid} />
{props.info.type==='image' &&
<p className="img">
@ -104,6 +113,7 @@ function FlowItem(props) {
}
{props.info.type==='audio' && <AudioWidget src={AUDIO_BASE+props.info.url} />}
</div>
</div>
);
}
@ -129,9 +139,6 @@ class FlowSidebar extends PureComponent {
.then((json)=>{
this.setState((prev,props)=>({
replies: json.data,
info: Object.assign({}, prev.info, {
reply: ''+json.data.length,
}),
attention: !!json.attention,
loading_status: 'done',
}), ()=>{
@ -213,20 +220,20 @@ class FlowSidebar extends PureComponent {
return (
<div className="flow-item-row sidebar-flow-item">
<div className="box box-tip">
{star_brush &&
{(star_brush && !!this.props.token) &&
<span>
<a onClick={this.star_brush.bind(this)}>-</a>
&nbsp;/&nbsp;
</span>
}
{this.props.token &&
{!!this.props.token &&
<span>
<a onClick={this.report.bind(this)}>举报</a>
&nbsp;/&nbsp;
</span>
}
<a onClick={this.load_replies.bind(this)}>刷新回复</a>
{this.props.token &&
{!!this.props.token &&
<span>
&nbsp;/&nbsp;
<a onClick={()=>{
@ -241,14 +248,20 @@ class FlowSidebar extends PureComponent {
}
</div>
<FlowItem info={this.state.info} attention={this.state.attention} img_clickable={true}
color_picker={this.color_picker} show_pid={this.show_pid} />
color_picker={this.color_picker} show_pid={this.show_pid} replies={this.state.replies} />
{(this.props.deletion_detect && parseInt(this.state.info.reply)!==this.state.replies.length) &&
<div className="box box-tip flow-item box-danger">
{parseInt(this.state.info.reply)-this.state.replies.length} 条回复被删除
</div>
}
{this.state.replies.map((reply)=>(
<LazyLoad key={reply.cid} offset={500} height="5em" overflow={true} once={true}>
<Reply info={reply} color_picker={this.color_picker} show_pid={this.show_pid} />
</LazyLoad>
))}
{this.props.token &&
<ReplyForm pid={this.state.info.pid} token={this.props.token} on_complete={this.load_replies.bind(this)} />
{!!this.props.token ?
<ReplyForm pid={this.state.info.pid} token={this.props.token} on_complete={this.load_replies.bind(this)} /> :
<div className="box box-tip flow-item">登录后可以回复树洞</div>
}
</div>
)
@ -283,9 +296,6 @@ class FlowItemRow extends PureComponent {
.then((json)=>{
this.setState((prev,props)=>({
replies: json.data,
info: Object.assign({}, prev.info, {
reply: ''+json.data.length,
}),
attention: !!json.attention,
reply_status: 'done',
}),callback);
@ -305,6 +315,7 @@ class FlowItemRow extends PureComponent {
<FlowSidebar
info={this.state.info} replies={this.state.replies} attention={this.state.attention} sync_state={this.setState.bind(this)}
token={this.props.token} show_sidebar={this.props.show_sidebar} color_picker={this.color_picker}
deletion_detect={this.props.deletion_detect}
/>
);
}
@ -316,7 +327,7 @@ class FlowItemRow extends PureComponent {
this.show_sidebar();
}}>
<FlowItem info={this.state.info} attention={this.state.attention} img_clickable={false}
color_picker={this.color_picker} show_pid={this.show_pid} />
color_picker={this.color_picker} show_pid={this.show_pid} replies={this.state.replies} />
<div className="flow-reply-row">
{this.state.reply_status==='loading' && <div className="box box-tip">加载中</div>}
{this.state.reply_status==='failed' &&
@ -349,7 +360,8 @@ function FlowChunk(props) {
</div>
</div>
}
<FlowItemRow info={info} show_sidebar={props.show_sidebar} token={token} />
<FlowItemRow info={info} show_sidebar={props.show_sidebar} token={token}
deletion_detect={props.deletion_detect} />
</div>
</LazyLoad>
))}

2
src/Sidebar.css

@ -24,7 +24,7 @@
height: 100%;
width: calc(100% - 700px);
padding: 1em;
background-color: rgba(255,255,255,.8);
background-color: rgba(255,255,255,.7);
z-index: 21;
overflow-y: auto;
}

4
src/UserAction.js

@ -102,8 +102,8 @@ export class LoginForm extends Component {
请勿泄露 Token它代表您的登录状态与您的账户唯一对应且泄露后无法重置
</p>
</div> :
<div>
<p>登录后可以使用关注回复等功能</p>
}
<p>
<label>
 学号&nbsp;
@ -129,6 +129,8 @@ export class LoginForm extends Component {
我们不会记录或使用您的登录信息
</p>
</div>
}
</div>
}</TokenCtx.Consumer>
)
}

2
src/index.css

@ -20,7 +20,7 @@ body, textarea, pre {
-webkit-overflow-scrolling: touch;
}
p {
p, pre {
margin: 0;
}

Loading…
Cancel
Save