Skip to content

Commit

Permalink
Improve loading speed
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Mar 19, 2024
1 parent a972cbf commit a496cf1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/components/auth/MyAccountsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export function MyAccountsProvider(props: React.PropsWithChildren<{}>) {
const reloadAccountIdsByFollower = useCreateReloadAccountIdsByFollower()
const reloadSpaceIdsRelatedToAccount = useCreateReloadSpaceIdsRelatedToAccount()
const address = useMyAddress()
const isInitialized = useMyAccount(state => state.isInitialized)
const { getAllEmailAccounts } = useEmailAccount()
const [, recheck] = useReducer(x => (x + 1) % 16384, 0)
const isMobile = useIsMobileWidthOrDevice()
Expand Down Expand Up @@ -165,6 +166,7 @@ export function MyAccountsProvider(props: React.PropsWithChildren<{}>) {
[address],
)
useEffect(() => {
if (!isInitialized || !address) return
dispatch(
fetchEntityOfSpaceIdsByFollower({
id: address,
Expand All @@ -176,7 +178,7 @@ export function MyAccountsProvider(props: React.PropsWithChildren<{}>) {
fetchProfileSpace({ id: address, api: getSubsocialApi(), dataSource: DataSourceTypes.SQUID }),
)
dispatch(fetchAddressLikeCounts({ address, postIds: null }))
}, [address])
}, [address, isInitialized])

const state = useMemo(
() => ({ accounts, status, emailAccounts }),
Expand Down
6 changes: 3 additions & 3 deletions src/components/main/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,20 @@ const TabsHomePage = ({
setFiltersInUrl(router, key, filterType, { ref: refId })
}

const isInitializedProxy = useMyAccount(state => state.isInitializedProxy)
const isInitialized = useMyAccount(state => state.isInitialized)
const followedIds = useAppSelector(state => {
return selectSpaceIdsByFollower(state, myAddress)
})

const isLoadingFollowedIds = followedIds === undefined
useEffect(() => {
if (!isInitializedProxy || !isSignedIn || isLoadingFollowedIds) return
if (!isInitialized || !isSignedIn || isLoadingFollowedIds) return
if (followedIds.length === 0) {
setFiltersInUrl(router, 'posts', { type: 'hot' }, { ref: refId })
} else {
onChangeKey(tab)
}
}, [followedIds, isInitializedProxy])
}, [followedIds, isInitialized])

const handleScroll = () => {
const currentScrollPos = window.pageYOffset
Expand Down
3 changes: 1 addition & 2 deletions src/stores/my-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,9 @@ export const useMyAccount = create<State & Actions>()((set, get) => ({
}
}

set({ isInitialized: true })
set({ isInitialized: true, parentProxyAddress: parentProxyAddress || undefined })

if (parentProxyAddress) {
set({ parentProxyAddress })
try {
const proxies = await getProxies(parentProxyAddress)
const currentProxy = proxies.find(({ address }) => address === get().address)
Expand Down

0 comments on commit a496cf1

Please sign in to comment.