tooot/src/components/Timelines/Timeline/Default.tsx

130 lines
3.8 KiB
TypeScript
Raw Normal View History

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-11-23 00:07:32 +01:00
import Actioned from './Shared/Actioned'
import Avatar from './Shared/Avatar'
import HeaderDefault from './Shared/HeaderDefault'
import Content from './Shared/Content'
import Poll from './Shared/Poll'
import Attachment from './Shared/Attachment'
import Card from './Shared/Card'
import ActionsStatus from './Shared/ActionsStatus'
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
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-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(
() => (
<>
{actualStatus.content ? (
<Content
content={actualStatus.content}
emojis={actualStatus.emojis}
mentions={actualStatus.mentions}
spoiler_text={actualStatus.spoiler_text}
// tags={actualStatus.tags}
/>
) : (
<></>
)}
{actualStatus.poll && <Poll poll={actualStatus.poll} />}
{actualStatus.media_attachments.length > 0 && (
<Attachment
media_attachments={actualStatus.media_attachments}
sensitive={actualStatus.sensitive}
width={
2020-11-30 00:24:53 +01:00
Dimensions.get('window').width - StyleConstants.Spacing.M * 2 - 50 - 8
2020-11-28 17:07:30 +01:00
}
/>
)}
{actualStatus.card && <Card card={actualStatus.card} />}
</>
),
[]
)
const statusView = useMemo(() => {
2020-10-29 14:52:28 +01:00
return (
<View style={styles.statusView}>
2020-11-22 00:46:23 +01:00
{item.reblog && (
2020-10-30 00:49:05 +01:00
<Actioned
action='reblog'
2020-11-22 00:46:23 +01:00
name={item.account.display_name || item.account.username}
emojis={item.account.emojis}
2020-10-29 14:52:28 +01:00
/>
)}
<View style={styles.status}>
2020-10-29 14:52:28 +01:00
<Avatar
uri={actualStatus.account.avatar}
id={actualStatus.account.id}
2020-10-29 14:52:28 +01:00
/>
<View style={styles.details}>
2020-11-23 00:07:32 +01:00
<HeaderDefault
2020-11-06 18:40:14 +01:00
queryKey={queryKey}
accountId={actualStatus.account.id}
domain={actualStatus.uri.split(new RegExp(/\/\/(.*?)\//))[1]}
2020-10-29 14:52:28 +01:00
name={
actualStatus.account.display_name ||
actualStatus.account.username
2020-10-29 14:52:28 +01:00
}
emojis={actualStatus.account.emojis}
account={actualStatus.account.acct}
2020-11-22 00:46:23 +01:00
created_at={item.created_at}
2020-11-29 18:08:31 +01:00
visibility={item.visibility}
2020-11-22 00:46:23 +01:00
application={item.application}
2020-10-29 14:52:28 +01:00
/>
{/* Can pass toot info to next page to speed up performance */}
2020-11-28 17:07:30 +01:00
<Pressable onPress={pressableToot} children={childrenToot} />
<ActionsStatus queryKey={queryKey} status={actualStatus} />
2020-10-29 14:52:28 +01:00
</View>
</View>
</View>
)
2020-11-22 00:46:23 +01:00
}, [item])
2020-10-29 14:52:28 +01:00
return statusView
2020-10-29 14:52:28 +01:00
}
const styles = StyleSheet.create({
statusView: {
2020-10-29 14:52:28 +01:00
flex: 1,
flexDirection: 'column',
2020-11-30 00:24:53 +01:00
padding: StyleConstants.Spacing.Global.PagePadding
2020-10-29 14:52:28 +01:00
},
status: {
2020-10-29 14:52:28 +01:00
flex: 1,
flexDirection: 'row'
},
details: {
flex: 1,
flexGrow: 1
}
})
2020-11-28 17:07:30 +01:00
export default React.memo(TimelineDefault, (prev, next) => {
let skipUpdate = true
skipUpdate = prev.item.id === next.item.id
skipUpdate = prev.item.replies_count === next.item.replies_count
skipUpdate = prev.item.favourited === next.item.favourited
skipUpdate = prev.item.reblogged === next.item.reblogged
skipUpdate = prev.item.bookmarked === next.item.bookmarked
return skipUpdate
})