mirror of
				https://github.com/Alamantus/Lexiconga.git
				synced 2025-11-04 10:17:01 +01:00 
			
		
		
		
	Add lazyloading and Ad component
This commit is contained in:
		
							parent
							
								
									e51e906785
								
							
						
					
					
						commit
						0ae6d76b82
					
				
					 6 changed files with 560 additions and 202 deletions
				
			
		| 
						 | 
					@ -30,6 +30,7 @@
 | 
				
			||||||
    "express": "^4.15.2",
 | 
					    "express": "^4.15.2",
 | 
				
			||||||
    "file-loader": "^0.11.2",
 | 
					    "file-loader": "^0.11.2",
 | 
				
			||||||
    "html-loader": "^0.4.5",
 | 
					    "html-loader": "^0.4.5",
 | 
				
			||||||
 | 
					    "inferno-create-element": "^3.9.0",
 | 
				
			||||||
    "node-sass": "^4.5.3",
 | 
					    "node-sass": "^4.5.3",
 | 
				
			||||||
    "raw-loader": "^0.5.1",
 | 
					    "raw-loader": "^0.5.1",
 | 
				
			||||||
    "sass-loader": "^6.0.6",
 | 
					    "sass-loader": "^6.0.6",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,7 +33,8 @@ export const MainDisplay = ({ dictionaryInfo, wordsToDisplay, updateDisplay, upd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <WordsList
 | 
					            <WordsList
 | 
				
			||||||
              lastRender={ lastRender }
 | 
					              lastRender={ lastRender }
 | 
				
			||||||
              words={ wordsToDisplay } />
 | 
					              words={ wordsToDisplay }
 | 
				
			||||||
 | 
					              adsEveryXWords={ 10 } />
 | 
				
			||||||
          </RightColumn>
 | 
					          </RightColumn>
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										26
									
								
								src/components/display/Ad.jsx
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/components/display/Ad.jsx
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,26 @@
 | 
				
			||||||
 | 
					import Inferno from 'inferno';
 | 
				
			||||||
 | 
					import Component from 'inferno-component';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export class Ad extends Component {
 | 
				
			||||||
 | 
					  constructor (props) {
 | 
				
			||||||
 | 
					    super(props);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  componentDidMount() {
 | 
				
			||||||
 | 
					    // Insert ad initialization here
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  render () {
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					      <div className='notification'>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <div className='content'>
 | 
				
			||||||
 | 
					          Want a feature-packed tool for building your conlang with an active community and inter-linked word definitions?
 | 
				
			||||||
 | 
					          <br />
 | 
				
			||||||
 | 
					          Check out <a href='http://conworkshop.info/' target='_blank'>ConWorkShop</a>!
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -2,21 +2,44 @@ import Inferno from 'inferno';
 | 
				
			||||||
import Component from 'inferno-component';
 | 
					import Component from 'inferno-component';
 | 
				
			||||||
import marked from 'marked';
 | 
					import marked from 'marked';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// npm lazyload-inferno-component uses outdated inferno dependencies, so just using the script.
 | 
				
			||||||
 | 
					import LazyLoader from '../../../vendor/LGabAnnell/lazyload-inferno-component/lazyload-component';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import idManager from '../../managers/IDManager';
 | 
					import idManager from '../../managers/IDManager';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { WordDisplay } from './WordDisplay';
 | 
					import { WordDisplay } from './WordDisplay';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const loadAd = (callback, { props, router }) => {
 | 
				
			||||||
 | 
					  require.ensure([], (require) => {
 | 
				
			||||||
 | 
					    const component = require("./Ad").Ad;
 | 
				
			||||||
 | 
					    callback(component);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class WordsList extends Component {
 | 
					export class WordsList extends Component {
 | 
				
			||||||
  constructor (props) {
 | 
					  constructor (props) {
 | 
				
			||||||
    super(props);
 | 
					    super(props);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  render () {
 | 
					  render () {
 | 
				
			||||||
 | 
					    const adsEveryXWords = this.props.adsEveryXWords || 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <div className='box'>
 | 
					      <div className='box'>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        {this.props.words
 | 
					        {this.props.words
 | 
				
			||||||
          && this.props.words.map(word => {
 | 
					          && this.props.words.map((word, index) => {
 | 
				
			||||||
 | 
					            if (index % adsEveryXWords == 0) {
 | 
				
			||||||
 | 
					              return (
 | 
				
			||||||
 | 
					                <div>
 | 
				
			||||||
 | 
					                  <LazyLoader lazyLoad={ loadAd } />
 | 
				
			||||||
 | 
					                  
 | 
				
			||||||
 | 
					                  <WordDisplay key={ `word_${word.id}` }
 | 
				
			||||||
 | 
					                    word={ word } />
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					              );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return (
 | 
					            return (
 | 
				
			||||||
              <WordDisplay key={ `word_${word.id}` }
 | 
					              <WordDisplay key={ `word_${word.id}` }
 | 
				
			||||||
                word={ word } />
 | 
					                word={ word } />
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										60
									
								
								vendor/LGabAnnell/lazyload-inferno-component/lazyload-component.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								vendor/LGabAnnell/lazyload-inferno-component/lazyload-component.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,60 @@
 | 
				
			||||||
 | 
					"use strict";
 | 
				
			||||||
 | 
					var __extends = (this && this.__extends) || (function () {
 | 
				
			||||||
 | 
					    var extendStatics = Object.setPrototypeOf ||
 | 
				
			||||||
 | 
					        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
 | 
				
			||||||
 | 
					        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
 | 
				
			||||||
 | 
					    return function (d, b) {
 | 
				
			||||||
 | 
					        extendStatics(d, b);
 | 
				
			||||||
 | 
					        function __() { this.constructor = d; }
 | 
				
			||||||
 | 
					        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					})();
 | 
				
			||||||
 | 
					Object.defineProperty(exports, "__esModule", { value: true });
 | 
				
			||||||
 | 
					var inferno_create_element_1 = require("inferno-create-element");
 | 
				
			||||||
 | 
					var inferno_component_1 = require("inferno-component");
 | 
				
			||||||
 | 
					/** @internal
 | 
				
			||||||
 | 
					    * Function pretty much copied from infernojs - Route.ts
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					function rest(object, excluded) {
 | 
				
			||||||
 | 
					    var t = {};
 | 
				
			||||||
 | 
					    for (var p in object) {
 | 
				
			||||||
 | 
					        if (excluded.indexOf(p) < 0) {
 | 
				
			||||||
 | 
					            t[p] = object[p];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return t;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					var LazyLoader = /** @class */ (function (_super) {
 | 
				
			||||||
 | 
					    __extends(LazyLoader, _super);
 | 
				
			||||||
 | 
					    function LazyLoader(props, context) {
 | 
				
			||||||
 | 
					        var _this = _super.call(this, props, context) || this;
 | 
				
			||||||
 | 
					        _this.state = {
 | 
				
			||||||
 | 
					            child: null
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        _this.context = context;
 | 
				
			||||||
 | 
					        _this.lazyLoad = props.lazyLoad;
 | 
				
			||||||
 | 
					        _this.children = props.children;
 | 
				
			||||||
 | 
					        _this.loadComponent = _this.loadComponent.bind(_this);
 | 
				
			||||||
 | 
					        return _this;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    LazyLoader.prototype.loadComponent = function (componentName, props) {
 | 
				
			||||||
 | 
					        var finalProps;
 | 
				
			||||||
 | 
					        if (!props) {
 | 
				
			||||||
 | 
					            finalProps = rest(this.props, ["lazyLoad", "children"]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            finalProps = Object.assign({}, props, rest(this.props, ["lazyLoad", "children"]));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        this.setState({
 | 
				
			||||||
 | 
					            child: inferno_create_element_1.default(componentName, finalProps, this.children)
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    LazyLoader.prototype.componentWillMount = function () {
 | 
				
			||||||
 | 
					        this.lazyLoad(this.loadComponent, { props: this.props, router: this.context.router });
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    LazyLoader.prototype.render = function () {
 | 
				
			||||||
 | 
					        return this.state.child ? this.state.child : null;
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    return LazyLoader;
 | 
				
			||||||
 | 
					}(inferno_component_1.default));
 | 
				
			||||||
 | 
					exports.default = LazyLoader;
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue