Created reducer and stateactions for lobby.

master
Håvar Aambø Fosstveit 2019-10-15 08:03:18 +02:00
parent aa55adbb2d
commit 2e166ca2b2
2 changed files with 76 additions and 0 deletions

View File

@ -391,6 +391,30 @@ export const setPeerVolume = (peerId, volume) =>
};
};
export const addLobbyPeer = (lobbyPeer) =>
{
return {
type : 'ADD_LOBBY_PEER',
payload : { lobbyPeer }
};
};
export const removeLobbyPeer = (peerId) =>
{
return {
type : 'REMOVE_LOBBY_PEER',
payload : { peerId }
};
};
export const setLobbyPeerDisplayName = (displayName, peerId) =>
{
return {
type : 'SET_LOBBY_PEER_DISPLAY_NAME',
payload : { displayName, peerId }
};
};
export const addNotification = (notification) =>
{
return {

View File

@ -0,0 +1,52 @@
const lobbyPeer = (state = {}, action) =>
{
switch (action.type)
{
case 'ADD_LOBBY_PEER':
return action.payload.lobbyPeer;
case 'SET_LOBBY_PEER_DISPLAY_NAME':
return { ...state, displayName: action.payload.displayName };
default:
return state;
}
};
const lobbyPeers = (state = {}, action) =>
{
switch (action.type)
{
case 'ADD_LOBBY_PEER':
{
return { ...state, [action.payload.lobbyPeer.id]: lobbyPeer(undefined, action) };
}
case 'REMOVE_LOBBY_PEER':
{
const { peerId } = action.payload;
const newState = { ...state };
delete newState[peerId];
return newState;
}
case 'SET_LOBBY_PEER_DISPLAY_NAME':
{
const oldLobbyPeer = state[action.payload.peerId];
if (!oldLobbyPeer)
{
throw new Error('no Peer found');
}
return { ...state, [oldLobbyPeer.id]: lobbyPeer(oldLobbyPeer, action) };
}
default:
return state;
}
};
export default lobbyPeers;