Some me model cleanup (#1928)
* Replace me model in post dropdown btn * Replace delete account logic * Replace me model in bottom bar web * Replace me model in bottom bar * Replace me model in reply prompt * Better fallback * Fix reference * Fix bad ref in bottom barzio/stable
parent
a652b52b88
commit
310a7eaca7
|
@ -3,13 +3,15 @@ import {StyleSheet, TouchableOpacity} from 'react-native'
|
|||
import {UserAvatar} from '../util/UserAvatar'
|
||||
import {Text} from '../util/text/Text'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useStores} from 'state/index'
|
||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||
import {Trans, msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useProfileQuery} from '#/state/queries/profile'
|
||||
|
||||
export function ComposePrompt({onPressCompose}: {onPressCompose: () => void}) {
|
||||
const store = useStores()
|
||||
const {currentAccount} = useSession()
|
||||
const {data: profile} = useProfileQuery({did: currentAccount?.did})
|
||||
const pal = usePalette('default')
|
||||
const {_} = useLingui()
|
||||
const {isDesktop} = useWebMediaQueries()
|
||||
|
@ -21,7 +23,7 @@ export function ComposePrompt({onPressCompose}: {onPressCompose: () => void}) {
|
|||
accessibilityRole="button"
|
||||
accessibilityLabel={_(msg`Compose reply`)}
|
||||
accessibilityHint="Opens composer">
|
||||
<UserAvatar avatar={store.me.avatar} size={38} />
|
||||
<UserAvatar avatar={profile?.avatar} size={38} />
|
||||
<Text
|
||||
type="xl"
|
||||
style={[
|
||||
|
|
|
@ -9,7 +9,6 @@ import {TextInput} from './util'
|
|||
import LinearGradient from 'react-native-linear-gradient'
|
||||
import * as Toast from '../util/Toast'
|
||||
import {Text} from '../util/text/Text'
|
||||
import {useStores} from 'state/index'
|
||||
import {s, colors, gradients} from 'lib/styles'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useTheme} from 'lib/ThemeContext'
|
||||
|
@ -20,13 +19,15 @@ import {resetToTab} from '../../../Navigation'
|
|||
import {Trans, msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useSession, useSessionApi} from '#/state/session'
|
||||
|
||||
export const snapPoints = ['60%']
|
||||
|
||||
export function Component({}: {}) {
|
||||
const pal = usePalette('default')
|
||||
const theme = useTheme()
|
||||
const store = useStores()
|
||||
const {agent, currentAccount} = useSession()
|
||||
const {clearCurrentAccount, removeAccount} = useSessionApi()
|
||||
const {_} = useLingui()
|
||||
const {closeModal} = useModalControls()
|
||||
const {isMobile} = useWebMediaQueries()
|
||||
|
@ -39,7 +40,7 @@ export function Component({}: {}) {
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
await store.agent.com.atproto.server.requestAccountDelete()
|
||||
await agent.com.atproto.server.requestAccountDelete()
|
||||
setIsEmailSent(true)
|
||||
} catch (e: any) {
|
||||
setError(cleanError(e))
|
||||
|
@ -47,19 +48,24 @@ export function Component({}: {}) {
|
|||
setIsProcessing(false)
|
||||
}
|
||||
const onPressConfirmDelete = async () => {
|
||||
if (!currentAccount?.did) {
|
||||
throw new Error(`DeleteAccount modal: currentAccount.did is undefined`)
|
||||
}
|
||||
|
||||
setError('')
|
||||
setIsProcessing(true)
|
||||
const token = confirmCode.replace(/\s/g, '')
|
||||
|
||||
try {
|
||||
await store.agent.com.atproto.server.deleteAccount({
|
||||
did: store.me.did,
|
||||
await agent.com.atproto.server.deleteAccount({
|
||||
did: currentAccount.did,
|
||||
password,
|
||||
token,
|
||||
})
|
||||
Toast.show('Your account has been deleted')
|
||||
resetToTab('HomeTab')
|
||||
store.session.clear()
|
||||
removeAccount(currentAccount)
|
||||
clearCurrentAccount()
|
||||
closeModal()
|
||||
} catch (e: any) {
|
||||
setError(cleanError(e))
|
||||
|
@ -88,7 +94,7 @@ export function Component({}: {}) {
|
|||
pal.text,
|
||||
s.bold,
|
||||
]}>
|
||||
{store.me.handle}
|
||||
{currentAccount?.handle}
|
||||
</Text>
|
||||
<Text type="title-xl" style={[pal.text, s.bold]}>
|
||||
{'"'}
|
||||
|
|
|
@ -15,12 +15,12 @@ import {EventStopper} from '../EventStopper'
|
|||
import {useModalControls} from '#/state/modals'
|
||||
import {makeProfileLink} from '#/lib/routes/links'
|
||||
import {getTranslatorLink} from '#/locale/helpers'
|
||||
import {useStores} from '#/state'
|
||||
import {usePostDeleteMutation} from '#/state/queries/post'
|
||||
import {useMutedThreads, useToggleThreadMute} from '#/state/muted-threads'
|
||||
import {useLanguagePrefs} from '#/state/preferences'
|
||||
import {logger} from '#/logger'
|
||||
import {Shadow} from '#/state/cache/types'
|
||||
import {useSession} from '#/state/session'
|
||||
|
||||
export function PostDropdownBtn({
|
||||
testID,
|
||||
|
@ -33,7 +33,7 @@ export function PostDropdownBtn({
|
|||
record: AppBskyFeedPost.Record
|
||||
style?: StyleProp<ViewStyle>
|
||||
}) {
|
||||
const store = useStores()
|
||||
const {currentAccount} = useSession()
|
||||
const theme = useTheme()
|
||||
const defaultCtrlColor = theme.palette.default.postCtrl
|
||||
const {openModal} = useModalControls()
|
||||
|
@ -44,7 +44,7 @@ export function PostDropdownBtn({
|
|||
|
||||
const rootUri = record.reply?.root?.uri || post.uri
|
||||
const isThreadMuted = mutedThreads.includes(rootUri)
|
||||
const isAuthor = post.author.did === store.me.did
|
||||
const isAuthor = post.author.did === currentAccount?.did
|
||||
const href = React.useMemo(() => {
|
||||
const urip = new AtUri(post.uri)
|
||||
return makeProfileLink(post.author, 'post', urip.rkey)
|
||||
|
|
|
@ -6,7 +6,6 @@ import {BottomTabBarProps} from '@react-navigation/bottom-tabs'
|
|||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
import {Text} from 'view/com/util/text/Text'
|
||||
import {useStores} from 'state/index'
|
||||
import {useAnalytics} from 'lib/analytics/analytics'
|
||||
import {clamp} from 'lib/numbers'
|
||||
import {
|
||||
|
@ -30,6 +29,8 @@ import {useModalControls} from '#/state/modals'
|
|||
import {useShellLayout} from '#/state/shell/shell-layout'
|
||||
import {useUnreadNotifications} from '#/state/queries/notifications/unread'
|
||||
import {emitSoftReset} from '#/state/events'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useProfileQuery} from '#/state/queries/profile'
|
||||
|
||||
type TabOptions = 'Home' | 'Search' | 'Notifications' | 'MyProfile' | 'Feeds'
|
||||
|
||||
|
@ -37,7 +38,7 @@ export const BottomBar = observer(function BottomBarImpl({
|
|||
navigation,
|
||||
}: BottomTabBarProps) {
|
||||
const {openModal} = useModalControls()
|
||||
const store = useStores()
|
||||
const {currentAccount} = useSession()
|
||||
const pal = usePalette('default')
|
||||
const {_} = useLingui()
|
||||
const safeAreaInsets = useSafeAreaInsets()
|
||||
|
@ -47,6 +48,7 @@ export const BottomBar = observer(function BottomBarImpl({
|
|||
useNavigationTabState()
|
||||
const numUnreadNotifications = useUnreadNotifications()
|
||||
const {footerMinimalShellTransform} = useMinimalShellMode()
|
||||
const {data: profile} = useProfileQuery({did: currentAccount?.did})
|
||||
|
||||
const onPressTab = React.useCallback(
|
||||
(tab: TabOptions) => {
|
||||
|
@ -203,7 +205,7 @@ export const BottomBar = observer(function BottomBarImpl({
|
|||
{borderColor: pal.text.color},
|
||||
]}>
|
||||
<UserAvatar
|
||||
avatar={store.me.avatar}
|
||||
avatar={profile?.avatar}
|
||||
size={27}
|
||||
// See https://github.com/bluesky-social/social-app/pull/1801:
|
||||
usePlainRNImage={true}
|
||||
|
@ -212,7 +214,7 @@ export const BottomBar = observer(function BottomBarImpl({
|
|||
) : (
|
||||
<View style={[styles.ctrlIcon, pal.text, styles.profileIcon]}>
|
||||
<UserAvatar
|
||||
avatar={store.me.avatar}
|
||||
avatar={profile?.avatar}
|
||||
size={28}
|
||||
// See https://github.com/bluesky-social/social-app/pull/1801:
|
||||
usePlainRNImage={true}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import React from 'react'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
import {useStores} from 'state/index'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useNavigationState} from '@react-navigation/native'
|
||||
import Animated from 'react-native-reanimated'
|
||||
|
@ -23,9 +22,10 @@ import {Link} from 'view/com/util/Link'
|
|||
import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode'
|
||||
import {makeProfileLink} from 'lib/routes/links'
|
||||
import {CommonNavigatorParams} from 'lib/routes/types'
|
||||
import {useSession} from '#/state/session'
|
||||
|
||||
export const BottomBarWeb = observer(function BottomBarWebImpl() {
|
||||
const store = useStores()
|
||||
const {currentAccount} = useSession()
|
||||
const pal = usePalette('default')
|
||||
const safeAreaInsets = useSafeAreaInsets()
|
||||
const {footerMinimalShellTransform} = useMinimalShellMode()
|
||||
|
@ -88,7 +88,16 @@ export const BottomBarWeb = observer(function BottomBarWebImpl() {
|
|||
)
|
||||
}}
|
||||
</NavItem>
|
||||
<NavItem routeName="Profile" href={makeProfileLink(store.me)}>
|
||||
<NavItem
|
||||
routeName="Profile"
|
||||
href={
|
||||
currentAccount
|
||||
? makeProfileLink({
|
||||
did: currentAccount.did,
|
||||
handle: currentAccount.handle,
|
||||
})
|
||||
: '/'
|
||||
}>
|
||||
{({isActive}) => {
|
||||
const Icon = isActive ? UserIconSolid : UserIcon
|
||||
return (
|
||||
|
@ -109,18 +118,18 @@ const NavItem: React.FC<{
|
|||
href: string
|
||||
routeName: string
|
||||
}> = ({children, href, routeName}) => {
|
||||
const {currentAccount} = useSession()
|
||||
const currentRoute = useNavigationState(state => {
|
||||
if (!state) {
|
||||
return {name: 'Home'}
|
||||
}
|
||||
return getCurrentRoute(state)
|
||||
})
|
||||
const store = useStores()
|
||||
const isActive =
|
||||
currentRoute.name === 'Profile'
|
||||
? isTab(currentRoute.name, routeName) &&
|
||||
(currentRoute.params as CommonNavigatorParams['Profile']).name ===
|
||||
store.me.handle
|
||||
currentAccount?.handle
|
||||
: isTab(currentRoute.name, routeName)
|
||||
|
||||
return (
|
||||
|
|
Loading…
Reference in New Issue