2020-11-28 17:07:30 +01:00
|
|
|
import React, { useCallback, useMemo } from 'react'
|
2020-10-29 14:52:28 +01:00
|
|
|
import { Dimensions, Pressable, StyleSheet, View } from 'react-native'
|
|
|
|
import { useNavigation } from '@react-navigation/native'
|
|
|
|
|
2020-12-03 01:28:56 +01:00
|
|
|
import TimelineActioned from './Shared/Actioned'
|
|
|
|
import TimelineActions from './Shared/Actions'
|
|
|
|
import TimelineAttachment from './Shared/Attachment'
|
|
|
|
import TimelineAvatar from './Shared/Avatar'
|
|
|
|
import TimelineCard from './Shared/Card'
|
|
|
|
import TimelineContent from './Shared/Content'
|
|
|
|
import TimelineHeaderDefault from './Shared/HeaderDefault'
|
|
|
|
import TimelinePoll from './Shared/Poll'
|
|
|
|
|
2020-11-30 00:24:53 +01:00
|
|
|
import { StyleConstants } from 'src/utils/styles/constants'
|
2020-10-29 14:52:28 +01:00
|
|
|
|
2020-10-31 21:04:46 +01:00
|
|
|
export interface Props {
|
2020-11-22 00:46:23 +01:00
|
|
|
item: Mastodon.Status
|
2020-11-21 00:40:55 +01:00
|
|
|
queryKey: App.QueryKey
|
2020-10-31 21:04:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 00:07:32 +01:00
|
|
|
// When the poll is long
|
2020-11-22 00:46:23 +01:00
|
|
|
const TimelineDefault: React.FC<Props> = ({ item, queryKey }) => {
|
2020-10-29 14:52:28 +01:00
|
|
|
const navigation = useNavigation()
|
|
|
|
|
2020-11-22 00:46:23 +01:00
|
|
|
let actualStatus = item.reblog ? item.reblog : item
|
2020-12-03 01:28:56 +01:00
|
|
|
const contentWidth =
|
|
|
|
Dimensions.get('window').width -
|
|
|
|
StyleConstants.Spacing.Global.PagePadding * 2 - // Global page padding on both sides
|
|
|
|
StyleConstants.Avatar.S - // Avatar width
|
|
|
|
StyleConstants.Spacing.S // Avatar margin to the right
|
2020-10-29 14:52:28 +01:00
|
|
|
|
2020-11-28 17:07:30 +01:00
|
|
|
const pressableToot = useCallback(
|
|
|
|
() =>
|
|
|
|
navigation.navigate('Screen-Shared-Toot', {
|
|
|
|
toot: actualStatus.id
|
|
|
|
}),
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
const childrenToot = useMemo(
|
|
|
|
() => (
|
|
|
|
<>
|
2020-12-03 01:28:56 +01:00
|
|
|
{actualStatus.content.length > 0 && (
|
|
|
|
<TimelineContent status={actualStatus} />
|
|
|
|
)}
|
|
|
|
{actualStatus.poll && (
|
2020-12-03 10:39:37 +01:00
|
|
|
<TimelinePoll queryKey={queryKey} status={actualStatus} />
|
2020-11-28 17:07:30 +01:00
|
|
|
)}
|
|
|
|
{actualStatus.media_attachments.length > 0 && (
|
2020-12-03 01:28:56 +01:00
|
|
|
<TimelineAttachment status={actualStatus} width={contentWidth} />
|
2020-11-28 17:07:30 +01:00
|
|
|
)}
|
2020-12-03 01:28:56 +01:00
|
|
|
{actualStatus.card && <TimelineCard card={actualStatus.card} />}
|
2020-11-28 17:07:30 +01:00
|
|
|
</>
|
|
|
|
),
|
2020-12-03 01:28:56 +01:00
|
|
|
[actualStatus.poll?.voted]
|
2020-11-28 17:07:30 +01:00
|
|
|
)
|
|
|
|
|
2020-12-03 01:28:56 +01:00
|
|
|
return (
|
|
|
|
<View style={styles.statusView}>
|
|
|
|
{item.reblog && (
|
|
|
|
<TimelineActioned action='reblog' account={item.account} />
|
|
|
|
)}
|
|
|
|
<View style={styles.status}>
|
|
|
|
<TimelineAvatar account={actualStatus.account} />
|
|
|
|
<View style={styles.details}>
|
|
|
|
<TimelineHeaderDefault queryKey={queryKey} status={actualStatus} />
|
|
|
|
{/* Can pass toot info to next page to speed up performance */}
|
|
|
|
<Pressable onPress={pressableToot} children={childrenToot} />
|
|
|
|
<TimelineActions queryKey={queryKey} status={actualStatus} />
|
2020-10-29 14:52:28 +01:00
|
|
|
</View>
|
|
|
|
</View>
|
2020-12-03 01:28:56 +01:00
|
|
|
</View>
|
|
|
|
)
|
2020-10-29 14:52:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2020-11-04 22:26:38 +01:00
|
|
|
statusView: {
|
2020-10-29 14:52:28 +01:00
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'column',
|
2020-12-01 00:44:28 +01:00
|
|
|
padding: StyleConstants.Spacing.Global.PagePadding,
|
|
|
|
paddingBottom: StyleConstants.Spacing.M
|
2020-10-29 14:52:28 +01:00
|
|
|
},
|
2020-11-04 22:26:38 +01:00
|
|
|
status: {
|
2020-10-29 14:52:28 +01:00
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
details: {
|
2020-12-03 01:28:56 +01:00
|
|
|
flex: 1
|
2020-10-29 14:52:28 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-11-28 17:07:30 +01:00
|
|
|
export default React.memo(TimelineDefault, (prev, next) => {
|
|
|
|
let skipUpdate = true
|
2020-12-03 10:39:37 +01:00
|
|
|
skipUpdate =
|
|
|
|
prev.item.id === next.item.id &&
|
|
|
|
prev.item.replies_count === next.item.replies_count &&
|
|
|
|
prev.item.favourited === next.item.favourited &&
|
|
|
|
prev.item.reblogged === next.item.reblogged &&
|
|
|
|
prev.item.bookmarked === next.item.bookmarked &&
|
|
|
|
prev.item.poll?.voted === next.item.poll?.voted &&
|
|
|
|
prev.item.reblog?.poll?.voted === next.item.reblog?.poll?.voted
|
|
|
|
|
2020-11-28 17:07:30 +01:00
|
|
|
return skipUpdate
|
|
|
|
})
|