import React, {Component, PureComponent} from 'react';
import {PKUHELPER_ROOT} from './flows_api';
import TimeAgo from 'react-timeago';
import Linkify from 'react-linkify';
import chineseStrings from 'react-timeago/lib/language-strings/zh-CN';
import buildFormatter from 'react-timeago/lib/formatters/buildFormatter';
import './Common.css';
const chinese_format=buildFormatter(chineseStrings);
export const API_BASE=PKUHELPER_ROOT+'services/pkuhole';
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;
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 (
{props.text}
) } export class HighlightedText extends PureComponent { render() { let parts=[].concat.apply([], this.props.text.split(PID_RE).map((p)=>p.split(NICKNAME_RE))); return (
{parts.map((p,idx)=>(
{
PID_RE.test(p) ? {e.preventDefault(); this.props.show_pid(p);}}>{p} :
NICKNAME_RE.test(p) ? {p} :
p
}
))}