[Session] Add useAgent
hook and replace (#3706)
* Hook it up * Memoize getAgent method * Use one shared reference --------- Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
This commit is contained in:
parent
d8c8e1e854
commit
45d354cd0c
53 changed files with 231 additions and 114 deletions
|
@ -19,7 +19,7 @@ import {resetProfilePostsQueries} from '#/state/queries/post-feed'
|
|||
import {useModerationOpts} from '#/state/queries/preferences'
|
||||
import {useProfileQuery} from '#/state/queries/profile'
|
||||
import {useResolveDidQuery} from '#/state/queries/resolve-uri'
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {useSetDrawerSwipeDisabled, useSetMinimalShellMode} from '#/state/shell'
|
||||
import {useComposerControls} from '#/state/shell/composer'
|
||||
import {useAnalytics} from 'lib/analytics/analytics'
|
||||
|
@ -472,6 +472,7 @@ function ProfileScreenLoaded({
|
|||
}
|
||||
|
||||
function useRichText(text: string): [RichTextAPI, boolean] {
|
||||
const {getAgent} = useAgent()
|
||||
const [prevText, setPrevText] = React.useState(text)
|
||||
const [rawRT, setRawRT] = React.useState(() => new RichTextAPI({text}))
|
||||
const [resolvedRT, setResolvedRT] = React.useState<RichTextAPI | null>(null)
|
||||
|
@ -495,7 +496,7 @@ function useRichText(text: string): [RichTextAPI, boolean] {
|
|||
return () => {
|
||||
ignore = true
|
||||
}
|
||||
}, [text])
|
||||
}, [text, getAgent])
|
||||
const isResolving = resolvedRT === null
|
||||
return [resolvedRT ?? rawRT, isResolving]
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import {useLingui} from '@lingui/react'
|
|||
|
||||
import {cleanError} from '#/lib/strings/errors'
|
||||
import {isNative} from '#/platform/detection'
|
||||
import {getAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {ErrorMessage} from '#/view/com/util/error/ErrorMessage'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
|
||||
|
@ -31,6 +31,7 @@ export function DisableEmail2FADialog({
|
|||
const {gtMobile} = useBreakpoints()
|
||||
const {currentAccount} = useSession()
|
||||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const [stage, setStage] = useState<Stages>(Stages.Email)
|
||||
const [confirmationCode, setConfirmationCode] = useState<string>('')
|
||||
|
|
|
@ -3,7 +3,7 @@ import {msg} from '@lingui/macro'
|
|||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {getAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {ToggleButton} from 'view/com/util/forms/ToggleButton'
|
||||
import {useDialogControl} from '#/components/Dialog'
|
||||
import {DisableEmail2FADialog} from './DisableEmail2FADialog'
|
||||
|
@ -14,6 +14,7 @@ export function Email2FAToggle() {
|
|||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {openModal} = useModalControls()
|
||||
const disableDialogCtrl = useDialogControl()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const enableEmailAuthFactor = React.useCallback(async () => {
|
||||
if (currentAccount?.email) {
|
||||
|
@ -25,7 +26,7 @@ export function Email2FAToggle() {
|
|||
emailAuthFactor: true,
|
||||
})
|
||||
}
|
||||
}, [currentAccount, updateCurrentAccount])
|
||||
}, [currentAccount, updateCurrentAccount, getAgent])
|
||||
|
||||
const onToggle = React.useCallback(() => {
|
||||
if (!currentAccount) {
|
||||
|
|
|
@ -3,7 +3,7 @@ import {View} from 'react-native'
|
|||
import {msg, Trans} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
|
||||
import {Button, ButtonText} from '#/components/Button'
|
||||
import * as Dialog from '#/components/Dialog'
|
||||
|
@ -19,6 +19,7 @@ export function ExportCarDialog({
|
|||
const t = useTheme()
|
||||
const {gtMobile} = useBreakpoints()
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const downloadUrl = React.useMemo(() => {
|
||||
const agent = getAgent()
|
||||
|
@ -30,7 +31,7 @@ export function ExportCarDialog({
|
|||
url.pathname = '/xrpc/com.atproto.sync.getRepo'
|
||||
url.searchParams.set('did', agent.session.did)
|
||||
return url.toString()
|
||||
}, [currentAccount])
|
||||
}, [currentAccount, getAgent])
|
||||
|
||||
return (
|
||||
<Dialog.Outer control={control}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue