2020-03-27 22:23:31 +00:00
|
|
|
import React from "react";
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
import classNames from "classnames";
|
|
|
|
|
2021-04-07 23:14:42 +01:00
|
|
|
import { Dispatch, State } from "../store";
|
|
|
|
import { togglePlay } from "../store/music/types";
|
2020-03-27 22:23:31 +00:00
|
|
|
|
|
|
|
type IndicatorProps = {
|
2021-04-07 23:23:21 +01:00
|
|
|
muted: boolean;
|
|
|
|
playing: boolean;
|
2020-03-27 22:23:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type IndicatorDispatch = {
|
2021-04-07 23:23:21 +01:00
|
|
|
play: () => void;
|
2020-03-27 22:23:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type Props = IndicatorProps & IndicatorDispatch;
|
|
|
|
|
2021-04-07 23:14:42 +01:00
|
|
|
class Indicator extends React.Component<Props, State> {
|
2021-04-07 23:23:21 +01:00
|
|
|
render() {
|
2022-07-30 22:17:32 +01:00
|
|
|
const button_classes = classNames({
|
|
|
|
button: true,
|
|
|
|
"is-primary": true,
|
|
|
|
"level-item": true,
|
|
|
|
// TODO(tlater): Add loading logic here
|
|
|
|
});
|
|
|
|
|
|
|
|
const icon_classes = classNames({
|
2021-04-07 23:23:21 +01:00
|
|
|
fas: true,
|
2022-07-30 22:17:32 +01:00
|
|
|
"fa-2x": true,
|
2021-04-07 23:23:21 +01:00
|
|
|
"fa-muted": this.props.muted,
|
2022-07-30 22:17:32 +01:00
|
|
|
"fa-play": !this.props.playing,
|
|
|
|
"fa-pause": this.props.playing,
|
2021-04-07 23:23:21 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
2022-08-03 01:48:06 +01:00
|
|
|
onClick={this.click}
|
2022-08-01 21:43:50 +01:00
|
|
|
className={button_classes}
|
|
|
|
>
|
2022-07-30 22:17:32 +01:00
|
|
|
<span className="icon is-medium">
|
|
|
|
<i className={icon_classes}></i>
|
|
|
|
</span>
|
|
|
|
</button>
|
2021-04-07 23:23:21 +01:00
|
|
|
);
|
|
|
|
}
|
2022-08-03 01:48:06 +01:00
|
|
|
|
|
|
|
click = () => {
|
|
|
|
this.props.play();
|
|
|
|
};
|
2020-03-27 22:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state: State): IndicatorProps {
|
2021-04-07 23:23:21 +01:00
|
|
|
return {
|
|
|
|
muted: state.musicState.muted,
|
|
|
|
playing: state.musicState.playing,
|
|
|
|
};
|
2020-03-27 22:23:31 +00:00
|
|
|
}
|
|
|
|
|
2021-04-07 23:14:42 +01:00
|
|
|
function mapDispatchToProps(dispatch: Dispatch): IndicatorDispatch {
|
2021-04-07 23:23:21 +01:00
|
|
|
return {
|
|
|
|
play: () => {
|
|
|
|
dispatch(togglePlay());
|
|
|
|
},
|
|
|
|
};
|
2020-03-27 22:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Indicator);
|