forked from tanner/qotnews
		
	order feed by reverse chronological
This commit is contained in:
		@@ -22,18 +22,23 @@ class Feed extends React.Component {
 | 
				
			|||||||
					const updated = !this.state.stories || this.state.stories[0].id !== result.stories[0].id;
 | 
										const updated = !this.state.stories || this.state.stories[0].id !== result.stories[0].id;
 | 
				
			||||||
					console.log('updated:', updated);
 | 
										console.log('updated:', updated);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					this.setState({ stories: result.stories });
 | 
										const { stories } = result;
 | 
				
			||||||
					localStorage.setItem('stories', JSON.stringify(result.stories));
 | 
										if (stories) {
 | 
				
			||||||
 | 
											stories.sort((a, b) => b.date - a.date);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										this.setState({ stories });
 | 
				
			||||||
 | 
										localStorage.setItem('stories', JSON.stringify(stories));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if (updated) {
 | 
										if (updated) {
 | 
				
			||||||
						localForage.clear();
 | 
											localForage.clear();
 | 
				
			||||||
						result.stories.forEach((x, i) => {
 | 
											stories.forEach((x, i) => {
 | 
				
			||||||
							fetch('/api/' + x.id)
 | 
												fetch('/api/' + x.id)
 | 
				
			||||||
								.then(res => res.json())
 | 
													.then(res => res.json())
 | 
				
			||||||
								.then(result => {
 | 
													.then(({ story }) => {
 | 
				
			||||||
									localForage.setItem(x.id, result.story)
 | 
														localForage.setItem(x.id, story)
 | 
				
			||||||
										.then(console.log('preloaded', x.id, x.title));
 | 
															.then(console.log('preloaded', x.id, x.title));
 | 
				
			||||||
									this.props.updateCache(x.id, result.story);
 | 
														this.props.updateCache(x.id, story);
 | 
				
			||||||
								}, error => { }
 | 
													}, error => { }
 | 
				
			||||||
								);
 | 
													);
 | 
				
			||||||
						});
 | 
											});
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user