mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Clean up core timeline components
This commit is contained in:
@ -8,8 +8,9 @@ import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||
import { getInstanceAccount } from '@utils/slices/instancesSlice'
|
||||
import { StyleConstants } from '@utils/styles/constants'
|
||||
import { useTheme } from '@utils/styles/ThemeManager'
|
||||
import { isEqual } from 'lodash'
|
||||
import React, { useCallback } from 'react'
|
||||
import { Pressable, StyleSheet, View } from 'react-native'
|
||||
import { Pressable, View } from 'react-native'
|
||||
import { useMutation, useQueryClient } from 'react-query'
|
||||
import { useSelector } from 'react-redux'
|
||||
import TimelineActions from './Shared/Actions'
|
||||
@ -54,117 +55,107 @@ export interface Props {
|
||||
highlighted?: boolean
|
||||
}
|
||||
|
||||
const TimelineConversation: React.FC<Props> = ({
|
||||
conversation,
|
||||
queryKey,
|
||||
highlighted = false
|
||||
}) => {
|
||||
const instanceAccount = useSelector(
|
||||
getInstanceAccount,
|
||||
(prev, next) => prev?.id === next?.id
|
||||
)
|
||||
const { colors } = useTheme()
|
||||
const TimelineConversation = React.memo(
|
||||
({ conversation, queryKey, highlighted = false }: Props) => {
|
||||
const instanceAccount = useSelector(
|
||||
getInstanceAccount,
|
||||
(prev, next) => prev?.id === next?.id
|
||||
)
|
||||
const { colors } = useTheme()
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const fireMutation = useCallback(() => {
|
||||
return apiInstance<Mastodon.Conversation>({
|
||||
method: 'post',
|
||||
url: `conversations/${conversation.id}/read`
|
||||
})
|
||||
}, [])
|
||||
const { mutate } = useMutation(fireMutation, {
|
||||
onSettled: () => {
|
||||
queryClient.invalidateQueries(queryKey)
|
||||
}
|
||||
})
|
||||
|
||||
const navigation =
|
||||
useNavigation<StackNavigationProp<TabLocalStackParamList>>()
|
||||
const onPress = useCallback(() => {
|
||||
analytics('timeline_conversation_press')
|
||||
if (conversation.last_status) {
|
||||
conversation.unread && mutate()
|
||||
navigation.push('Tab-Shared-Toot', {
|
||||
toot: conversation.last_status,
|
||||
rootQueryKey: queryKey
|
||||
const queryClient = useQueryClient()
|
||||
const fireMutation = useCallback(() => {
|
||||
return apiInstance<Mastodon.Conversation>({
|
||||
method: 'post',
|
||||
url: `conversations/${conversation.id}/read`
|
||||
})
|
||||
}
|
||||
}, [])
|
||||
}, [])
|
||||
const { mutate } = useMutation(fireMutation, {
|
||||
onSettled: () => {
|
||||
queryClient.invalidateQueries(queryKey)
|
||||
}
|
||||
})
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
style={[
|
||||
styles.base,
|
||||
{ backgroundColor: colors.backgroundDefault },
|
||||
conversation.unread && {
|
||||
borderLeftWidth: StyleConstants.Spacing.XS,
|
||||
borderLeftColor: colors.blue,
|
||||
paddingLeft:
|
||||
StyleConstants.Spacing.Global.PagePadding -
|
||||
StyleConstants.Spacing.XS
|
||||
}
|
||||
]}
|
||||
onPress={onPress}
|
||||
>
|
||||
<View style={styles.header}>
|
||||
<Avatars accounts={conversation.accounts} />
|
||||
<TimelineHeaderConversation
|
||||
queryKey={queryKey}
|
||||
conversation={conversation}
|
||||
/>
|
||||
</View>
|
||||
const navigation =
|
||||
useNavigation<StackNavigationProp<TabLocalStackParamList>>()
|
||||
const onPress = useCallback(() => {
|
||||
analytics('timeline_conversation_press')
|
||||
if (conversation.last_status) {
|
||||
conversation.unread && mutate()
|
||||
navigation.push('Tab-Shared-Toot', {
|
||||
toot: conversation.last_status,
|
||||
rootQueryKey: queryKey
|
||||
})
|
||||
}
|
||||
}, [])
|
||||
|
||||
{conversation.last_status ? (
|
||||
<>
|
||||
<View
|
||||
style={{
|
||||
paddingTop: highlighted ? StyleConstants.Spacing.S : 0,
|
||||
paddingLeft: highlighted
|
||||
? 0
|
||||
: StyleConstants.Avatar.M + StyleConstants.Spacing.S
|
||||
}}
|
||||
>
|
||||
<TimelineContent
|
||||
return (
|
||||
<Pressable
|
||||
style={[
|
||||
{
|
||||
flex: 1,
|
||||
flexDirection: 'column',
|
||||
padding: StyleConstants.Spacing.Global.PagePadding,
|
||||
paddingBottom: 0,
|
||||
backgroundColor: colors.backgroundDefault
|
||||
},
|
||||
conversation.unread && {
|
||||
borderLeftWidth: StyleConstants.Spacing.XS,
|
||||
borderLeftColor: colors.blue,
|
||||
paddingLeft:
|
||||
StyleConstants.Spacing.Global.PagePadding -
|
||||
StyleConstants.Spacing.XS
|
||||
}
|
||||
]}
|
||||
onPress={onPress}
|
||||
>
|
||||
<View style={{ flex: 1, width: '100%', flexDirection: 'row' }}>
|
||||
<Avatars accounts={conversation.accounts} />
|
||||
<TimelineHeaderConversation
|
||||
queryKey={queryKey}
|
||||
conversation={conversation}
|
||||
/>
|
||||
</View>
|
||||
|
||||
{conversation.last_status ? (
|
||||
<>
|
||||
<View
|
||||
style={{
|
||||
paddingTop: highlighted ? StyleConstants.Spacing.S : 0,
|
||||
paddingLeft: highlighted
|
||||
? 0
|
||||
: StyleConstants.Avatar.M + StyleConstants.Spacing.S
|
||||
}}
|
||||
>
|
||||
<TimelineContent
|
||||
status={conversation.last_status}
|
||||
highlighted={highlighted}
|
||||
/>
|
||||
{conversation.last_status.poll ? (
|
||||
<TimelinePoll
|
||||
queryKey={queryKey}
|
||||
statusId={conversation.last_status.id}
|
||||
poll={conversation.last_status.poll}
|
||||
reblog={false}
|
||||
sameAccount={
|
||||
conversation.last_status.id === instanceAccount?.id
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
<TimelineActions
|
||||
queryKey={queryKey}
|
||||
status={conversation.last_status}
|
||||
highlighted={highlighted}
|
||||
accts={conversation.accounts.map(account => account.acct)}
|
||||
reblog={false}
|
||||
/>
|
||||
{conversation.last_status.poll ? (
|
||||
<TimelinePoll
|
||||
queryKey={queryKey}
|
||||
statusId={conversation.last_status.id}
|
||||
poll={conversation.last_status.poll}
|
||||
reblog={false}
|
||||
sameAccount={
|
||||
conversation.last_status.id === instanceAccount?.id
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
<TimelineActions
|
||||
queryKey={queryKey}
|
||||
status={conversation.last_status}
|
||||
highlighted={highlighted}
|
||||
accts={conversation.accounts.map(account => account.acct)}
|
||||
reblog={false}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
base: {
|
||||
flex: 1,
|
||||
flexDirection: 'column',
|
||||
padding: StyleConstants.Spacing.Global.PagePadding,
|
||||
paddingBottom: 0
|
||||
</>
|
||||
) : null}
|
||||
</Pressable>
|
||||
)
|
||||
},
|
||||
header: {
|
||||
flex: 1,
|
||||
width: '100%',
|
||||
flexDirection: 'row'
|
||||
}
|
||||
})
|
||||
(prev, next) => isEqual(prev.conversation, next.conversation)
|
||||
)
|
||||
|
||||
export default TimelineConversation
|
||||
|
Reference in New Issue
Block a user