container.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React from 'react';
  2. import PageLead from 'misago/components/page-lead'; // jshint ignore:line
  3. import Toolbar from 'misago/components/threads/toolbar'; // jshint ignore:line
  4. export default class extends React.Component {
  5. getCategoryDescription() {
  6. if (this.props.route.category.description) {
  7. /* jshint ignore:start */
  8. return <div className="category-description">
  9. <PageLead copy={this.props.route.category.description.html} />
  10. </div>;
  11. /* jshint ignore:end */
  12. } else {
  13. return null;
  14. }
  15. }
  16. getToolbarLabel() {
  17. if (this.props.isLoaded) {
  18. let label = null;
  19. if (this.props.route.list.path) {
  20. label = ngettext(
  21. "%(threads)s thread found.",
  22. "%(threads)s threads found.",
  23. this.props.threadsCount);
  24. } else if (this.props.route.category.parent) {
  25. label = ngettext(
  26. "There is %(threads)s thread in this category.",
  27. "There are %(threads)s threads in this category.",
  28. this.props.threadsCount);
  29. } else {
  30. label = ngettext(
  31. "There is %(threads)s thread on our forums.",
  32. "There are %(threads)s threads on our forums.",
  33. this.props.threadsCount);
  34. }
  35. return interpolate(label, {
  36. threads: this.props.threadsCount
  37. }, true);
  38. } else {
  39. return gettext("Loading threads...");
  40. }
  41. }
  42. getDisableToolbar() {
  43. return !this.props.isLoaded || this.props.isBusy || this.props.busyThreads.length;
  44. }
  45. getToolbar() {
  46. if (this.props.subcategories.length || this.props.user.id) {
  47. /* jshint ignore:start */
  48. return <Toolbar subcategories={this.props.subcategories}
  49. categories={this.props.route.categories}
  50. categoriesMap={this.props.route.categoriesMap}
  51. list={this.props.route.list}
  52. threads={this.props.threads}
  53. moderation={this.props.moderation}
  54. selection={this.props.selection}
  55. selectAllThreads={this.props.selectAllThreads}
  56. selectNoneThreads={this.props.selectNoneThreads}
  57. addThreads={this.props.addThreads}
  58. freezeThread={this.props.freezeThread}
  59. deleteThread={this.props.deleteThread}
  60. updateThread={this.props.updateThread}
  61. route={this.props.route}
  62. disabled={this.getDisableToolbar()}
  63. user={this.props.user}>
  64. {this.getToolbarLabel()}
  65. </Toolbar>;
  66. /* jshint ignore:end */
  67. } else {
  68. return null;
  69. }
  70. }
  71. render() {
  72. /* jshint ignore:start */
  73. return <div className="container">
  74. {this.getCategoryDescription()}
  75. {this.getToolbar()}
  76. {this.props.children}
  77. </div>;
  78. /* jshint ignore:end */
  79. }
  80. }