Overlays.jsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, { Component } from "react";
  2. import PropTypes from "prop-types";
  3. import { connect } from "react-redux";
  4. import Settings from "./Settings";
  5. import Playlists from "./Playlists/index.jsx";
  6. import EditPlaylist from "./Playlists/EditPlaylist";
  7. import SearchYouTube from "./SearchYouTube/index.jsx";
  8. import QueueList from "./Queue/index.jsx";
  9. @connect(state => ({
  10. overlay1: state.stationOverlay.get("overlay1"),
  11. overlay2: state.stationOverlay.get("overlay2"),
  12. overlay3: state.stationOverlay.get("overlay3"),
  13. extraProps2: state.stationOverlay.get("extraProps2"),
  14. }))
  15. export default class Overlays extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. overlay1: null,
  20. overlay2: null,
  21. overlay3: null,
  22. };
  23. }
  24. getComponent = (type, key) => {
  25. let input = null;
  26. if (type === "settings") input = <Settings t={ this.props.t } key={ key }/>;
  27. else if (type === "playlists") input = <Playlists t={ this.props.t } key={ key }/>;
  28. else if (type === "editPlaylist") input = <EditPlaylist t={ this.props.t } key={ key } playlistId={ this.props.extraProps2.get("playlistId") }/>;
  29. else if (type === "searchYouTube") {
  30. if (this.state.overlay2) input = <SearchYouTube t={ this.props.t } order={ 3 } key={ key }/>;
  31. else input = <SearchYouTube t={ this.props.t } order={ 2 } key={ key }/>;
  32. }
  33. else if (type === "queueList") input = <QueueList t={ this.props.t } key={ key }/>;
  34. return input;
  35. };
  36. componentDidUpdate(prevProps, prevState) {
  37. if (this.props.overlay1 !== prevProps.overlay1) {
  38. this.setState({
  39. overlay1: this.getComponent(this.props.overlay1),
  40. });
  41. }
  42. if (this.props.overlay2 !== prevProps.overlay2) {
  43. this.setState({
  44. overlay2: this.getComponent(this.props.overlay2),
  45. });
  46. }
  47. if (this.props.overlay3 !== prevProps.overlay3) {
  48. this.setState({
  49. overlay3: this.getComponent(this.props.overlay3),
  50. });
  51. }
  52. }
  53. render() {
  54. return <div id="overlays">
  55. { this.state.overlay1 }
  56. { this.state.overlay2 }
  57. { this.state.overlay3 }
  58. </div>;
  59. }
  60. }