From 34b17ac3b1e0fcfa1d6c021efbd25a0d3258f788 Mon Sep 17 00:00:00 2001 From: lczaplinski Date: Tue, 11 Apr 2017 20:17:02 +0200 Subject: [PATCH] Read more events via cursor --- actions/handlers/index.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/actions/handlers/index.go b/actions/handlers/index.go index 99b66c0..8c2ebd4 100644 --- a/actions/handlers/index.go +++ b/actions/handlers/index.go @@ -49,26 +49,46 @@ const index = ` class Stream extends React.Component { constructor(props) { super(props); - this.name = props.match.params.name; + this.updateProps(props); this.state = { "results": [] }; } - componentDidMount() { - $.getJSON('/stream/' + this.name, (data) => { + componentWillReceiveProps(props) { + this.updateProps(props); + this.fetchData(); + } + + updateProps(props) { + this.name = props.match.params.name; + this.cursor = props.match.params.cursor || ''; + } + + fetchData() { + $.getJSON('/stream/' + this.name + "?cursor=" + this.cursor, (data) => { this.setState(data); }); } + componentDidMount() { + this.fetchData(); + } + render() { let items = this.state.results.map((result, index) =>
  • {JSON.stringify(result)}
  • ); + let more = ''; + let cursor = this.state.cursor && this.state.cursor.next; + if (cursor) { + more = More; + } return(

    {this.name}

      {items}
    + { more }
    ); } @@ -95,7 +115,8 @@ const index = `
    - + +
    , document.getElementById('app')