forked from ppfun/pixelplanet
split ranks from user reducer
This commit is contained in:
parent
dec817d8a0
commit
e76e56027f
|
@ -34,7 +34,7 @@ const DailyRankings = ({ totalDailyRanking }) => (
|
|||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { totalDailyRanking } = state.user;
|
||||
const { totalDailyRanking } = state.ranks;
|
||||
return { totalDailyRanking };
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ const TotalRankings = ({ totalRanking }) => (
|
|||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { totalRanking } = state.user;
|
||||
const { totalRanking } = state.ranks;
|
||||
return { totalRanking };
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
80
src/reducers/ranks.js
Normal file
80
src/reducers/ranks.js
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user