tooot/src/components/TootTimeline.jsx

113 lines
3.3 KiB
React
Raw Normal View History

2020-10-29 14:52:28 +01:00
import React, { useMemo } from 'react'
2020-10-30 00:10:25 +01:00
import propTypesStatus from 'src/prop-types/status'
2020-10-29 14:52:28 +01:00
import { Dimensions, Pressable, StyleSheet, View } from 'react-native'
import { useNavigation } from '@react-navigation/native'
import Reblog from './Toot/Reblog'
import Avatar from './Toot/Avatar'
import Header from './Toot/Header'
import Content from './Toot/Content'
import Poll from './Toot/Poll'
import Media from './Toot/Media'
import Card from './Toot/Card'
import Actions from './Toot/Actions'
2020-10-30 00:10:25 +01:00
export default function TootTimeline ({ toot }) {
2020-10-29 14:52:28 +01:00
const navigation = useNavigation()
let actualContent
2020-10-29 21:29:52 +01:00
if (toot.reblog) {
actualContent = toot.reblog
2020-10-29 14:52:28 +01:00
} else {
2020-10-29 21:29:52 +01:00
actualContent = toot
2020-10-29 14:52:28 +01:00
}
2020-10-29 21:29:52 +01:00
const tootView = useMemo(() => {
2020-10-29 14:52:28 +01:00
return (
<View style={styles.tootTimeline}>
2020-10-29 21:29:52 +01:00
{toot.reblog && (
2020-10-29 14:52:28 +01:00
<Reblog
2020-10-29 21:29:52 +01:00
name={toot.account.display_name || toot.account.username}
emojis={toot.account.emojis}
2020-10-29 14:52:28 +01:00
/>
)}
<View style={styles.toot}>
<Avatar
uri={actualContent.account.avatar}
id={actualContent.account.id}
/>
<View style={styles.details}>
<Header
name={
actualContent.account.display_name ||
actualContent.account.username
}
emojis={actualContent.account.emojis}
account={actualContent.account.acct}
2020-10-29 21:29:52 +01:00
created_at={toot.created_at}
application={toot.application}
2020-10-29 14:52:28 +01:00
/>
{/* Can pass toot info to next page to speed up performance */}
<Pressable
onPress={() =>
navigation.navigate('Toot', { toot: actualContent.id })
}
>
{actualContent.content ? (
<Content
content={actualContent.content}
emojis={actualContent.emojis}
mentions={actualContent.mentions}
spoiler_text={actualContent.spoiler_text}
tags={actualContent.tags}
style={{ flex: 1 }}
/>
) : (
<></>
)}
{actualContent.poll && <Poll poll={actualContent.poll} />}
{actualContent.media_attachments && (
<Media
media_attachments={actualContent.media_attachments}
sensitive={actualContent.sensitive}
width={Dimensions.get('window').width - 24 - 50 - 8}
/>
)}
{actualContent.card && <Card card={actualContent.card} />}
</Pressable>
<Actions
replies_count={actualContent.replies_count}
reblogs_count={actualContent.reblogs_count}
reblogged={actualContent.reblogged}
favourites_count={actualContent.favourites_count}
favourited={actualContent.favourited}
/>
</View>
</View>
</View>
)
})
2020-10-29 21:29:52 +01:00
return tootView
2020-10-29 14:52:28 +01:00
}
const styles = StyleSheet.create({
tootTimeline: {
flex: 1,
flexDirection: 'column',
padding: 12
},
toot: {
flex: 1,
flexDirection: 'row'
},
details: {
flex: 1,
flexGrow: 1
}
})
2020-10-30 00:10:25 +01:00
TootTimeline.propTypes = {
toot: propTypesStatus
2020-10-29 14:52:28 +01:00
}