Skip to content

Commit

Permalink
empty result fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
teseo committed Jul 6, 2016
1 parent 4f788a6 commit 5acbba7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
25 changes: 20 additions & 5 deletions components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default class Main extends Component {
this.state = {
articles: dataSource,
loaderImage:false,
dataSetEmpty: false,
offset: 1
}

Expand Down Expand Up @@ -74,9 +75,15 @@ export default class Main extends Component {
loaderImage:!this.state.loaderImage
});
}
toggleEmptyResult ( value ) {
this.setState({
dataSetEmpty: value
});
}
render() {

const { articles } = this.state;

const loaderImage = require('../assets/loading.gif');
const loadMore = require('../assets/plus-button.gif');

Expand All @@ -91,11 +98,13 @@ export default class Main extends Component {
style={ styles.loaderImage }/>
)}


<ListView dataSource={ articles }
style={ styles.listItem }
renderRow={ this.renderRow } ref="listView"/>

{renderIf(this.state.dataSetEmpty)(
<Text style={ styles.emptyResult }> Empty Result </Text>
)}
<ListView dataSource={ articles }
style={ styles.listItem }
enableEmptySections={true}
renderRow={ this.renderRow } ref="listView"/>
</View>
);
}
Expand All @@ -111,6 +120,9 @@ export default class Main extends Component {
});
}).then(() => {
this.toggleImageLoader();
var emptyValue = this.state.articles._cachedRowCount == 0
? true : false;
this.toggleEmptyResult(emptyValue);
})
.catch((error) => {
throw error;
Expand Down Expand Up @@ -150,4 +162,7 @@ export default class Main extends Component {
width:15,
height:15
},
emptyResult: {
marginTop: 10
}
});
1 change: 0 additions & 1 deletion components/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default class Root extends Component {
{
return <Main navigator={ navigator }/>;
}
console.log(route);
return <Article articleData = {route}/>;
};

Expand Down
2 changes: 1 addition & 1 deletion utils/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function get(url){

export default function searchFor(query, offset){
const requestUrl = (
`http://content.guardianapis.com/search?show-elements=all&show-blocks=body&show-fields=lastModified,byline,headline,trailText,thumbnail,body&page-size=20&page=${ offset }&q=${ query }&type=article&api-key=4f508039-f7af-4b2e-838b-4766794a86ea&order-by=newest`
`http://content.guardianapis.com/search?show-elements=all&show-blocks=body&show-fields=lastModified,byline,headline,trailText,thumbnail,body&page-size=20&page=${ offset }&q=${ query }&type=article&api-key=api-key&order-by=newest`
);

return get(requestUrl)
Expand Down

0 comments on commit 5acbba7

Please sign in to comment.