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