123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- import { Map, List } from "immutable";
- const JOIN_STATION = "STATION_INFO::JOIN_STATION";
- const LEAVE_STATION = "STATION_INFO::LEAVE_STATION";
- const USER_LIST_UPDATE = "STATION_INFO::USER_LIST_UPDATE";
- const USER_COUNT_UPDATE = "STATION_INFO::USER_COUNT_UPDATE";
- const NAME_UPDATE = "STATION_INFO::NAME_UPDATE";
- const DISPLAY_NAME_UPDATE = "STATION_INFO::DISPLAY_NAME_UPDATE";
- const DESCRIPTION_UPDATE = "STATION_INFO::DESCRIPTION_UPDATE";
- const MODE_UPDATE = "STATION_INFO::MODE_UPDATE";
- const QUEUE_INDEX = "STATION_INFO::QUEUE_INDEX";
- const QUEUE_UPDATE = "STATION_INFO::QUEUE_UPDATE";
- function joinStation(station) {
- return {
- type: JOIN_STATION,
- station,
- }
- }
- function leaveStation() {
- return {
- type: LEAVE_STATION,
- }
- }
- function userListUpdate(userList) {
- return {
- type: USER_LIST_UPDATE,
- userList,
- }
- }
- function userCountUpdate(userCount) {
- return {
- type: USER_COUNT_UPDATE,
- userCount,
- }
- }
- function nameUpdate(name) {
- return {
- type: NAME_UPDATE,
- name,
- }
- }
- function displayNameUpdate(displayName) {
- return {
- type: DISPLAY_NAME_UPDATE,
- displayName,
- }
- }
- function descriptionUpdate(description) {
- return {
- type: DESCRIPTION_UPDATE,
- description,
- }
- }
- function modeUpdate(mode) {
- return {
- type: MODE_UPDATE,
- mode,
- }
- }
- function queueIndex(songList) {
- return {
- type: QUEUE_INDEX,
- songList,
- }
- }
- function queueUpdate(songList) {
- return {
- type: QUEUE_UPDATE,
- songList,
- }
- }
- const initialState = Map({
- "stationId": "",
- "name": "",
- "displayName": "",
- "description": "",
- "privacy": "private",
- "type": "community",
- "ownerId": "",
- "paused": true,
- "mode": "",
- "userList": List([]),
- "userCount": 0,
- "songList": List([]),
- });
- function reducer(state = initialState, action) {
- let name, displayName, description, mode, userList, userCount, songList;
- function getModeTemp(partyEnabled, queueLocked) {
- // If party enabled
- // If queue locked
- // Mode is DJ
- // If queue not locked
- // Mode party
- // If party not enabled
- // Mode is normal
- if (partyEnabled) {
- if (queueLocked) return "dj";
- else return "party";
- } else return "normal";
- }
- switch (action.type) {
- case JOIN_STATION:
- const { stationId, privacy, type, ownerId, paused } = action.station;
- name = action.station.name;
- displayName = action.station.displayName;
- description = action.station.description;
- userCount = action.station.userCount;
- mode = (getModeTemp(action.station.partyMode, action.station.locked));
- userList = List([]);
- action.station.userList.forEach((user) => {
- userList.push(user);
- });
- songList = List([]);
- action.station.songList.forEach((song) => {
- songList.push(song);
- });
- return state.merge({
- stationId,
- name: action.station.name,
- displayName,
- description,
- privacy,
- type,
- ownerId,
- paused,
- mode,
- userList,
- userCount,
- songList,
- });
- case LEAVE_STATION:
- return initialState;
- case USER_LIST_UPDATE:
- userList = List([]);
- action.userList.forEach((user) => {
- userList.push(user);
- });
- state.set("userList", userList);
- return state;
- case USER_COUNT_UPDATE:
- userCount = action.userCount;
- state.set("userCount", userCount);
- return state;
- case NAME_UPDATE:
- name = action.name;
- state.set("name", name);
- return state;
- case DISPLAY_NAME_UPDATE:
- displayName = action.displayName;
- state.set("displayName", displayName);
- return state;
- case DESCRIPTION_UPDATE:
- description = action.description;
- state.set("description", description);
- return state;
- case MODE_UPDATE:
- mode = action.mode;
- state.set("mode", mode);
- return state;
- case QUEUE_INDEX:
- songList = List([]);
- action.songList.forEach((song) => {
- songList.push(song);
- });
- return state;
- case QUEUE_UPDATE:
- songList = List([]);
- action.songList.forEach((song) => {
- songList.push(song);
- });
- return state;
- }
- return state;
- }
- const actionCreators = {
- joinStation,
- leaveStation,
- userListUpdate,
- userCountUpdate,
- nameUpdate,
- displayNameUpdate,
- descriptionUpdate,
- modeUpdate,
- queueIndex,
- queueUpdate,
- };
- const actionTypes = {
- JOIN_STATION,
- LEAVE_STATION,
- USER_LIST_UPDATE,
- USER_COUNT_UPDATE,
- NAME_UPDATE,
- DISPLAY_NAME_UPDATE,
- DESCRIPTION_UPDATE,
- MODE_UPDATE,
- QUEUE_INDEX,
- QUEUE_UPDATE,
- };
- export {
- actionCreators,
- actionTypes,
- };
- export default reducer;
|