Use skeleton states for refetch on focus

This commit is contained in:
Eric Bailey
2025-04-07 10:38:39 -05:00
parent 67c79dd8ba
commit b25aa7eda8
3 changed files with 16 additions and 7 deletions
+13 -4
View File
@@ -197,11 +197,12 @@ export function Explore({
const gate = useGate() const gate = useGate()
const guide = useProgressGuide('follow-10') const guide = useProgressGuide('follow-10')
const [selectedInterest, setSelectedInterest] = useState<string | null>(null) const [selectedInterest, setSelectedInterest] = useState<string | null>(null)
// TODO always get at least 10 back // TODO always get at least 10 back TODO still
const { const {
data: suggestedUsers, data: suggestedUsers,
isLoading: suggestedUsersIsLoading, isLoading: suggestedUsersIsLoading,
error: suggestedUsersError, error: suggestedUsersError,
isRefetching: suggestedUsersIsRefetching,
} = useGetSuggestedUsersQuery({ } = useGetSuggestedUsersQuery({
category: selectedInterest, category: selectedInterest,
}) })
@@ -221,6 +222,7 @@ export function Explore({
data: suggestedSPs, data: suggestedSPs,
isLoading: isLoadingSuggestedSPs, isLoading: isLoadingSuggestedSPs,
error: suggestedSPsError, error: suggestedSPsError,
isRefetching: isRefetchingSuggestedSPs,
} = useSuggestedStarterPacksQuery() } = useSuggestedStarterPacksQuery()
const isLoadingMoreFeeds = isFetchingNextFeedsPage && !isLoadingFeeds const isLoadingMoreFeeds = isFetchingNextFeedsPage && !isLoadingFeeds
@@ -299,7 +301,7 @@ export function Explore({
}, },
}) })
if (suggestedUsersIsLoading) { if (suggestedUsersIsLoading || suggestedUsersIsRefetching) {
i.push({type: 'profilePlaceholder', key: 'profilePlaceholder'}) i.push({type: 'profilePlaceholder', key: 'profilePlaceholder'})
} else if (suggestedUsersError) { } else if (suggestedUsersError) {
i.push({ i.push({
@@ -346,6 +348,7 @@ export function Explore({
moderationOpts, moderationOpts,
suggestedUsers, suggestedUsers,
suggestedUsersIsLoading, suggestedUsersIsLoading,
suggestedUsersIsRefetching,
suggestedUsersError, suggestedUsersError,
]) ])
const suggestedFeedsModule = useMemo(() => { const suggestedFeedsModule = useMemo(() => {
@@ -460,7 +463,7 @@ export function Explore({
iconSize: 'xl', iconSize: 'xl',
}) })
if (isLoadingSuggestedSPs) { if (isLoadingSuggestedSPs || isRefetchingSuggestedSPs) {
Array.from({length: 3}).forEach((__, index) => Array.from({length: 3}).forEach((__, index) =>
i.push({ i.push({
type: 'starterPackSkeleton', type: 'starterPackSkeleton',
@@ -480,7 +483,13 @@ export function Explore({
}) })
} }
return i return i
}, [suggestedSPs, _, isLoadingSuggestedSPs, suggestedSPsError]) }, [
suggestedSPs,
_,
isLoadingSuggestedSPs,
suggestedSPsError,
isRefetchingSuggestedSPs,
])
const feedPreviewsModule = useMemo(() => { const feedPreviewsModule = useMemo(() => {
const i: ExploreScreenItems[] = [] const i: ExploreScreenItems[] = []
i.push(...feedPreviewSlices) i.push(...feedPreviewSlices)
@@ -29,10 +29,10 @@ export function ExploreTrendingTopics() {
} }
function Inner() { function Inner() {
const {data: trending, error, isLoading} = useGetTrendsQuery() const {data: trending, error, isLoading, isRefetching} = useGetTrendsQuery()
const noTopics = !isLoading && !error && !trending?.trends?.length const noTopics = !isLoading && !error && !trending?.trends?.length
return isLoading ? ( return isLoading || isRefetching ? (
Array.from({length: TOPIC_COUNT}).map((__, i) => ( Array.from({length: TOPIC_COUNT}).map((__, i) => (
<TrendingTopicRowSkeleton key={i} withPosts={i === 0} /> <TrendingTopicRowSkeleton key={i} withPosts={i === 0} />
)) ))
@@ -26,7 +26,7 @@ export function useGetTrendsQuery() {
return useQuery({ return useQuery({
enabled: !!preferences, enabled: !!preferences,
refetchOnWindowFocus: true, refetchOnWindowFocus: true,
staleTime: STALE.MINUTES.THREE, staleTime: STALE.MINUTES.ONE,
queryKey: createGetTrendsQueryKey(), queryKey: createGetTrendsQueryKey(),
queryFn: async () => { queryFn: async () => {
const contentLangs = getContentLanguages().join(',') const contentLangs = getContentLanguages().join(',')