mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
18 lines
630 B
JavaScript
18 lines
630 B
JavaScript
import unionBy from 'lodash/unionBy'
|
|
|
|
export default function UpdateQuery(component, { $state, pageKey }) {
|
|
if (!pageKey) throw new Error('No key given for the graphql query { data } object')
|
|
return (previousResult, { fetchMoreResult }) => {
|
|
const oldData = (previousResult && previousResult[pageKey]) || []
|
|
const newData = (fetchMoreResult && fetchMoreResult[pageKey]) || []
|
|
if (newData.length < component.pageSize) {
|
|
component.hasMore = false
|
|
$state.complete()
|
|
}
|
|
const result = {}
|
|
result[pageKey] = unionBy(oldData, newData, (item) => item.id)
|
|
$state.loaded()
|
|
return result
|
|
}
|
|
}
|