[Perf - part 1] Hoist service config query (#8812)
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
import {STALE} from '#/state/queries'
|
||||
import {useServiceConfigQuery} from '#/state/queries/email-verification-required'
|
||||
import {useProfileQuery} from '#/state/queries/profile'
|
||||
import {useSession} from '#/state/session'
|
||||
import {BSKY_SERVICE} from '../constants'
|
||||
import {getHostnameFromUrl} from '../strings/url-helpers'
|
||||
|
||||
export function useEmail() {
|
||||
const {currentAccount} = useSession()
|
||||
|
||||
const {data: serviceConfig} = useServiceConfigQuery()
|
||||
const {data: profile} = useProfileQuery({
|
||||
did: currentAccount?.did,
|
||||
staleTime: STALE.INFINITY,
|
||||
})
|
||||
|
||||
const checkEmailConfirmed = !!serviceConfig?.checkEmailConfirmed
|
||||
|
||||
// Date set for 11 AM PST on the 18th of November
|
||||
const isNewEnough =
|
||||
!!profile?.createdAt &&
|
||||
Date.parse(profile.createdAt) >= Date.parse('2024-11-18T19:00:00.000Z')
|
||||
|
||||
const isSelfHost =
|
||||
currentAccount &&
|
||||
getHostnameFromUrl(currentAccount.service) !==
|
||||
getHostnameFromUrl(BSKY_SERVICE)
|
||||
|
||||
const needsEmailVerification =
|
||||
!isSelfHost &&
|
||||
checkEmailConfirmed &&
|
||||
!currentAccount?.emailConfirmed &&
|
||||
isNewEnough
|
||||
|
||||
return {needsEmailVerification}
|
||||
}
|
||||
@@ -2,10 +2,10 @@ import {useMemo} from 'react'
|
||||
import {Trans} from '@lingui/macro'
|
||||
|
||||
import {useRequireEmailVerification} from '#/lib/hooks/useRequireEmailVerification'
|
||||
import {useOpenComposer as rootUseOpenComposer} from '#/state/shell/composer'
|
||||
import {useOpenComposer as useRootOpenComposer} from '#/state/shell/composer'
|
||||
|
||||
export function useOpenComposer() {
|
||||
const {openComposer} = rootUseOpenComposer()
|
||||
const {openComposer} = useRootOpenComposer()
|
||||
const requireEmailVerification = useRequireEmailVerification()
|
||||
return useMemo(() => {
|
||||
return {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {useCallback} from 'react'
|
||||
import {Keyboard} from 'react-native'
|
||||
|
||||
import {useEmail} from '#/lib/hooks/useEmail'
|
||||
import {useEmail} from '#/state/email-verification'
|
||||
import {useRequireAuth, useSession} from '#/state/session'
|
||||
import {useCloseAllActiveElements} from '#/state/util'
|
||||
import {
|
||||
|
||||
Reference in New Issue
Block a user