|
|
@@ -1,10 +1,10 @@
|
|
|
import { NavigationProp, useFocusEffect } from '@react-navigation/native';
|
|
|
-import React, { FC, useCallback, useEffect, useState } from 'react';
|
|
|
+import React, { FC, useCallback, useEffect, useRef, useState } from 'react';
|
|
|
import { ActivityIndicator, View } from 'react-native';
|
|
|
-import { Header, HorizontalTabView, Loading, PageWrapper, WarningModal } from 'src/components';
|
|
|
+import { Header, HorizontalTabView, Loading } from 'src/components';
|
|
|
|
|
|
import { Colors } from 'src/theme';
|
|
|
-import { FlashList } from '@shopify/flash-list';
|
|
|
+import { FlashList, FlashListRef } from '@shopify/flash-list';
|
|
|
import { StoreType, storage } from 'src/storage';
|
|
|
import { FilterButton, FilterModal } from '../../TravellersScreen/Components/FilterModal';
|
|
|
import { RankingDropdown } from '../../TravellersScreen/utils/types';
|
|
|
@@ -54,14 +54,26 @@ const MyFriendsScreen: FC<Props> = ({ navigation }) => {
|
|
|
{ key: 'received', title: 'Received requests' },
|
|
|
{ key: 'sent', title: 'Sent requests' }
|
|
|
];
|
|
|
- const [users, setUsers] = useState<{ [key in 'friends' | 'received' | 'sent']: any[] }>({
|
|
|
+ const [users, setUsers] = useState<{
|
|
|
+ friends: any[];
|
|
|
+ received: any[];
|
|
|
+ sent: any[];
|
|
|
+ friends_max: number;
|
|
|
+ received_max: number;
|
|
|
+ sent_max: number;
|
|
|
+ }>({
|
|
|
friends: [],
|
|
|
+ friends_max: 1,
|
|
|
received: [],
|
|
|
- sent: []
|
|
|
+ received_max: 1,
|
|
|
+ sent: [],
|
|
|
+ sent_max: 1
|
|
|
});
|
|
|
const { mutateAsync: updateFriendStatus } = usePostUpdateFriendStatusMutation();
|
|
|
const { mutateAsync: hideShowRequest } = usePostHideShowRequestMutation();
|
|
|
|
|
|
+ const flashListRef = useRef<FlashListRef<any> | null>(null);
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
if (filter.age || filter.ranking || filter.country) {
|
|
|
applySort();
|
|
|
@@ -69,7 +81,19 @@ const MyFriendsScreen: FC<Props> = ({ navigation }) => {
|
|
|
}, [filter]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
+ setPage(0);
|
|
|
+ const currentRouteKey = routes[index].key;
|
|
|
+ if (currentRouteKey === 'friends') {
|
|
|
+ setMaxPages(users.friends_max);
|
|
|
+ } else if (currentRouteKey === 'received') {
|
|
|
+ setMaxPages(users.received_max);
|
|
|
+ } else if (currentRouteKey === 'sent') {
|
|
|
+ setMaxPages(users.sent_max);
|
|
|
+ }
|
|
|
fetchUsers();
|
|
|
+ if (flashListRef && flashListRef.current) {
|
|
|
+ flashListRef.current?.scrollToOffset({ offset: 0, animated: false });
|
|
|
+ }
|
|
|
setFilter({
|
|
|
age: undefined,
|
|
|
ranking: undefined,
|
|
|
@@ -129,8 +153,11 @@ const MyFriendsScreen: FC<Props> = ({ navigation }) => {
|
|
|
onSuccess: (data) => {
|
|
|
setUsers({
|
|
|
friends: data.friends.users,
|
|
|
+ friends_max: data.friends.max_pages,
|
|
|
received: data.received.users,
|
|
|
- sent: data.sent.users
|
|
|
+ received_max: data.received.max_pages,
|
|
|
+ sent: data.sent.users,
|
|
|
+ sent_max: data.sent.max_pages
|
|
|
});
|
|
|
setMaxPages(data[routes[index].key].max_pages);
|
|
|
setMasterCountries(convertData(data[routes[index].key].countries) ?? []);
|
|
|
@@ -237,6 +264,7 @@ const MyFriendsScreen: FC<Props> = ({ navigation }) => {
|
|
|
renderScene={({ route }: { route: Routes }) => (
|
|
|
<>
|
|
|
<FlashList
|
|
|
+ ref={flashListRef}
|
|
|
viewabilityConfig={{
|
|
|
waitForInteraction: true,
|
|
|
itemVisiblePercentThreshold: 50,
|