mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-18 19:01:38 +03:00
realtine notification data aggregation
This commit is contained in:
parent
10a9895386
commit
ddfabc64f1
@ -5,7 +5,7 @@ import {
|
||||
useQueries,
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { useIntl } from 'react-intl';
|
||||
import { unionBy } from 'lodash';
|
||||
import bugsnapInstance from '../../config/bugsnag';
|
||||
@ -20,7 +20,6 @@ import QUERIES from './queryKeys';
|
||||
const FETCH_LIMIT = 20;
|
||||
|
||||
export const useNotificationsQuery = (filter: NotificationFilters) => {
|
||||
const [data, setData] = useState([]);
|
||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||
const [pageParams, setPageParams] = useState(['']);
|
||||
|
||||
@ -37,11 +36,6 @@ export const useNotificationsQuery = (filter: NotificationFilters) => {
|
||||
return lastId;
|
||||
};
|
||||
|
||||
const _onSuccess = () => {
|
||||
const dataArrs = notificationQueries.map((query) => query.data);
|
||||
const _data = unionBy(...dataArrs, 'id');
|
||||
setData(_data);
|
||||
};
|
||||
|
||||
// query initialization
|
||||
const notificationQueries = useQueries({
|
||||
@ -49,7 +43,6 @@ export const useNotificationsQuery = (filter: NotificationFilters) => {
|
||||
queryKey: [QUERIES.NOTIFICATIONS.GET, filter, pageParam],
|
||||
queryFn: () => _fetchNotifications(pageParam),
|
||||
initialData: [],
|
||||
onSuccess: _onSuccess,
|
||||
})),
|
||||
});
|
||||
|
||||
@ -74,8 +67,10 @@ export const useNotificationsQuery = (filter: NotificationFilters) => {
|
||||
}
|
||||
};
|
||||
|
||||
const _dataArrs = notificationQueries.map(query => query.data);
|
||||
|
||||
return {
|
||||
data,
|
||||
data: unionBy(..._dataArrs, 'id'),
|
||||
isRefreshing,
|
||||
isLoading: notificationQueries.lastItem.isLoading || notificationQueries.lastItem.isFetching,
|
||||
fetchNextPage: _fetchNextPage,
|
||||
|
Loading…
Reference in New Issue
Block a user