@@ -2,6 +2,7 @@ import {debug} from 'common/logger'
22import { Profile } from 'common/profiles/profile'
33import { removeNullOrUndefinedProps } from 'common/util/object'
44import { DAY_MS } from 'common/util/time'
5+ import { isEqual } from 'lodash'
56import { useRouter } from 'next/router'
67import { useCallback , useEffect , useRef , useState } from 'react'
78import toast from 'react-hot-toast'
@@ -51,6 +52,10 @@ export function ProfilesHome() {
5152 undefined ,
5253 'profiles' ,
5354 )
55+ const [ getProfilesArgs , setGetProfilesArgs ] = usePersistentInMemoryState < any > (
56+ undefined ,
57+ 'get-profiles-args' ,
58+ )
5459 const [ profileCount , setProfileCount ] = usePersistentInMemoryState < number | undefined > (
5560 undefined ,
5661 'profile-count' ,
@@ -96,19 +101,23 @@ export function ProfilesHome() {
96101 setProfileCount ( 0 )
97102 return
98103 }
99- setIsReloading ( true )
100- const current = ++ id . current
101104 const args = removeNullOrUndefinedProps ( {
102105 limit : 20 ,
103106 compatibleWithUserId : user ?. id ,
104107 locale,
105108 ...filters ,
106109 } )
107- debug ( 'Refreshing profiles, filters:' , args )
110+ if ( ! ! profiles ?. length && isEqual ( getProfilesArgs , args ) ) {
111+ return
112+ }
113+ setIsReloading ( true )
114+ const current = ++ id . current
115+ debug ( 'Refreshing profiles. Filters:' , args )
108116 api ( 'get-profiles' , args as any )
109117 . then ( ( { profiles, count} ) => {
110118 if ( current === id . current ) {
111119 setProfiles ( profiles )
120+ setGetProfilesArgs ( args )
112121 setProfileCount ( count )
113122 }
114123 } )
@@ -134,6 +143,7 @@ export function ProfilesHome() {
134143 return false
135144 }
136145 if ( ! profiles || isLoadingMore ) return false
146+ debug ( 'Loading more profiles. Current:' , profiles . length )
137147 if ( fromSignup && isClearedFilters && sendScrollWarning ) {
138148 setSendScrollWarning ( false )
139149 toast (
0 commit comments