Skip to content

Commit a108590

Browse files
committed
Do not refresh profiles grid when going back to it without any filter change
1 parent 697252e commit a108590

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

backend/api/src/get-profiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ export const loadProfiles = async (props: profileQueryType) => {
675675

676676
const profiles = await pg.map(query, [], convertRow)
677677

678-
console.debug('profiles:', profiles)
678+
// console.debug('profiles:', profiles)
679679

680680
const countQuery = renderSql(select(`count(*) as count`), ...tableSelection, ...filters)
681681

web/components/profiles/profiles-home.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {debug} from 'common/logger'
22
import {Profile} from 'common/profiles/profile'
33
import {removeNullOrUndefinedProps} from 'common/util/object'
44
import {DAY_MS} from 'common/util/time'
5+
import {isEqual} from 'lodash'
56
import {useRouter} from 'next/router'
67
import {useCallback, useEffect, useRef, useState} from 'react'
78
import 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

Comments
 (0)