From 47e5ee57ca448f6eabbc659465761a2b80667619 Mon Sep 17 00:00:00 2001
From: xmcp
Date: Wed, 28 Aug 2019 23:08:55 +0800
Subject: [PATCH] add balance shower and remove quote,color_picker config
---
src/BalanceShower.css | 19 ++++++++++
src/BalanceShower.js | 81 +++++++++++++++++++++++++++++++++++++++++++
src/Config.js | 12 +------
src/Flows.js | 2 +-
src/Title.js | 15 ++++----
src/color_picker.js | 2 --
6 files changed, 111 insertions(+), 20 deletions(-)
create mode 100644 src/BalanceShower.css
create mode 100644 src/BalanceShower.js
diff --git a/src/BalanceShower.css b/src/BalanceShower.css
new file mode 100644
index 0000000..4b5a918
--- /dev/null
+++ b/src/BalanceShower.css
@@ -0,0 +1,19 @@
+.balance-popover {
+ position: absolute;
+ top: 2em;
+ margin: auto;
+ left: 50%;
+ transform: translateX(-50%);
+ z-index: 1;
+}
+
+.balance-value {
+ opacity: 0;
+ animation: balance-disappear 2s ease-in;
+}
+
+@keyframes balance-disappear {
+ from {opacity: 1;}
+ 75% {opacity: 1;}
+ to {opacity: 0;}
+}
\ No newline at end of file
diff --git a/src/BalanceShower.js b/src/BalanceShower.js
new file mode 100644
index 0000000..86ebf52
--- /dev/null
+++ b/src/BalanceShower.js
@@ -0,0 +1,81 @@
+import React, {Component, PureComponent} from 'react';
+import {PKUHELPER_ROOT} from './infrastructure/const';
+import {API_VERSION_PARAM, get_json} from './flows_api';
+import {TokenCtx} from './UserAction';
+
+import './BalanceShower.css';
+
+export class BalanceShower extends PureComponent {
+ constructor(props) {
+ super(props);
+ this.state={
+ loading_status: 'idle',
+ error: null,
+ balance: null,
+ };
+ }
+
+ do_load(token) {
+ if(this.state.loading_status==='loading')
+ return;
+ if(!token || !window.config.easter_egg) {
+ this.setState({
+ loading_status: 'idle',
+ });
+ return;
+ }
+
+ this.setState({
+ loading_status: 'loading',
+ },()=>{
+ fetch(
+ PKUHELPER_ROOT+'api_xmcp/isop/card_balance'
+ +'?user_token='+encodeURIComponent(token)
+ +API_VERSION_PARAM()
+ )
+ .then(get_json)
+ .then((json)=>{
+ console.log(json);
+ if(!json.success)
+ throw new Error(JSON.stringify(json));
+
+ this.setState({
+ loading_status: 'done',
+ error: null,
+ balance: json.balance,
+ });
+ })
+ .catch((e)=>{
+ console.error(e);
+ this.setState({
+ loading_status: 'error',
+ error: ''+e,
+ });
+ });
+ })
+ }
+
+ render_popover() {
+ if(this.state.loading_status==='idle') // no token or disabled
+ return null;
+ else if(this.state.loading_status==='loading')
+ return (……
);
+ else if(this.state.loading_status==='error')
+ return ();
+ else if(this.state.loading_status==='done')
+ return (校园卡 ¥{this.state.balance}
);
+ else
+ return null;
+ }
+
+ render() {
+ return (
+ {(token)=>(
+ this.do_load(token.value)}>
+
{this.render_popover()}
+ {this.props.children}
+
+ )}
+ )
+ }
+}
\ No newline at end of file
diff --git a/src/Config.js b/src/Config.js
index b494f41..a7d14b9 100644
--- a/src/Config.js
+++ b/src/Config.js
@@ -14,9 +14,7 @@ const DEFAULT_CONFIG={
background_img: 'static/bg/gbp.jpg',
background_color: '#113366',
pressure: false,
- quote: true,
horizontal_scroll: true,
- color_picker: true,
easter_egg: true,
comment_cache: false,
color_scheme: 'default',
@@ -235,20 +233,12 @@ export class ConfigUI extends PureComponent {
-
-
+ />y
-
-
diff --git a/src/Flows.js b/src/Flows.js
index fe5d121..bc06ad6 100644
--- a/src/Flows.js
+++ b/src/Flows.js
@@ -484,7 +484,7 @@ class FlowItemRow extends PureComponent {
let parts=split_text(this.state.info.text,hl_rules);
let quote_id=null;
- if(!this.props.is_quote && window.config.quote)
+ if(!this.props.is_quote)
for(let [mode,content] of parts)
if(mode==='pid' && QUOTE_BLACKLIST.indexOf(content)===-1 && parseInt(content)强制检查更新
- ([{process.env.REACT_APP_BUILD_INFO||'---'}] {process.env.NODE_ENV})
+ ({process.env.REACT_APP_BUILD_INFO||'---'} {process.env.NODE_ENV})
This program is free software: you can redistribute it and/or modify
@@ -186,11 +187,13 @@ export function Title(props) {
diff --git a/src/color_picker.js b/src/color_picker.js
index cff6ead..f786652 100644
--- a/src/color_picker.js
+++ b/src/color_picker.js
@@ -12,8 +12,6 @@ export class ColorPicker {
name=name.toLowerCase();
if(name==='洞主')
return ['hsl(0,0%,97%)','hsl(0,0%,25%)'];
- if(!window.config.color_picker)
- return ['hsl(0,0%,87%)','hsl(0,0%,13%)'];
if(!this.names[name]) {
this.current_h+=golden_ratio_conjugate;