Skip to content

Commit

Permalink
fetching and checking for new waves compared to existing data
Browse files Browse the repository at this point in the history
  • Loading branch information
noumantahir committed Sep 27, 2023
1 parent 369fe36 commit 0880a64
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/providers/queries/postQueries/wavesQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,48 @@ export const useWavesQuery = (host: string) => {




const _data = unionBy(...wavesQueries.map((query) => query.data), 'url');

const _filteredData = useMemo(() =>
_data.filter(post => isArray(mutes) ? mutes.indexOf(post?.author) < 0 : true),
[mutes, _data])
_data.filter(post => isArray(mutes) ? mutes.indexOf(post?.author) < 0 : true),
[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 {
data: _filteredData,
isRefreshing,
isLoading: isLoading || wavesQueries.lastItem?.isLoading || wavesQueries.lastItem?.isFetching,
fetchNextPage: _fetchNextPage,
latestWavesFetch: _lastestWavesFetch,
refresh: _refresh,
};
};
Expand Down

0 comments on commit 0880a64

Please sign in to comment.