mirror of https://github.com/tooot-app/app
Improve account fetching
This commit is contained in:
parent
84b36e0f9c
commit
dd4a9671ba
|
@ -8,8 +8,12 @@ import AccountNav from '@screens/Tabs/Shared/Account/Nav'
|
|||
import AccountContext from '@screens/Tabs/Shared/Account/utils/createContext'
|
||||
import accountInitialState from '@screens/Tabs/Shared/Account/utils/initialState'
|
||||
import accountReducer from '@screens/Tabs/Shared/Account/utils/reducer'
|
||||
import { getInstanceActive } from '@utils/slices/instancesSlice'
|
||||
import React, { useReducer, useRef, useState } from 'react'
|
||||
import { useAccountQuery } from '@utils/queryHooks/account'
|
||||
import {
|
||||
getInstanceAccount,
|
||||
getInstanceActive
|
||||
} from '@utils/slices/instancesSlice'
|
||||
import React, { useReducer, useRef } from 'react'
|
||||
import Animated, {
|
||||
useAnimatedScrollHandler,
|
||||
useSharedValue
|
||||
|
@ -18,12 +22,19 @@ import { useSelector } from 'react-redux'
|
|||
|
||||
const ScreenMeRoot: React.FC = () => {
|
||||
const instanceActive = useSelector(getInstanceActive)
|
||||
const instanceAccount = useSelector(
|
||||
getInstanceAccount,
|
||||
(prev, next) => prev?.id === next?.id
|
||||
)
|
||||
const { data } = useAccountQuery({
|
||||
// @ts-ignore
|
||||
id: instanceAccount?.id,
|
||||
options: { enabled: instanceActive !== -1, keepPreviousData: false }
|
||||
})
|
||||
|
||||
const scrollRef = useRef<Animated.ScrollView>(null)
|
||||
useScrollToTop(scrollRef)
|
||||
|
||||
const [data, setData] = useState<Mastodon.Account>()
|
||||
|
||||
const [accountState, accountDispatch] = useReducer(
|
||||
accountReducer,
|
||||
accountInitialState
|
||||
|
@ -46,7 +57,7 @@ const ScreenMeRoot: React.FC = () => {
|
|||
scrollEventThrottle={16}
|
||||
>
|
||||
{instanceActive !== -1 ? (
|
||||
<MyInfo setData={setData} />
|
||||
<MyInfo account={data} />
|
||||
) : (
|
||||
<ComponentInstance />
|
||||
)}
|
||||
|
|
|
@ -1,31 +1,16 @@
|
|||
import AccountHeader from '@screens/Tabs/Shared/Account/Header'
|
||||
import AccountInformation from '@screens/Tabs/Shared/Account/Information'
|
||||
import { useAccountQuery } from '@utils/queryHooks/account'
|
||||
import { getInstanceAccount } from '@utils/slices/instancesSlice'
|
||||
import React, { useEffect } from 'react'
|
||||
import { useSelector } from 'react-redux'
|
||||
import React from 'react'
|
||||
|
||||
export interface Props {
|
||||
setData: React.Dispatch<React.SetStateAction<Mastodon.Account | undefined>>
|
||||
account: Mastodon.Account | undefined
|
||||
}
|
||||
|
||||
const MyInfo: React.FC<Props> = ({ setData }) => {
|
||||
const instanceAccount = useSelector(
|
||||
getInstanceAccount,
|
||||
(prev, next) => prev?.id === next?.id
|
||||
)
|
||||
const { data } = useAccountQuery({ id: instanceAccount!.id })
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
setData(data)
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const MyInfo: React.FC<Props> = ({ account }) => {
|
||||
return (
|
||||
<>
|
||||
<AccountHeader account={data} limitHeight />
|
||||
<AccountInformation account={data} myInfo />
|
||||
<AccountHeader account={account} limitHeight />
|
||||
<AccountInformation account={account} myInfo />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ const AccountInformationAccount: React.FC<Props> = ({ account, myInfo }) => {
|
|||
} else {
|
||||
return (
|
||||
<PlaceholderLine
|
||||
width={StyleConstants.Font.Size.M * 2}
|
||||
width={StyleConstants.Font.Size.M * 3}
|
||||
height={StyleConstants.Font.LineHeight.M}
|
||||
color={theme.shimmerDefault}
|
||||
noMargin
|
||||
|
|
|
@ -48,7 +48,7 @@ const AccountInformationCreated: React.FC<Props> = ({ account }) => {
|
|||
} else {
|
||||
return (
|
||||
<PlaceholderLine
|
||||
width={StyleConstants.Font.Size.S * 3}
|
||||
width={StyleConstants.Font.Size.S * 4}
|
||||
height={StyleConstants.Font.LineHeight.S}
|
||||
color={theme.shimmerDefault}
|
||||
noMargin
|
||||
|
|
|
@ -36,31 +36,31 @@ const AccountInformationName: React.FC<Props> = ({ account }) => {
|
|||
}
|
||||
}, [account?.moved])
|
||||
|
||||
if (account) {
|
||||
return (
|
||||
<View style={[styles.base, { flexDirection: 'row' }]}>
|
||||
<Text style={movedStyle.base}>
|
||||
<ParseEmojis
|
||||
content={account.display_name || account.username}
|
||||
emojis={account.emojis}
|
||||
size='L'
|
||||
fontBold
|
||||
/>
|
||||
</Text>
|
||||
{movedContent}
|
||||
</View>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<PlaceholderLine
|
||||
width={StyleConstants.Font.Size.L * 2}
|
||||
height={StyleConstants.Font.LineHeight.L}
|
||||
color={theme.shimmerDefault}
|
||||
noMargin
|
||||
style={styles.base}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<View style={[styles.base, { flexDirection: 'row' }]}>
|
||||
{account ? (
|
||||
<>
|
||||
<Text style={movedStyle.base}>
|
||||
<ParseEmojis
|
||||
content={account.display_name || account.username}
|
||||
emojis={account.emojis}
|
||||
size='L'
|
||||
fontBold
|
||||
/>
|
||||
</Text>
|
||||
{movedContent}
|
||||
</>
|
||||
) : (
|
||||
<PlaceholderLine
|
||||
width={StyleConstants.Font.Size.L * 2}
|
||||
height={StyleConstants.Font.LineHeight.L}
|
||||
color={theme.shimmerDefault}
|
||||
noMargin
|
||||
style={{ borderRadius: 0 }}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
|
|
Loading…
Reference in New Issue