-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.es
90 lines (80 loc) · 2.71 KB
/
index.es
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React, { Component } from 'react'
import { isEmpty } from 'lodash'
import { join } from 'path-extra'
import { observer, observe } from 'redux-observers'
import { store } from 'views/createStore'
import { reducer } from './redux'
import { baseDetailSelector, historyDataSelector, rankSelector } from './redux/selectors'
import { storeHistoryData } from './redux/actions'
import { saveHistoryData, storePath, getMemberId } from './components/utils'
import SettingPanel from './components/setting-panel'
import DetailPanel from './components/detail-panel'
import TimerPanel from './components/timer-panel'
import RatePanel from './components/rate-panel'
import RankPanel from './components/rank-panel'
import HistoryPanel from './components/history-panel'
export const reactClass = class SenkaCalc extends Component {
render() {
return (
<div id="Senka Calc" className="Senka Calc">
<link rel='stylesheet' href={join(__dirname , 'assets', 'senka-calc.css')} />
<SettingPanel />
<DetailPanel />
<TimerPanel />
<RatePanel />
<RankPanel />
<HistoryPanel />
</div>
)
}
}
export { reducer }
let unsubBaseDetailObserve, unsubRankObserve, unsubHistoryDataObserve
export function pluginDidLoad() {
unsubBaseDetailObserve = observe(store, [observer(
baseDetailSelector,
(dispatch, current, previous) => {
if (isEmpty(current.custom)) {
return
}
if (previous.rank.updatedTime && previous.rank.updatedTime !== current.rank.updatedTime) {
return dispatch({ type: '@@RATE_RESET_RATE'})
}
if (previous.timer.counter.accounted.status !== current.timer.counter.accounted.status
&& current.timer.counter.accounted.status
&& current.rank.eoRate.new !== 0) {
return dispatch({ type: '@@RATE_STORE_EORATE'})
}
const id = getMemberId()
const data = JSON.parse(localStorage.getItem(storePath) || '{}')
data[id] = current
localStorage.setItem(storePath, JSON.stringify(data))
}
)])
unsubRankObserve = observe(store, [observer(
rankSelector,
(dispatch, current, previous) => {
if (!current.rank || !previous.rank) {
return
}
if (current.rank.updatedTime !== previous.rank.updatedTime) {
dispatch(storeHistoryData())
}
}
)])
unsubHistoryDataObserve = observe(store, [observer(
historyDataSelector,
(dispatch, current, previous) => {
if (!current.historyData) {
return
}
saveHistoryData(current.historyData)
}
)])
store.dispatch({ type: '@@poi-plugin-senka-calc@init' })
}
export function pluginWillUnload() {
unsubBaseDetailObserve()
unsubRankObserve()
unsubHistoryDataObserve()
}