Skip to content

Commit

Permalink
feat(UseMeetingControls): check for available controls
Browse files Browse the repository at this point in the history
  • Loading branch information
akoushke committed Jan 23, 2020
1 parent ff14955 commit c0599d5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/hooks/useMeetingControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ export default function useMeetingControl(type) {
const [display, setDisplay] = useState({});
const {meetingsAdapter} = useContext(AdapterContext);
const meetingID = useContext(MeetingContext);
const controls = meetingsAdapter.meetingControls;
let control;

const control = meetingsAdapter.meetingControls[type];
const {action} = control;
if (controls[type]) {
control = controls[type];
} else {
// eslint-disable-next-line no-console
console.error(`${type} control is not defined. Available controls are "${Object.keys(controls).join(', ')}".`);
}

useEffect(() => {
const subscription = control.display(meetingID).subscribe(setDisplay);
Expand All @@ -25,5 +31,5 @@ export default function useMeetingControl(type) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return [() => action(meetingID), display];
return [() => control.action(meetingID), display];
}

0 comments on commit c0599d5

Please sign in to comment.