Files
CHOMPStation2/tgui/packages/tgui-panel/audio/reducer.js
Chompstation Bot 331e5230d6 TGUI 4.3
2021-06-19 04:46:36 -04:00

51 lines
839 B
JavaScript

/**
* @file
* @copyright 2020 Aleksej Komarov
* @license MIT
*/
const initialState = {
visible: false,
playing: false,
track: null,
};
export const audioReducer = (state = initialState, action) => {
const { type, payload } = action;
if (type === 'audio/playing') {
return {
...state,
visible: true,
playing: true,
};
}
if (type === 'audio/stopped') {
return {
...state,
visible: false,
playing: false,
};
}
if (type === 'audio/playMusic') {
return {
...state,
meta: payload,
};
}
if (type === 'audio/stopMusic') {
return {
...state,
visible: false,
playing: false,
meta: null,
};
}
if (type === 'audio/toggle') {
return {
...state,
visible: !state.visible,
};
}
return state;
};