header.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React from "react"
  2. import { Link } from "react-router"
  3. import Button from "misago/components/button"
  4. import DropdownToggle from "misago/components/dropdown-toggle"
  5. import Nav from "misago/components/threads/nav"
  6. import ajax from "misago/services/ajax"
  7. import posting from "misago/services/posting"
  8. import snackbar from "misago/services/snackbar"
  9. import store from "misago/services/store"
  10. import misago from "misago"
  11. export default class extends React.Component {
  12. constructor(props) {
  13. super(props)
  14. this.state = {
  15. isBusy: false
  16. }
  17. }
  18. startThread = () => {
  19. posting.open(
  20. this.props.startThread || {
  21. mode: "START",
  22. config: misago.get("THREAD_EDITOR_API"),
  23. submit: misago.get("THREADS_API"),
  24. category: this.props.route.category.id
  25. }
  26. )
  27. }
  28. hasGoBackButton() {
  29. return !!this.props.route.category.parent
  30. }
  31. getGoBackButton() {
  32. if (!this.props.route.category.parent) return null
  33. const parent = this.props.categories[this.props.route.category.parent]
  34. return (
  35. <div className="hidden-xs col-sm-2 col-lg-1">
  36. <Link
  37. className="btn btn-default btn-icon btn-aligned btn-go-back btn-block btn-outline"
  38. to={parent.url.index + this.props.route.list.path}
  39. >
  40. <span className="material-icon">keyboard_arrow_left</span>
  41. </Link>
  42. </div>
  43. )
  44. }
  45. getStartThreadButton() {
  46. if (!this.props.user.id) return null
  47. return (
  48. <Button
  49. className="btn-primary btn-block btn-outline"
  50. onClick={this.startThread}
  51. disabled={this.props.disabled}
  52. >
  53. <span className="material-icon">chat</span>
  54. {gettext("Start thread")}
  55. </Button>
  56. )
  57. }
  58. render() {
  59. let headerClassName = "col-xs-12"
  60. if (this.hasGoBackButton()) {
  61. headerClassName += " col-sm-10 col-lg-11 sm-align-row-buttons"
  62. }
  63. const isAuthenticated = !!this.props.user.id
  64. return (
  65. <div className="page-header-bg">
  66. <div className="page-header">
  67. <div className="container">
  68. <div className="row">
  69. <div
  70. className={isAuthenticated ? "col-sm-9 col-md-10" : "col-xs-12"}
  71. >
  72. <div className="row">
  73. {this.getGoBackButton()}
  74. <div className={headerClassName}>
  75. <ParentCategory
  76. categories={this.props.categories}
  77. category={this.props.route.category.parent}
  78. />
  79. <h1>{this.props.title}</h1>
  80. </div>
  81. </div>
  82. </div>
  83. {isAuthenticated && (
  84. <div className="col-sm-3 col-md-2 xs-margin-top">
  85. {this.getStartThreadButton()}
  86. </div>
  87. )}
  88. </div>
  89. </div>
  90. <Nav
  91. baseUrl={this.props.route.category.url.index}
  92. list={this.props.route.list}
  93. lists={this.props.route.lists}
  94. />
  95. </div>
  96. </div>
  97. )
  98. }
  99. }
  100. export function ParentCategory({ categories, category }) {
  101. if (!category) return null
  102. const parent = categories[category]
  103. return (
  104. <Link className="go-back-sm visible-xs-block" to={parent.url.index}>
  105. <span className="material-icon">chevron_left</span>
  106. {parent.parent ? parent.name : gettext("Threads")}
  107. </Link>
  108. )
  109. }