pluginlist.jsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. var Preact = require('preact'),
  2. h = require('preact').h,
  3. createClass = require('preact-compat').createClass,
  4. Plugin = require('./plugin.jsx');
  5. var InitialPageLength = 10;
  6. var PageExtensionLength = 20;
  7. /*
  8. States site loaded
  9. */
  10. var PluginList = createClass({
  11. getInitialState: function() {
  12. return { bootstrapped: false }
  13. },
  14. componentWillReceiveProps: function() {
  15. // Recieving a set of plugins
  16. this.setState({
  17. bootstrapped: true,
  18. searchPage: 0
  19. });
  20. },
  21. increaseSearchResults: function() {
  22. this.setState({ searchPage: this.state.searchPage + 1 });
  23. },
  24. render: function() {
  25. if (!this.state.bootstrapped) {
  26. var emptyPluginList = [];
  27. for (var i = 0; i < InitialPageLength; i++) {
  28. emptyPluginList.push(<Plugin key={i}/>)
  29. };
  30. return (
  31. <div className="container plugins-results-container">
  32. {emptyPluginList}
  33. </div>
  34. )
  35. } else {
  36. var plugins = this.props.plugins;
  37. var showMore = null, visiblePlugins = [];
  38. if (plugins.length - this.state.searchPage * PageExtensionLength > InitialPageLength) {
  39. showMore =
  40. <div className="plugin-results-show-more btn-block btn-primary" onClick={this.increaseSearchResults}>
  41. Show More
  42. </div>;
  43. }
  44. if (plugins.length === 0) {
  45. return (
  46. <div className="container plugins-results-container">
  47. No plugins found. Learn how to <a href="{{ site.baseurl }}/docs/en/{{ site.default_linked_docs_version }}/guide/hybrid/plugins/index.html">create one</a>
  48. </div>
  49. );
  50. } else {
  51. for (var i = 0; i < InitialPageLength + this.state.searchPage * PageExtensionLength; i++) {
  52. if (plugins[i]) {
  53. visiblePlugins.push(<Plugin plugin={plugins[i]} key={i} flashEnabled={this.props.flashEnabled}/>);
  54. } else {
  55. break;
  56. }
  57. };
  58. return (
  59. <div className="container plugins-results-container">
  60. {visiblePlugins}
  61. {showMore}
  62. </div>
  63. );
  64. }
  65. }
  66. }
  67. });
  68. module.exports = PluginList;