This repository has been archived on 2022-09-16. You can view files and clone it, but cannot push or open issues/pull-requests.
tlaternet-templates/src/music/components/indicator.tsx

70 lines
1.6 KiB
TypeScript
Raw Normal View History

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";
type IndicatorProps = {
2021-04-07 23:23:21 +01:00
muted: boolean;
playing: boolean;
};
type IndicatorDispatch = {
2021-04-07 23:23:21 +01:00
play: () => void;
};
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();
};
}
function mapStateToProps(state: State): IndicatorProps {
2021-04-07 23:23:21 +01:00
return {
muted: state.musicState.muted,
playing: state.musicState.playing,
};
}
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());
},
};
}
export default connect(mapStateToProps, mapDispatchToProps)(Indicator);