root.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import moment from 'moment';
  2. import React from 'react';
  3. import Category from 'misago/components/categories/category'; // jshint ignore:line
  4. import misago from 'misago/index';
  5. import polls from 'misago/services/polls';
  6. let hydrate = function(category) {
  7. return Object.assign({}, category, {
  8. last_post_on: category.last_post_on ? moment(category.last_post_on) : null,
  9. subcategories: category.subcategories.map(hydrate)
  10. });
  11. };
  12. export default class extends React.Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. categories: misago.get('CATEGORIES').map(hydrate)
  17. };
  18. this.startPolling(misago.get('CATEGORIES_API'));
  19. }
  20. startPolling(api) {
  21. polls.start({
  22. poll: 'categories',
  23. url: api,
  24. frequency: 180 * 1000,
  25. update: this.update
  26. });
  27. }
  28. /* jshint ignore:start */
  29. update = (data) => {
  30. this.setState({
  31. categories: data.map(hydrate)
  32. });
  33. };
  34. /* jshint ignore:end */
  35. render() {
  36. /* jshint ignore:start */
  37. return <div className="categories-list">
  38. {this.state.categories.map(function(category) {
  39. return <Category category={category} key={category.id} />;
  40. })}
  41. </div>;
  42. /* jshint ignore:end */
  43. }
  44. }
  45. export function select(store) {
  46. return {
  47. 'tick': store.tick.tick,
  48. };
  49. }