From 4a1527a9825c566ed489d899587f7c9d9fafa5b8 Mon Sep 17 00:00:00 2001 From: xmcp Date: Tue, 18 Jun 2019 19:17:53 +0800 Subject: [PATCH] extract infrastructure --- .gitmodules | 3 +++ src/Common.css | 36 ------------------------------------ src/Common.js | 34 ++-------------------------------- src/UserAction.js | 12 +++++------- src/flows_api.js | 9 ++++----- src/index.css | 28 ---------------------------- src/infrastructure | 1 + 7 files changed, 15 insertions(+), 108 deletions(-) create mode 160000 src/infrastructure diff --git a/.gitmodules b/.gitmodules index 992305c..acf50cf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,3 +6,6 @@ path = src/react-lazyload url = https://github.com/xmcp/react-lazyload +[submodule "src/infrastructure"] + path = src/infrastructure + url = https://github.com/pkuhelper-web/infrastructure diff --git a/src/Common.css b/src/Common.css index 7b3c454..56532be 100644 --- a/src/Common.css +++ b/src/Common.css @@ -1,39 +1,3 @@ -.centered-line { - overflow: hidden; - text-align: center; -} - -.centered-line::before, -.centered-line::after { - background-color: #000; - content: ""; - display: inline-block; - height: 1px; - position: relative; - vertical-align: middle; - width: 50%; -} - -.centered-line::before { - right: 1em; - margin-left: -50%; -} - -.centered-line::after { - left: 1em; - margin-right: -50%; -} - -.title-line { - color: #fff; - margin-top: 1em; -} -.title-line::before, -.title-line::after { - background-color: #fff; - box-shadow: 0 1px 1px #000; -} - .bg-img { position: fixed; z-index: -1; diff --git a/src/Common.js b/src/Common.js index 34544fb..ae300ff 100644 --- a/src/Common.js +++ b/src/Common.js @@ -1,20 +1,13 @@ import React, {Component, PureComponent} from 'react'; +import {format_time,Time,TitleLine} from './infrastructure/widgets'; import {PKUHELPER_ROOT} from './flows_api'; -import TimeAgo from 'react-timeago'; -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 {format_time,Time,TitleLine}; export const API_BASE=PKUHELPER_ROOT+'services/pkuhole'; -function pad2(x) { - return x<10 ? '0'+x : ''+x; -} - // https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex function escape_regex(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string @@ -24,29 +17,6 @@ export function build_highlight_re(txt,split) { return txt ? new RegExp(`(${txt.split(split).filter((x)=>!!x).map(escape_regex).join('|')})`,'g') : /^$/g; } -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 ( - - -   - {format_time(time)} - - ); -} - -export function TitleLine(props) { - return ( -

- {props.text} -

- ) -} - export class HighlightedText extends PureComponent { render() { function normalize_url(url) { diff --git a/src/UserAction.js b/src/UserAction.js index 5d5efe4..c3f7f03 100644 --- a/src/UserAction.js +++ b/src/UserAction.js @@ -1,20 +1,18 @@ import React, {Component, PureComponent} from 'react'; +import {ISOP_APPKEY,ISOP_APPCODE,ISOP_SVCID} from './infrastructure/const'; import copy from 'copy-to-clipboard'; -import {SafeTextarea} from './Common'; -import {API_VERSION_PARAM,PKUHELPER_ROOT,API,get_json} from './flows_api' +import {API_BASE,SafeTextarea} from './Common'; +import {MessageViewer} from './Message'; +import {API_VERSION_PARAM,PKUHELPER_ROOT,API,get_json} from './flows_api'; import md5 from 'md5'; import './UserAction.css'; -import {API_BASE} from './Common'; -import {MessageViewer} from './Message'; const LOGIN_BASE=PKUHELPER_ROOT+'services/login'; const MAX_IMG_PX=2500; const MAX_IMG_FILESIZE=300000; -export const ISOP_APPKEY='0feb3a8a831e11e8933a0050568508a5'; -export const ISOP_APPCODE='0fec960a831e11e8933a0050568508a5'; -export const ISOP_SVCID='PERSON_BASE_INFO,STUDENT_SCORE,STUDENT_COURSE_TABLE,STUDENT_COURSE_TABLE_ROOM,CARD_BALANCE'; +export {ISOP_APPKEY,ISOP_APPCODE,ISOP_SVCID}; export const TokenCtx=React.createContext({ value: null, diff --git a/src/flows_api.js b/src/flows_api.js index 7f6d463..b79d505 100644 --- a/src/flows_api.js +++ b/src/flows_api.js @@ -1,16 +1,15 @@ +import {get_json} from './infrastructure/functions'; +import {PKUHELPER_ROOT} from './infrastructure/const'; import {API_BASE} from './Common'; export const API_VERSION_PARAM='&PKUHelperAPI=3.0'; -export const PKUHELPER_ROOT='//pkuhelper.pku.edu.cn/'; +export {PKUHELPER_ROOT}; function token_param(token) { return API_VERSION_PARAM + (token ? ('&user_token='+token) : ''); } -export function get_json(res) { - if(!res.ok) throw Error(`网络错误 ${res.status} ${res.statusText}`); - return res.json(); -} +export {get_json}; export const API={ load_replies: (pid,token,color_picker)=>{ diff --git a/src/index.css b/src/index.css index 61bea1f..e48245f 100644 --- a/src/index.css +++ b/src/index.css @@ -1,10 +1,6 @@ body { - margin: 0; - padding: 0; background-size: cover; - overflow-x: hidden; user-select: none; - text-size-adjust: 100%; background-color: #124; } @@ -15,24 +11,8 @@ html { scrollbar-width: none; } -body, textarea, pre { - font-family: 'Segoe UI', '微软雅黑', 'Microsoft YaHei', sans-serif; -} - -* { - box-sizing: border-box; - word-wrap: break-word; - -webkit-overflow-scrolling: touch; -} - -p, pre { - margin: 0; -} - a { - text-decoration: none; color: #00c; - cursor: pointer; } input, textarea { @@ -49,10 +29,6 @@ audio { vertical-align: middle; } -pre { - white-space: pre-line; -} - button, .button { color: black; background-color: rgba(235,235,235,.5); @@ -70,7 +46,3 @@ button:hover, .button:hover { button:disabled, .button:disabled { background-color: rgba(128,128,128,.5); } - -code { - font-family: Consolas, Courier, monospace; -} \ No newline at end of file diff --git a/src/infrastructure b/src/infrastructure new file mode 160000 index 0000000..68ae75e --- /dev/null +++ b/src/infrastructure @@ -0,0 +1 @@ +Subproject commit 68ae75e38ecb45e7518b2b94c0de91701b8a56e8