diff --git a/src/components/DailyRankings.jsx b/src/components/DailyRankings.jsx index 672519c..80eb57c 100644 --- a/src/components/DailyRankings.jsx +++ b/src/components/DailyRankings.jsx @@ -34,7 +34,7 @@ const DailyRankings = ({ totalDailyRanking }) => ( ); function mapStateToProps(state: State) { - const { totalDailyRanking } = state.user; + const { totalDailyRanking } = state.ranks; return { totalDailyRanking }; } diff --git a/src/components/TotalRankings.jsx b/src/components/TotalRankings.jsx index a227f90..10bbd9c 100644 --- a/src/components/TotalRankings.jsx +++ b/src/components/TotalRankings.jsx @@ -34,7 +34,7 @@ const TotalRankings = ({ totalRanking }) => ( ); function mapStateToProps(state: State) { - const { totalRanking } = state.user; + const { totalRanking } = state.ranks; return { totalRanking }; } diff --git a/src/components/UserArea.jsx b/src/components/UserArea.jsx index a11f0a1..28c5ada 100644 --- a/src/components/UserArea.jsx +++ b/src/components/UserArea.jsx @@ -212,11 +212,13 @@ function mapStateToProps(state: State) { const { name, mailreg, + } = state.user; + const { totalPixels, dailyTotalPixels, ranking, dailyRanking, - } = state.user; + } = state.ranks; const stats = { totalPixels, dailyTotalPixels, diff --git a/src/reducers/index.js b/src/reducers/index.js index 28fc39e..0ad4c09 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -7,6 +7,7 @@ import canvas from './canvas'; import gui from './gui'; import modal from './modal'; import user from './user'; +import ranks from './ranks'; import chat from './chat'; import contextMenu from './contextMenu'; import chatRead from './chatRead'; @@ -38,6 +39,7 @@ const config = { storage: localForage, blacklist: [ 'user', + 'ranks', 'canvas', 'modal', 'chat', @@ -52,6 +54,7 @@ export default persistCombineReducers(config, { gui, modal, user, + ranks, chat, contextMenu, chatRead, diff --git a/src/reducers/ranks.js b/src/reducers/ranks.js new file mode 100644 index 0000000..fc87936 --- /dev/null +++ b/src/reducers/ranks.js @@ -0,0 +1,80 @@ +/* @flow */ + +import type { Action } from '../actions/types'; + +export type UserState = { + totalPixels: number, + dailyTotalPixels: number, + ranking: number, + dailyRanking: number, + // global stats + online: ?number, + totalRanking: Object, + totalDailyRanking: Object, +}; + +const initialState: UserState = { + totalPixels: 0, + dailyTotalPixels: 0, + ranking: 1488, + dailyRanking: 1488, + online: 1, + totalRanking: {}, + totalDailyRanking: {}, +}; + +export default function ranks( + state: UserState = initialState, + action: Action, +): UserState { + switch (action.type) { + case 'PLACED_PIXELS': { + let { totalPixels, dailyTotalPixels } = state; + const { amount } = action; + totalPixels += amount; + dailyTotalPixels += amount; + return { + ...state, + totalPixels, + dailyTotalPixels, + }; + } + + case 'RECEIVE_ONLINE': { + const { online } = action; + return { + ...state, + online, + }; + } + + case 'RECEIVE_ME': + case 'LOGIN': { + const { + totalPixels, + dailyTotalPixels, + ranking, + dailyRanking, + } = action; + return { + ...state, + totalPixels, + dailyTotalPixels, + ranking, + dailyRanking, + }; + } + + case 'RECEIVE_STATS': { + const { totalRanking, totalDailyRanking } = action; + return { + ...state, + totalRanking, + totalDailyRanking, + }; + } + + default: + return state; + } +} diff --git a/src/reducers/user.js b/src/reducers/user.js index 067261d..37a5a08 100644 --- a/src/reducers/user.js +++ b/src/reducers/user.js @@ -5,7 +5,6 @@ import type { Action } from '../actions/types'; import { createNameRegExp } from '../core/utils'; - export type UserState = { name: string, center: Cell, @@ -13,18 +12,9 @@ export type UserState = { coolDown: ?number, // ms lastCoolDownEnd: ?Date, requestingPixel: boolean, - online: ?number, // messages are sent by api/me, like not_verified status messages: Array, mailreg: boolean, - // stats - totalPixels: number, - dailyTotalPixels: number, - ranking: number, - dailyRanking: number, - // global stats - totalRanking: Object, - totalDailyRanking: Object, // minecraft minecraftname: string, // blocking all Dms @@ -46,11 +36,8 @@ const initialState: UserState = { coolDown: null, lastCoolDownEnd: null, requestingPixel: true, - online: null, messages: [], mailreg: false, - totalRanking: {}, - totalDailyRanking: {}, minecraftname: null, blockDm: false, isOnMobile: false, @@ -120,35 +107,11 @@ export default function user( }; } - case 'PLACED_PIXELS': { - let { totalPixels, dailyTotalPixels } = state; - const { amount } = action; - totalPixels += amount; - dailyTotalPixels += amount; - return { - ...state, - totalPixels, - dailyTotalPixels, - }; - } - - case 'RECEIVE_ONLINE': { - const { online } = action; - return { - ...state, - online, - }; - } - case 'RECEIVE_ME': case 'LOGIN': { const { name, mailreg, - totalPixels, - dailyTotalPixels, - ranking, - dailyRanking, minecraftname, blockDm, userlvl, @@ -160,10 +123,6 @@ export default function user( name, messages, mailreg, - totalPixels, - dailyTotalPixels, - ranking, - dailyRanking, minecraftname, blockDm, userlvl, @@ -184,15 +143,6 @@ export default function user( }; } - case 'RECEIVE_STATS': { - const { totalRanking, totalDailyRanking } = action; - return { - ...state, - totalRanking, - totalDailyRanking, - }; - } - case 'SET_NAME': { const { name } = action; const nameRegExp = createNameRegExp(name); diff --git a/src/utils/ip.js b/src/utils/ip.js index 2226e1f..e7afe69 100644 --- a/src/utils/ip.js +++ b/src/utils/ip.js @@ -31,7 +31,7 @@ export function getIPFromRequest(req): ?string { if (!USE_XREALIP) { logger.warn( - `Connection not going through reverse proxy! IP: ${conip}`, reqheaders, + `Connection not going through reverse proxy! IP: ${conip}`, req.headers, ); }