From 141e85c023c5534195e83f496d209f4263a984d0 Mon Sep 17 00:00:00 2001 From: Unicar Date: Wed, 29 May 2019 21:55:49 +1000 Subject: [PATCH] added support for local shici --- package.json | 1 - src/App.jsx | 38 +++++++++++++++++++++++++-------- src/components/LoadedVerses.jsx | 34 +---------------------------- yarn.lock | 5 ----- 4 files changed, 30 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index 78d910e..b0f49d4 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "dependencies": { "evergreen-ui": "^4.15.0", "html2canvas": "^1.0.0-rc.1", - "jinrishici": "^1.0.6", "prop-types": "^15", "react": "^16", "react-dom": "^16", diff --git a/src/App.jsx b/src/App.jsx index b15cde1..a7d69e7 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -9,6 +9,9 @@ import ConfigMenu from './components/ConfigMenu' import html2canvas from 'html2canvas' import Storager from './utils/storager' import { InlineAlert } from 'evergreen-ui' +import { load } from './utils/jinrishici' + +let shici = require('./utils/shici.json') class App extends Component { constructor (props) { @@ -23,12 +26,28 @@ class App extends Component { this.state = { isPlaying: true, defaultPlayChecked: true, - colorStayChecked: false + colorStayChecked: false, + verses: { + content: '红豆生南国,春来发几枝。', + origin: { + author: '王维', + title: '相思' + } + }, + errMessage: '' } } componentDidMount () { - Storager.get(['selected', 'colorStayChecked', 'defaultPlayChecked'], res => { + load(result => { + Storager.set({ verses: result.data }) + }, result => { + this.setState({ errMessage: result.errMessage }) + const localShici = shici[Math.floor(Math.random() * shici.length)] + Storager.set({ verses: localShici }) + }) + + Storager.get(['verses', 'selected', 'colorStayChecked', 'defaultPlayChecked'], res => { const isColorStayCheckedUntouched = res.colorStayChecked === undefined const isDefaultPlayCheckedUntouched = res.defaultPlayChecked === undefined @@ -36,7 +55,8 @@ class App extends Component { colorStayChecked: isColorStayCheckedUntouched ? false : res.colorStayChecked, defaultPlayChecked: isDefaultPlayCheckedUntouched ? true : res.defaultPlayChecked, isPlaying: isDefaultPlayCheckedUntouched ? true : res.defaultPlayChecked, - selected: res.selected || 'waves' + selected: res.selected || 'waves', + verses: res.verses }) }) } @@ -97,13 +117,13 @@ class App extends Component { } render () { - const { isPlaying, defaultPlayChecked, colorStayChecked, selected } = this.state + const { verses, isPlaying, defaultPlayChecked, colorStayChecked, selected, errMessage } = this.state const sketches = { blobs: blobs, waves: waves } return selected ? (
- + -
- - Changes will affect all warehouses + {errMessage &&
+ + {errMessage} -
+
}
) : null diff --git a/src/components/LoadedVerses.jsx b/src/components/LoadedVerses.jsx index 42095ce..d74684b 100644 --- a/src/components/LoadedVerses.jsx +++ b/src/components/LoadedVerses.jsx @@ -1,41 +1,9 @@ import React, { Component } from 'react' -import { load } from '../utils/jinrishici' import { Icon } from 'evergreen-ui' -import Storager from '../utils/storager' -let shici = require('../utils/shici.json') export default class LoadedVerses extends Component { - constructor (props) { - super() - this.state = { - verses: { - content: '红豆生南国,春来发几枝。', - origin: { - author: '王维', - title: '相思' - } - } - } - } - - componentDidMount () { - // fetch a verse from storage - Storager.get(['verses'], res => { - res.verses && this.setState({ verses: res.verses }) - }) - // fetch verse from jinrishici - - load(result => { - Storager.set({ verses: result.data }) - }, result => { - console.log(result) - const localShici = shici[Math.floor(Math.random() * shici.length)] - Storager.set({ verses: localShici }) - }) - } - render () { - const { content, origin } = this.state.verses + const { content, origin } = this.props.verses return (
diff --git a/yarn.lock b/yarn.lock index 3559574..54bcbf9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5141,11 +5141,6 @@ jest@^23: import-local "^1.0.0" jest-cli "^23.6.0" -jinrishici@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/jinrishici/-/jinrishici-1.0.6.tgz#1f3e1259de5e889ce1bab00f118248c7c346bd98" - integrity sha512-4Bk5VHo6xg9DspGS8y8I7D6kftA6DYy4rSvwpdtxFvh9DidXMgf+NSZKAXrcLTi8S5NjqmwkpAKYPHXRURH64Q== - js-levenshtein@^1.1.3: version "1.1.6" resolved "https://registry.yarnpkg.com/js-levenshtein/-/js-levenshtein-1.1.6.tgz#c6cee58eb3550372df8deb85fad5ce66ce01d59d"