Defer profile favourites until needed
This commit is contained in:
@@ -16,6 +16,7 @@ import TabWorlds from '../../components/profile/tabs/TabWorlds'
|
||||
import TabFollowers from '../../components/profile/tabs/TabFollowers'
|
||||
import GroupProfileSummary from '../../components/groups/GroupProfileSummary'
|
||||
import useLazyProfileFeaturedArtworks from '../../lib/useLazyProfileFeaturedArtworks'
|
||||
import useLazyProfileFavourites from '../../lib/useLazyProfileFavourites'
|
||||
|
||||
const VALID_TABS = ['posts', 'artworks', 'stories', 'achievements', 'worlds', 'collections', 'about', 'stats', 'favourites', 'activity', 'followers']
|
||||
|
||||
@@ -92,6 +93,11 @@ export default function ProfileShow() {
|
||||
initialFeaturedArtworks: featuredArtworks,
|
||||
enabled: activeTab === 'artworks',
|
||||
})
|
||||
const favouritesState = useLazyProfileFavourites({
|
||||
username: user?.username || user?.name || '',
|
||||
initialFavourites: favourites,
|
||||
enabled: activeTab === 'favourites',
|
||||
})
|
||||
|
||||
const handleTabChange = useCallback((tab) => {
|
||||
if (!VALID_TABS.includes(tab)) return
|
||||
@@ -133,10 +139,8 @@ export default function ProfileShow() {
|
||||
? artworks
|
||||
: (artworks?.data ?? [])
|
||||
const artworkNextCursor = artworks?.next_cursor ?? null
|
||||
const favouriteList = Array.isArray(favourites)
|
||||
? favourites
|
||||
: (favourites?.data ?? [])
|
||||
const favouriteNextCursor = favourites?.next_cursor ?? null
|
||||
const favouriteList = favouritesState.items
|
||||
const favouriteNextCursor = favouritesState.nextCursor
|
||||
|
||||
// Normalise social links (may be object keyed by platform, or array)
|
||||
const socialLinksObj = Array.isArray(socialLinks)
|
||||
@@ -281,6 +285,9 @@ export default function ProfileShow() {
|
||||
favourites={{ data: favouriteList, next_cursor: favouriteNextCursor }}
|
||||
isOwner={isOwner}
|
||||
username={user.username || user.name}
|
||||
loading={favouritesState.loading}
|
||||
error={favouritesState.error}
|
||||
onRetry={favouritesState.retry}
|
||||
/>
|
||||
)}
|
||||
{activeTab === 'activity' && (
|
||||
|
||||
Reference in New Issue
Block a user