mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-28 01:52:56 +03:00
fetching and checking for new waves compared to existing data
This reverts commit 6a74fd7c34
.
This commit is contained in:
parent
6a74fd7c34
commit
d48a334887
@ -221,17 +221,48 @@ export const useWavesQuery = (host: string) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const _data = unionBy(...wavesQueries.map((query) => query.data), 'url');
|
const _data = unionBy(...wavesQueries.map((query) => query.data), 'url');
|
||||||
|
|
||||||
const _filteredData = useMemo(() =>
|
const _filteredData = useMemo(() =>
|
||||||
_data.filter(post => isArray(mutes) ? mutes.indexOf(post?.author) < 0 : true),
|
_data.filter(post => isArray(mutes) ? mutes.indexOf(post?.author) < 0 : true),
|
||||||
[mutes, _data])
|
[mutes, _data])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const _lastestWavesFetch = async () => {
|
||||||
|
|
||||||
|
const _prevLatestWave = _filteredData[0]
|
||||||
|
|
||||||
|
await _fetchPermlinks('', true);
|
||||||
|
const queryResponse = await wavesQueries[0].refetch();
|
||||||
|
|
||||||
|
const _newData:any[] = queryResponse.data || [];
|
||||||
|
|
||||||
|
//check if new waves are available
|
||||||
|
const _lastIndex = _newData?.findIndex(item =>
|
||||||
|
( item.author + item.permlink === _prevLatestWave.author + _prevLatestWave.permlink));
|
||||||
|
|
||||||
|
let _newWaves:any[] = []
|
||||||
|
if (_lastIndex && _lastIndex !== 0) {
|
||||||
|
if (_lastIndex < 0) {
|
||||||
|
_newWaves = _newData?.splice(0, 5) || [];
|
||||||
|
} else {
|
||||||
|
_newWaves = _newData?.splice(0, _lastIndex) || [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _newWaves
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: _filteredData,
|
data: _filteredData,
|
||||||
isRefreshing,
|
isRefreshing,
|
||||||
isLoading: isLoading || wavesQueries.lastItem?.isLoading || wavesQueries.lastItem?.isFetching,
|
isLoading: isLoading || wavesQueries.lastItem?.isLoading || wavesQueries.lastItem?.isFetching,
|
||||||
fetchNextPage: _fetchNextPage,
|
fetchNextPage: _fetchNextPage,
|
||||||
|
latestWavesFetch: _lastestWavesFetch,
|
||||||
refresh: _refresh,
|
refresh: _refresh,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user