tooot/src/components/TootTimeline.tsx

113 lines
3.4 KiB
TypeScript
Raw Normal View History

2020-10-29 14:52:28 +01:00
import React, { useMemo } from 'react'
import { Dimensions, Pressable, StyleSheet, View } from 'react-native'
import { useNavigation } from '@react-navigation/native'
2020-10-30 00:49:05 +01:00
import Actioned from './Toot/Actioned'
2020-10-29 14:52:28 +01:00
import Avatar from './Toot/Avatar'
import Header from './Toot/Header'
import Content from './Toot/Content'
import Poll from './Toot/Poll'
2020-10-30 20:03:44 +01:00
import Attachment from './Toot/Attachment'
2020-10-29 14:52:28 +01:00
import Card from './Toot/Card'
import Actions from './Toot/Actions'
2020-10-31 21:04:46 +01:00
export interface Props {
toot: mastodon.Status
}
const TootTimeline: React.FC<Props> = ({ toot }) => {
2020-10-29 14:52:28 +01:00
const navigation = useNavigation()
2020-10-31 21:04:46 +01:00
let actualContent = toot.reblog ? toot.reblog : toot
2020-10-29 14:52:28 +01:00
2020-11-01 18:15:31 +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-30 00:49:05 +01:00
<Actioned
action='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
2020-10-31 02:22:08 +01:00
onPress={() =>
navigation.navigate('Toot', { toot: actualContent.id })
}
2020-10-29 14:52:28 +01:00
>
{actualContent.content ? (
<Content
content={actualContent.content}
emojis={actualContent.emojis}
mentions={actualContent.mentions}
spoiler_text={actualContent.spoiler_text}
2020-10-31 21:04:46 +01:00
// tags={actualContent.tags}
// style={{ flex: 1 }}
2020-10-29 14:52:28 +01:00
/>
) : (
<></>
)}
{actualContent.poll && <Poll poll={actualContent.poll} />}
2020-10-30 20:03:44 +01:00
{actualContent.media_attachments.length > 0 && (
<Attachment
2020-10-29 14:52:28 +01:00
media_attachments={actualContent.media_attachments}
sensitive={actualContent.sensitive}
width={Dimensions.get('window').width - 24 - 50 - 8}
/>
)}
{actualContent.card && <Card card={actualContent.card} />}
</Pressable>
<Actions
2020-10-31 02:22:08 +01:00
id={actualContent.id}
2020-11-01 18:15:31 +01:00
url={actualContent.url}
2020-10-29 14:52:28 +01:00
replies_count={actualContent.replies_count}
reblogs_count={actualContent.reblogs_count}
reblogged={actualContent.reblogged}
favourites_count={actualContent.favourites_count}
favourited={actualContent.favourited}
bookmarked={actualContent.bookmarked}
2020-10-29 14:52:28 +01:00
/>
</View>
</View>
</View>
)
2020-11-01 18:15:31 +01:00
}, [toot])
2020-10-29 14:52:28 +01:00
2020-11-01 18:15:31 +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-31 21:04:46 +01:00
export default TootTimeline