Remove deprecated models and mobx usage (react-query refactor) (#1934)
* Update login page to use service query * Update modal to use session instead of store * Move image sizes cache off store * Update settings to no longer use store * Update link-meta fetch to use agent instead of rootstore * Remove deprecated resolveName() * Delete deprecated link-metas cache * Delete deprecated posts cache * Delete all remaining mobx models, including the root store * Strip out unused mobx observer wrappers
This commit is contained in:
parent
e637798e05
commit
54faa7e176
81 changed files with 1084 additions and 1941 deletions
|
@ -1,6 +1,5 @@
|
|||
import React from 'react'
|
||||
import {SafeAreaView} from 'react-native'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
import {Login} from 'view/com/auth/login/Login'
|
||||
import {CreateAccount} from 'view/com/auth/create/CreateAccount'
|
||||
import {ErrorBoundary} from 'view/com/util/ErrorBoundary'
|
||||
|
@ -16,7 +15,7 @@ enum ScreenState {
|
|||
S_CreateAccount,
|
||||
}
|
||||
|
||||
export const LoggedOut = observer(function LoggedOutImpl() {
|
||||
export function LoggedOut() {
|
||||
const pal = usePalette('default')
|
||||
const setMinimalShellMode = useSetMinimalShellMode()
|
||||
const {screen} = useAnalytics()
|
||||
|
@ -58,4 +57,4 @@ export const LoggedOut = observer(function LoggedOutImpl() {
|
|||
</ErrorBoundary>
|
||||
</SafeAreaView>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import React from 'react'
|
||||
import {SafeAreaView} from 'react-native'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
import {ErrorBoundary} from 'view/com/util/ErrorBoundary'
|
||||
import {s} from 'lib/styles'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
|
@ -10,7 +9,7 @@ import {RecommendedFollows} from './onboarding/RecommendedFollows'
|
|||
import {useSetMinimalShellMode} from '#/state/shell/minimal-mode'
|
||||
import {useOnboardingState, useOnboardingDispatch} from '#/state/shell'
|
||||
|
||||
export const Onboarding = observer(function OnboardingImpl() {
|
||||
export function Onboarding() {
|
||||
const pal = usePalette('default')
|
||||
const setMinimalShellMode = useSetMinimalShellMode()
|
||||
const onboardingState = useOnboardingState()
|
||||
|
@ -38,4 +37,4 @@ export const Onboarding = observer(function OnboardingImpl() {
|
|||
</ErrorBoundary>
|
||||
</SafeAreaView>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4,12 +4,14 @@ import {
|
|||
FontAwesomeIcon,
|
||||
FontAwesomeIconStyle,
|
||||
} from '@fortawesome/react-native-fontawesome'
|
||||
import {ComAtprotoServerDescribeServer} from '@atproto/api'
|
||||
import {TextLink} from '../../util/Link'
|
||||
import {Text} from '../../util/text/Text'
|
||||
import {s, colors} from 'lib/styles'
|
||||
import {ServiceDescription} from 'state/models/session'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
|
||||
type ServiceDescription = ComAtprotoServerDescribeServer.OutputSchema
|
||||
|
||||
export const Policies = ({
|
||||
serviceDescription,
|
||||
needsGuardian,
|
||||
|
|
|
@ -13,7 +13,7 @@ import {ErrorMessage} from 'view/com/util/error/ErrorMessage'
|
|||
import {msg, Trans} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {LOCAL_DEV_SERVICE, STAGING_SERVICE, PROD_SERVICE} from 'state/index'
|
||||
import {LOCAL_DEV_SERVICE, STAGING_SERVICE, PROD_SERVICE} from 'lib/constants'
|
||||
import {LOGIN_INCLUDE_DEV_SERVERS} from 'lib/build-flags'
|
||||
|
||||
/** STEP 1: Your hosting provider
|
||||
|
|
|
@ -9,13 +9,13 @@ import {
|
|||
FontAwesomeIcon,
|
||||
FontAwesomeIconStyle,
|
||||
} from '@fortawesome/react-native-fontawesome'
|
||||
import {ComAtprotoServerDescribeServer} from '@atproto/api'
|
||||
import * as EmailValidator from 'email-validator'
|
||||
import {BskyAgent} from '@atproto/api'
|
||||
import {useAnalytics} from 'lib/analytics/analytics'
|
||||
import {Text} from '../../util/text/Text'
|
||||
import {s} from 'lib/styles'
|
||||
import {toNiceDomain} from 'lib/strings/url-helpers'
|
||||
import {ServiceDescription} from 'state/models/session'
|
||||
import {isNetworkError} from 'lib/strings/errors'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useTheme} from 'lib/ThemeContext'
|
||||
|
@ -26,6 +26,8 @@ import {useLingui} from '@lingui/react'
|
|||
import {styles} from './styles'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
|
||||
type ServiceDescription = ComAtprotoServerDescribeServer.OutputSchema
|
||||
|
||||
export const ForgotPasswordForm = ({
|
||||
error,
|
||||
serviceUrl,
|
||||
|
|
|
@ -2,8 +2,7 @@ import React, {useState, useEffect} from 'react'
|
|||
import {KeyboardAvoidingView} from 'react-native'
|
||||
import {useAnalytics} from 'lib/analytics/analytics'
|
||||
import {LoggedOutLayout} from 'view/com/util/layouts/LoggedOutLayout'
|
||||
import {useStores, DEFAULT_SERVICE} from 'state/index'
|
||||
import {ServiceDescription} from 'state/models/session'
|
||||
import {DEFAULT_SERVICE} from '#/lib/constants'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {logger} from '#/logger'
|
||||
import {ChooseAccountForm} from './ChooseAccountForm'
|
||||
|
@ -14,6 +13,7 @@ import {PasswordUpdatedForm} from './PasswordUpdatedForm'
|
|||
import {useLingui} from '@lingui/react'
|
||||
import {msg} from '@lingui/macro'
|
||||
import {useSession, SessionAccount} from '#/state/session'
|
||||
import {useServiceQuery} from '#/state/queries/service'
|
||||
|
||||
enum Forms {
|
||||
Login,
|
||||
|
@ -25,20 +25,20 @@ enum Forms {
|
|||
|
||||
export const Login = ({onPressBack}: {onPressBack: () => void}) => {
|
||||
const pal = usePalette('default')
|
||||
const store = useStores()
|
||||
const {accounts} = useSession()
|
||||
const {track} = useAnalytics()
|
||||
const {_} = useLingui()
|
||||
const [error, setError] = useState<string>('')
|
||||
const [retryDescribeTrigger, setRetryDescribeTrigger] = useState<any>({})
|
||||
const [serviceUrl, setServiceUrl] = useState<string>(DEFAULT_SERVICE)
|
||||
const [serviceDescription, setServiceDescription] = useState<
|
||||
ServiceDescription | undefined
|
||||
>(undefined)
|
||||
const [initialHandle, setInitialHandle] = useState<string>('')
|
||||
const [currentForm, setCurrentForm] = useState<Forms>(
|
||||
accounts.length ? Forms.ChooseAccount : Forms.Login,
|
||||
)
|
||||
const {
|
||||
data: serviceDescription,
|
||||
error: serviceError,
|
||||
refetch: refetchService,
|
||||
} = useServiceQuery(serviceUrl)
|
||||
|
||||
const onSelectAccount = (account?: SessionAccount) => {
|
||||
if (account?.service) {
|
||||
|
@ -54,35 +54,21 @@ export const Login = ({onPressBack}: {onPressBack: () => void}) => {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
let aborted = false
|
||||
setError('')
|
||||
store.session.describeService(serviceUrl).then(
|
||||
desc => {
|
||||
if (aborted) {
|
||||
return
|
||||
}
|
||||
setServiceDescription(desc)
|
||||
},
|
||||
err => {
|
||||
if (aborted) {
|
||||
return
|
||||
}
|
||||
logger.warn(`Failed to fetch service description for ${serviceUrl}`, {
|
||||
error: err,
|
||||
})
|
||||
setError(
|
||||
_(
|
||||
msg`Unable to contact your service. Please check your Internet connection.`,
|
||||
),
|
||||
)
|
||||
},
|
||||
)
|
||||
return () => {
|
||||
aborted = true
|
||||
if (serviceError) {
|
||||
setError(
|
||||
_(
|
||||
msg`Unable to contact your service. Please check your Internet connection.`,
|
||||
),
|
||||
)
|
||||
logger.warn(`Failed to fetch service description for ${serviceUrl}`, {
|
||||
error: String(serviceError),
|
||||
})
|
||||
} else {
|
||||
setError('')
|
||||
}
|
||||
}, [store.session, serviceUrl, retryDescribeTrigger, _])
|
||||
}, [serviceError, serviceUrl, _])
|
||||
|
||||
const onPressRetryConnect = () => setRetryDescribeTrigger({})
|
||||
const onPressRetryConnect = () => refetchService()
|
||||
const onPressForgotPassword = () => {
|
||||
track('Signin:PressedForgotPassword')
|
||||
setCurrentForm(Forms.ForgotPassword)
|
||||
|
|
|
@ -10,12 +10,12 @@ import {
|
|||
FontAwesomeIcon,
|
||||
FontAwesomeIconStyle,
|
||||
} from '@fortawesome/react-native-fontawesome'
|
||||
import {ComAtprotoServerDescribeServer} from '@atproto/api'
|
||||
import {useAnalytics} from 'lib/analytics/analytics'
|
||||
import {Text} from '../../util/text/Text'
|
||||
import {s} from 'lib/styles'
|
||||
import {createFullHandle} from 'lib/strings/handles'
|
||||
import {toNiceDomain} from 'lib/strings/url-helpers'
|
||||
import {ServiceDescription} from 'state/models/session'
|
||||
import {isNetworkError} from 'lib/strings/errors'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useTheme} from 'lib/ThemeContext'
|
||||
|
@ -27,6 +27,8 @@ import {styles} from './styles'
|
|||
import {useLingui} from '@lingui/react'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
|
||||
type ServiceDescription = ComAtprotoServerDescribeServer.OutputSchema
|
||||
|
||||
export const LoginForm = ({
|
||||
error,
|
||||
serviceUrl,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import React from 'react'
|
||||
import {ActivityIndicator, FlatList, StyleSheet, View} from 'react-native'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {TabletOrDesktop, Mobile} from 'view/com/util/layouts/Breakpoints'
|
||||
import {Text} from 'view/com/util/text/Text'
|
||||
|
@ -16,9 +15,7 @@ import {useSuggestedFeedsQuery} from '#/state/queries/suggested-feeds'
|
|||
type Props = {
|
||||
next: () => void
|
||||
}
|
||||
export const RecommendedFeeds = observer(function RecommendedFeedsImpl({
|
||||
next,
|
||||
}: Props) {
|
||||
export function RecommendedFeeds({next}: Props) {
|
||||
const pal = usePalette('default')
|
||||
const {isTabletOrMobile} = useWebMediaQueries()
|
||||
const {isLoading, data} = useSuggestedFeedsQuery()
|
||||
|
@ -146,7 +143,7 @@ export const RecommendedFeeds = observer(function RecommendedFeedsImpl({
|
|||
</Mobile>
|
||||
</>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const tdStyles = StyleSheet.create({
|
||||
container: {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import React from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {AppBskyFeedDefs, RichText as BskRichText} from '@atproto/api'
|
||||
import {Text} from 'view/com/util/text/Text'
|
||||
|
@ -19,7 +18,7 @@ import {
|
|||
} from '#/state/queries/preferences'
|
||||
import {logger} from '#/logger'
|
||||
|
||||
export const RecommendedFeedsItem = observer(function RecommendedFeedsItemImpl({
|
||||
export function RecommendedFeedsItem({
|
||||
item,
|
||||
}: {
|
||||
item: AppBskyFeedDefs.GeneratorView
|
||||
|
@ -164,4 +163,4 @@ export const RecommendedFeedsItem = observer(function RecommendedFeedsItemImpl({
|
|||
</View>
|
||||
</View>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import React from 'react'
|
||||
import {ActivityIndicator, FlatList, StyleSheet, View} from 'react-native'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {AppBskyActorDefs, moderateProfile} from '@atproto/api'
|
||||
import {TabletOrDesktop, Mobile} from 'view/com/util/layouts/Breakpoints'
|
||||
|
@ -19,9 +18,7 @@ import {logger} from '#/logger'
|
|||
type Props = {
|
||||
next: () => void
|
||||
}
|
||||
export const RecommendedFollows = observer(function RecommendedFollowsImpl({
|
||||
next,
|
||||
}: Props) {
|
||||
export function RecommendedFollows({next}: Props) {
|
||||
const pal = usePalette('default')
|
||||
const {isTabletOrMobile} = useWebMediaQueries()
|
||||
const {data: suggestedFollows, dataUpdatedAt} = useSuggestedFollowsQuery()
|
||||
|
@ -211,7 +208,7 @@ export const RecommendedFollows = observer(function RecommendedFollowsImpl({
|
|||
</Mobile>
|
||||
</>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const tdStyles = StyleSheet.create({
|
||||
container: {
|
||||
|
|
|
@ -7,16 +7,13 @@ import {usePalette} from 'lib/hooks/usePalette'
|
|||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {TitleColumnLayout} from 'view/com/util/layouts/TitleColumnLayout'
|
||||
import {Button} from 'view/com/util/forms/Button'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
|
||||
type Props = {
|
||||
next: () => void
|
||||
skip: () => void
|
||||
}
|
||||
|
||||
export const WelcomeDesktop = observer(function WelcomeDesktopImpl({
|
||||
next,
|
||||
}: Props) {
|
||||
export function WelcomeDesktop({next}: Props) {
|
||||
const pal = usePalette('default')
|
||||
const horizontal = useMediaQuery({minWidth: 1300})
|
||||
const title = (
|
||||
|
@ -105,7 +102,7 @@ export const WelcomeDesktop = observer(function WelcomeDesktopImpl({
|
|||
</View>
|
||||
</TitleColumnLayout>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
row: {
|
||||
|
|
|
@ -5,7 +5,6 @@ import {s} from 'lib/styles'
|
|||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {Button} from 'view/com/util/forms/Button'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
import {ViewHeader} from 'view/com/util/ViewHeader'
|
||||
import {Trans} from '@lingui/macro'
|
||||
|
||||
|
@ -14,10 +13,7 @@ type Props = {
|
|||
skip: () => void
|
||||
}
|
||||
|
||||
export const WelcomeMobile = observer(function WelcomeMobileImpl({
|
||||
next,
|
||||
skip,
|
||||
}: Props) {
|
||||
export function WelcomeMobile({next, skip}: Props) {
|
||||
const pal = usePalette('default')
|
||||
|
||||
return (
|
||||
|
@ -102,7 +98,7 @@ export const WelcomeMobile = observer(function WelcomeMobileImpl({
|
|||
/>
|
||||
</View>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
|
|
|
@ -5,7 +5,6 @@ import {
|
|||
StyleSheet,
|
||||
TouchableOpacity,
|
||||
} from 'react-native'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
import {CenteredView} from '../util/Views'
|
||||
import {LoggedOut} from './LoggedOut'
|
||||
import {Onboarding} from './Onboarding'
|
||||
|
@ -18,7 +17,7 @@ import {useSession} from '#/state/session'
|
|||
export const withAuthRequired = <P extends object>(
|
||||
Component: React.ComponentType<P>,
|
||||
): React.FC<P> =>
|
||||
observer(function AuthRequired(props: P) {
|
||||
function AuthRequired(props: P) {
|
||||
const {isInitialLoad, hasSession} = useSession()
|
||||
const onboardingState = useOnboardingState()
|
||||
if (isInitialLoad) {
|
||||
|
@ -31,7 +30,7 @@ export const withAuthRequired = <P extends object>(
|
|||
return <Onboarding />
|
||||
}
|
||||
return <Component {...props} />
|
||||
})
|
||||
}
|
||||
|
||||
function Loading() {
|
||||
const pal = usePalette('default')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue