StationCard.jsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import React, { Component } from "react";
  2. import { fallbackImage } from "constants.js";
  3. import { connect } from "react-redux";
  4. import { translate } from "react-i18next";
  5. @connect(state => ({
  6. user: {
  7. loggedIn: state.session.get("loggedIn"),
  8. userId: state.session.get("userId"),
  9. role: state.session.get("role"),
  10. },
  11. }))
  12. @translate(["home"], { wait: true })
  13. export default class StationCard extends Component {
  14. isOwner = () => {
  15. if (this.props.user.loggedIn) {
  16. if (this.props.user.role === "admin") return true;
  17. if (this.props.user.userId === this.props.station.get("stationOwner")) return true;
  18. }
  19. return false;
  20. };
  21. render() {
  22. const { station } = this.props;
  23. let icon = null;
  24. if (station.get("type") === "official") {
  25. if (station.get("privacy") !== "public") icon =
  26. <i className="material-icons" title={ this.props.t("home:thisStationIsNotVisible") }>lock</i>;
  27. } else {
  28. if (this.isOwner()) icon =
  29. <i className="material-icons" title={ this.props.t("home:thisIsYourStation") }>home</i>;
  30. if (station.get("privacy") !== "public") icon =
  31. <i className="material-icons" title={ this.props.t("home:thisStationIsNotVisible") }>lock</i>;
  32. }
  33. return (
  34. <div className="station-card">
  35. <div className="station-media">
  36. <img src={(station.get("currentSong")) ? station.getIn(["currentSong", "thumbnail"]) : ""} onError={function(e) {e.target.src=fallbackImage}}/>
  37. </div>
  38. <div className="station-body">
  39. <h3 className="displayName">{station.get("displayName")}</h3>
  40. <p className="description">{station.get("description")}</p>
  41. </div>
  42. <div className="station-footer">
  43. <div className="user-count" title={ this.props.t("home:howManyOtherUsers") }>
  44. <i className="material-icons">people</i>
  45. <span>{station.get("userCount")}</span>
  46. </div>
  47. { icon }
  48. </div>
  49. <a href={station.get("type") + "/" + station.get("name")}/>
  50. </div>
  51. );
  52. }
  53. }