Add selector options for special case shows.

This commit is contained in:
Matthew Stratford 2020-04-12 15:25:59 +01:00
parent d9334a9fd0
commit 3bc2990531
2 changed files with 116 additions and 2 deletions

View file

@ -18,6 +18,10 @@ export type BroadcastStageEnum =
interface BroadcastState {
stage: BroadcastStageEnum;
connID: number | null;
sourceID: number;
autoNewsBeginning: boolean;
autoNewsMiddle: boolean;
autoNewsEnd: boolean;
tracklisting: boolean;
connectionState: ConnectionStateEnum;
recordingState: ConnectionStateEnum;
@ -34,11 +38,20 @@ const broadcastState = createSlice({
initialState: {
stage: "NOT_REGISTERED",
connID: null,
sourceID: 5,
autoNewsBeginning: true,
autoNewsMiddle: true,
autoNewsEnd: true,
tracklisting: false,
connectionState: "NOT_CONNECTED",
recordingState: "NOT_CONNECTED"
} as BroadcastState,
reducers: {
changeSetting<K extends keyof BroadcastState>(state: BroadcastState, action: PayloadAction<{ key: K, val: BroadcastState[K] }>) {
state[action.payload.key] = action.payload.val;
console.log("Changing timeslot broadcast options.")
changeTimeslot()
},
toggleTracklisting(state) {
state.tracklisting = !state.tracklisting;
},
@ -61,12 +74,16 @@ const broadcastState = createSlice({
export default broadcastState.reducer;
export interface TrackListItem {
audiologid: number;
}
export const changeBroadcastSetting = <K extends keyof BroadcastState>(key: K, val: BroadcastState[K]): AppThunk => async (dispatch, getState) => {
dispatch(broadcastState.actions.changeSetting({key: key, val: val}));
dispatch(changeTimeslot());
}
@ -76,7 +93,7 @@ export const registerTimeslot = (): AppThunk => async (dispatch, getState) => {
const memberid = state.currentUser?.memberid;
const timeslotid = state.currentTimeslot?.timeslot_id;
console.log("Attempting to Register for Broadcast.");
var sourceid = 4; // TODO: make UI for this.
var sourceid = getState().broadcast.sourceID;
var connID = (await sendBroadcastRegister(timeslotid, memberid, sourceid));
if (connID !== undefined) {
dispatch(broadcastState.actions.setConnID(connID["connid"]));
@ -98,6 +115,15 @@ export const cancelTimeslot = (): AppThunk => async (dispatch, getState) => {
}
};
export const changeTimeslot = (): AppThunk => async (dispatch, getState) => {
var state = getState().broadcast;
if (state.stage === "REGISTERED") {
console.log("Attempting to Change Broadcast Options.");
var response = (await sendBroadcastChange(state.connID, state.sourceID, state.autoNewsBeginning, state.autoNewsMiddle, state.autoNewsEnd));
}
};
export function sendBroadcastRegister(timeslotid: number | undefined, memberid: number | undefined, sourceid: number): Promise<any> {
return broadcastApiRequest("/registerTimeslot", "POST", {
memberid: memberid,
@ -111,6 +137,16 @@ export function sendBroadcastCancel(connid: number | null): Promise<string | nul
});
}
export function sendBroadcastChange(connid: number | null, sourceid: number, beginning: boolean, middle: boolean, end: boolean): Promise<any> {
return broadcastApiRequest("/changeTimeslot", "POST", {
connid: connid,
sourceid: sourceid,
beginning: beginning,
middle: middle,
end: end
});
}

View file

@ -2,13 +2,91 @@ import React from "react";
import { RootState } from "../rootReducer";
import { useSelector, useDispatch } from "react-redux";
import { changeSetting } from "./settingsState";
import { changeBroadcastSetting } from "../broadcast/state";
export function AdvancedTab() {
const settings = useSelector((state: RootState) => state.settings);
const broadcastState = useSelector((state: RootState) => state.broadcast);
const dispatch = useDispatch();
return (
<>
<h2>Selector Options</h2>
<div className="form-group">
<label>Selector Source (Don't change this unless you know what you're doing!)</label>
<select className="form-control" id="broadcastSourceSelect"
value={broadcastState.sourceID}
onChange={(e) =>
dispatch(
changeBroadcastSetting(
"sourceID",
parseInt(e.target.value),
)
)
}>
<option value="4">4 (OB-Line)</option>
<option value="5">5 (WebStudio Direct)</option>
</select>
</div>
<h3>Automatic News</h3>
<div className="form-check">
<input
className="form-check-input"
type="checkbox"
checked={broadcastState.autoNewsBeginning}
onChange={(e) =>
dispatch(
changeBroadcastSetting(
"autoNewsBeginning",
e.target.checked
)
)
}
/>
<label className="form-check-label">
Beginning of Show
</label>
</div>
<div className="form-check">
<input
className="form-check-input"
type="checkbox"
checked={broadcastState.autoNewsMiddle}
onChange={(e) =>
dispatch(
changeBroadcastSetting(
"autoNewsMiddle",
e.target.checked
)
)
}
/>
<label className="form-check-label">
Middle of Show (2+ hour shows only)
</label>
</div>
<div className="form-check">
<input
className="form-check-input"
type="checkbox"
checked={broadcastState.autoNewsEnd}
onChange={(e) =>
dispatch(
changeBroadcastSetting(
"autoNewsEnd",
e.target.checked,
)
)
}
/>
<label className="form-check-label">
End of Show
</label>
</div>
<hr />
<h2>Misc</h2>
<div className="form-check">
<input
className="form-check-input"