Merge pull request #962 from esteemapp/bugfix/feed-caching

Bugfix/feed caching
This commit is contained in:
uğur erdal 2019-07-23 19:43:39 +03:00 committed by GitHub
commit 22371282d5
3 changed files with 16 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import React, { PureComponent, Fragment } from 'react';
import { connect } from 'react-redux';
import get from 'lodash/get';
// Component
import PostsView from '../view/postsView';
@ -53,7 +54,9 @@ class PostsContainer extends PureComponent {
return (
<PostsView
handleOnScrollStart={this._handleOnScrollStart}
currentAccountUsername={currentAccount && currentAccount.username}
currentAccountUsername={
currentAccount && (get(currentAccount, 'username') || get(currentAccount, 'name'))
}
setFeedPosts={this._setFeedPosts}
feedPosts={feedPosts}
isConnected={isConnected}

View File

@ -22,7 +22,7 @@ class PostsView extends Component {
super(props);
this.state = {
posts: props.feedPosts,
posts: props.isConnected ? [] : props.feedPosts,
startAuthor: '',
startPermlink: '',
refreshing: false,
@ -178,7 +178,10 @@ class PostsView extends Component {
}
}
setFeedPosts(_posts);
if (posts.length < 5) {
setFeedPosts(_posts);
}
if (refreshing && newPosts.length > 0) {
this.setState({
posts: _posts,

View File

@ -1,3 +1,5 @@
import get from 'lodash/get';
import {
FETCH_ACCOUNT_FAIL,
FETCHING_ACCOUNT,
@ -45,7 +47,11 @@ export default function(state = initialState, action) {
case ADD_OTHER_ACCOUNT:
return {
...state,
otherAccounts: [...state.otherAccounts, action.payload],
otherAccounts: state.otherAccounts.some(
({ username }) => username === get(action.payload, 'username'),
)
? [...state.otherAccounts]
: [...state.otherAccounts, action.payload],
isFetching: false,
hasError: false,
errorMessage: null,