xmcp 6 years ago
parent
commit
f53087d56c
  1. 24
      src/App.js
  2. 7
      src/Common.js
  3. 14
      src/Flows.js
  4. 4
      src/UserAction.js
  5. 2
      src/flows_api.js

24
src/App.js

@ -5,10 +5,23 @@ import {Sidebar} from './Sidebar';
import {PressureHelper} from './PressureHelper'; import {PressureHelper} from './PressureHelper';
import {TokenCtx} from './UserAction'; import {TokenCtx} from './UserAction';
function TokenDeprecatedAlert(props) { function DeprecatedAlert(props) {
if(!props.token || !props.token.startsWith('isop_')) // noinspection JSConstructorReturnsPrimitive if(['pkuhelper.com','www.pkuhelper.com','webhole.xmcp.ml','127.0.0.1','localhost'].indexOf(document.domain)===-1)
return null; return (
else <div className="flow-item-row">
<div className="box box-tip aux-margin">
<p><b>官宣了</b></p>
<br />
<p>请访问官方树洞网页版</p>
<p><a href="http://pkuhelper.com/hole">http://pkuhelper.com/hole</a></p>
<p>加载三倍速访问不卡顿</p>
<br />
<p>当前域名将停止维护</p>
<p>@xmcp</p>
</div>
</div>
);
if(props.token && props.token.startsWith('isop_'))
return ( return (
<div className="flow-item-row"> <div className="flow-item-row">
<div className="box box-tip box-danger aux-margin"> <div className="box box-tip box-danger aux-margin">
@ -18,6 +31,7 @@ function TokenDeprecatedAlert(props) {
</div> </div>
</div> </div>
); );
return null;
} }
class App extends Component { class App extends Component {
@ -79,7 +93,7 @@ class App extends Component {
<Title show_sidebar={this.show_sidebar_bound} set_mode={this.set_mode_bound} /> <Title show_sidebar={this.show_sidebar_bound} set_mode={this.set_mode_bound} />
<TokenCtx.Consumer>{(token)=>( <TokenCtx.Consumer>{(token)=>(
<div className="left-container"> <div className="left-container">
<TokenDeprecatedAlert token={token.value} /> <DeprecatedAlert token={token.value} />
<Flow key={this.state.flow_render_key} show_sidebar={this.show_sidebar_bound} <Flow key={this.state.flow_render_key} show_sidebar={this.show_sidebar_bound}
mode={this.state.mode} search_text={this.state.search_text} token={token.value} mode={this.state.mode} search_text={this.state.search_text} token={token.value}
/> />

7
src/Common.js

@ -1,4 +1,5 @@
import React, {Component, PureComponent} from 'react'; import React, {Component, PureComponent} from 'react';
import {PKUHELPER_ROOT} from './flows_api';
import TimeAgo from 'react-timeago'; import TimeAgo from 'react-timeago';
import Linkify from 'react-linkify'; import Linkify from 'react-linkify';
@ -9,7 +10,7 @@ import './Common.css';
const chinese_format=buildFormatter(chineseStrings); const chinese_format=buildFormatter(chineseStrings);
export const API_BASE=window.location.protocol==='https:' ? '/api_proxy' : 'http://www.pkuhelper.com:10301/services/pkuhole'; export const API_BASE=PKUHELPER_ROOT+'services/pkuhole';
const PID_RE=/(^|[^\d])([1-9]\d{4,5})(?!\d)/g; const PID_RE=/(^|[^\d])([1-9]\d{4,5})(?!\d)/g;
const NICKNAME_RE=/(^|[^A-Za-z])((?:(?:Angry|Baby|Crazy|Diligent|Excited|Fat|Greedy|Hungry|Interesting|Japanese|Kind|Little|Magic|Naïve|Old|Powerful|Quiet|Rich|Superman|THU|Undefined|Valuable|Wifeless|Xiangbuchulai|Young|Zombie)\s)?(?:Alice|Bob|Carol|Dave|Eve|Francis|Grace|Hans|Isabella|Jason|Kate|Louis|Margaret|Nathan|Olivia|Paul|Queen|Richard|Susan|Thomas|Uma|Vivian|Winnie|Xander|Yasmine|Zach)|You Win(?: \d+)?|洞主)(?![A-Za-z])/gi; const NICKNAME_RE=/(^|[^A-Za-z])((?:(?:Angry|Baby|Crazy|Diligent|Excited|Fat|Greedy|Hungry|Interesting|Japanese|Kind|Little|Magic|Naïve|Old|Powerful|Quiet|Rich|Superman|THU|Undefined|Valuable|Wifeless|Xiangbuchulai|Young|Zombie)\s)?(?:Alice|Bob|Carol|Dave|Eve|Francis|Grace|Hans|Isabella|Jason|Kate|Louis|Margaret|Nathan|Olivia|Paul|Queen|Richard|Susan|Thomas|Uma|Vivian|Winnie|Xander|Yasmine|Zach)|You Win(?: \d+)?|洞主)(?![A-Za-z])/gi;
@ -92,12 +93,10 @@ export class SafeTextarea extends Component {
text: '', text: '',
}); });
} }
set_and_focus(text) { set(text) {
this.change_callback(text); this.change_callback(text);
this.setState({ this.setState({
text: text, text: text,
},()=>{
this.area_ref.current.focus();
}); });
} }
get() { get() {

14
src/Flows.js

@ -7,10 +7,10 @@ import LazyLoad from 'react-lazyload';
import {AudioWidget} from './AudioWidget'; import {AudioWidget} from './AudioWidget';
import {TokenCtx, ReplyForm} from './UserAction'; import {TokenCtx, ReplyForm} from './UserAction';
import {API} from './flows_api'; import {API, PKUHELPER_ROOT} from './flows_api';
const IMAGE_BASE='http://www.pkuhelper.com:10301/services/pkuhole/images/'; const IMAGE_BASE=PKUHELPER_ROOT+'services/pkuhole/images/';
const AUDIO_BASE='http://www.pkuhelper.com:10301/services/pkuhole/audios/'; const AUDIO_BASE=PKUHELPER_ROOT+'services/pkuhole/audios/';
const SEARCH_PAGESIZE=50; const SEARCH_PAGESIZE=50;
const CLICKABLE_TAGS={a: true, audio: true}; const CLICKABLE_TAGS={a: true, audio: true};
@ -253,11 +253,11 @@ class FlowSidebar extends PureComponent {
} }
} }
do_reply(name,event) { show_reply_bar(name,event) {
if(event.target.tagName.toLowerCase()!=='a') { if(event.target.tagName.toLowerCase()!=='a') {
let text=this.reply_ref.current.get(); 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 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_and_focus('Re '+name+': '); this.reply_ref.current.set('Re '+name+': ');
} }
} }
@ -296,7 +296,7 @@ class FlowSidebar extends PureComponent {
</span> </span>
} }
</div> </div>
<div onClick={(e)=>{this.do_reply('',e);}}> <div onClick={(e)=>{this.show_reply_bar('',e);}}>
<FlowItem info={this.state.info} attention={this.state.attention} img_clickable={true} <FlowItem info={this.state.info} attention={this.state.attention} img_clickable={true}
color_picker={this.color_picker} show_pid={this.show_pid} replies={this.state.replies} color_picker={this.color_picker} show_pid={this.show_pid} replies={this.state.replies}
set_variant={(variant)=>{this.set_variant(null,variant);}} set_variant={(variant)=>{this.set_variant(null,variant);}}
@ -309,7 +309,7 @@ class FlowSidebar extends PureComponent {
} }
{this.state.replies.map((reply)=>( {this.state.replies.map((reply)=>(
<LazyLoad key={reply.cid} offset={1500} height="5em" overflow={true} once={true}> <LazyLoad key={reply.cid} offset={1500} height="5em" overflow={true} once={true}>
<div onClick={(e)=>{this.do_reply(reply.name,e);}}> <div onClick={(e)=>{this.show_reply_bar(reply.name,e);}}>
<Reply <Reply
info={reply} color_picker={this.color_picker} show_pid={this.show_pid} info={reply} color_picker={this.color_picker} show_pid={this.show_pid}
set_variant={(variant)=>{this.set_variant(reply.cid,variant);}} set_variant={(variant)=>{this.set_variant(reply.cid,variant);}}

4
src/UserAction.js

@ -1,12 +1,12 @@
import React, {Component, PureComponent} from 'react'; import React, {Component, PureComponent} from 'react';
import {SafeTextarea} from './Common'; import {SafeTextarea} from './Common';
import {API_VERSION_PARAM,API} from './flows_api' import {API_VERSION_PARAM,PKUHELPER_ROOT,API} from './flows_api'
import md5 from 'md5'; import md5 from 'md5';
import './UserAction.css'; import './UserAction.css';
import {API_BASE} from './Common'; import {API_BASE} from './Common';
const LOGIN_BASE=window.location.protocol==='https:' ? '/login_proxy' : 'http://www.pkuhelper.com:10301/services/login'; const LOGIN_BASE=PKUHELPER_ROOT+'services/login';
const MAX_IMG_PX=2000; const MAX_IMG_PX=2000;
const MAX_IMG_FILESIZE=256000; const MAX_IMG_FILESIZE=256000;

2
src/flows_api.js

@ -1,6 +1,8 @@
import {API_BASE} from './Common'; import {API_BASE} from './Common';
export const API_VERSION_PARAM='&PKUHelperAPI=3.0'; export const API_VERSION_PARAM='&PKUHelperAPI=3.0';
export const PKUHELPER_ROOT= // don't use :10301 if we are already in the same domain
(document.domain==='pkuhelper.com'||document.domain==='www.pkuhelper.com') ? '/' : 'http://pkuhelper.com:10301/';
function token_param(token) { function token_param(token) {
return API_VERSION_PARAM + (token ? ('&user_token='+token) : ''); return API_VERSION_PARAM + (token ? ('&user_token='+token) : '');

Loading…
Cancel
Save