2020-10-25 01:35:41 +02:00
|
|
|
import React, { useEffect, useState } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { StyleSheet, Text, View } from 'react-native'
|
|
|
|
|
|
|
|
import Emojis from './Emojis'
|
|
|
|
import relativeTime from 'src/utils/relativeTime'
|
|
|
|
|
|
|
|
export default function Header ({
|
|
|
|
name,
|
|
|
|
emojis,
|
|
|
|
account,
|
|
|
|
created_at,
|
|
|
|
application
|
|
|
|
}) {
|
|
|
|
const [since, setSince] = useState(relativeTime(created_at))
|
|
|
|
|
2020-10-28 00:02:37 +01:00
|
|
|
// causing full re-render
|
2020-10-25 01:35:41 +02:00
|
|
|
useEffect(() => {
|
2020-10-26 00:27:53 +01:00
|
|
|
setTimeout(() => {
|
2020-10-25 01:35:41 +02:00
|
|
|
setSince(relativeTime(created_at))
|
|
|
|
}, 1000)
|
2020-10-28 00:02:37 +01:00
|
|
|
}, [since])
|
2020-10-25 01:35:41 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<View style={styles.names}>
|
|
|
|
<View style={styles.name}>
|
|
|
|
<Emojis content={name} emojis={emojis} dimension={14} />
|
|
|
|
</View>
|
2020-10-29 14:52:28 +01:00
|
|
|
<Text style={styles.account} numberOfLines={1}>
|
|
|
|
@{account}
|
|
|
|
</Text>
|
2020-10-25 01:35:41 +02:00
|
|
|
</View>
|
|
|
|
<View style={styles.meta}>
|
|
|
|
<View>
|
|
|
|
<Text style={styles.created_at}>{since}</Text>
|
|
|
|
</View>
|
|
|
|
{application && application.name !== 'Web' && (
|
|
|
|
<View>
|
|
|
|
<Text
|
|
|
|
onPress={() => Linking.openURL(application.website)}
|
|
|
|
style={styles.application}
|
|
|
|
>
|
|
|
|
{application.name}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
names: {
|
2020-10-26 00:27:53 +01:00
|
|
|
flexDirection: 'row'
|
2020-10-25 01:35:41 +02:00
|
|
|
},
|
|
|
|
name: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
marginRight: 8
|
|
|
|
},
|
|
|
|
account: {
|
|
|
|
fontSize: 12,
|
|
|
|
lineHeight: 14
|
|
|
|
},
|
|
|
|
meta: {
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
created_at: {
|
|
|
|
fontSize: 12,
|
|
|
|
lineHeight: 12,
|
2020-10-26 00:27:53 +01:00
|
|
|
marginTop: 8,
|
|
|
|
marginBottom: 8,
|
2020-10-25 01:35:41 +02:00
|
|
|
marginRight: 8
|
|
|
|
},
|
|
|
|
application: {
|
|
|
|
fontSize: 12,
|
|
|
|
lineHeight: 11
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Header.propTypes = {
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
emojis: Emojis.propTypes.emojis,
|
|
|
|
account: PropTypes.string.isRequired,
|
|
|
|
created_at: PropTypes.string.isRequired,
|
|
|
|
application: PropTypes.exact({
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
website: PropTypes.string
|
|
|
|
})
|
|
|
|
}
|