Files
CHOMPStation2/tgui/packages/tgui-panel/audio/reducer.ts
CHOMPStation2 c96b18a2d3 [MIRROR] [TGUI 5.0 Prep] Removes context (#7455)
Co-authored-by: Selis <sirlionfur@hotmail.de>
Co-authored-by: Selis <selis@xynolabs.com>
2024-02-07 23:37:37 +01:00

51 lines
839 B
TypeScript

/**
* @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;
};