2
0

StationCard.jsx 1.8 KB

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