Files
GS13NG/tgui/packages/tgui-panel/game/reducer.js
2020-08-15 16:08:10 +08:00

40 lines
779 B
JavaScript

/**
* @file
* @copyright 2020 Aleksej Komarov
* @license MIT
*/
import { connectionLost } from './actions';
import { connectionRestored } from './actions';
const initialState = {
// TODO: This is where round info should be.
roundId: null,
roundTime: null,
roundRestartedAt: null,
connectionLostAt: null,
};
export const gameReducer = (state = initialState, action) => {
const { type, payload, meta } = action;
if (type === 'roundrestart') {
return {
...state,
roundRestartedAt: meta.now,
};
}
if (type === connectionLost.type) {
return {
...state,
connectionLostAt: meta.now,
};
}
if (type === connectionRestored.type) {
return {
...state,
connectionLostAt: null,
};
}
return state;
};