mirror of
https://github.com/tooot-app/app
synced 2025-02-20 13:50:49 +01:00
Notification done
This commit is contained in:
parent
301772e735
commit
2fae98cb9e
82
src/components/Toot/Actioned.jsx
Normal file
82
src/components/Toot/Actioned.jsx
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import propTypesEmoji from 'src/prop-types/emoji'
|
||||||
|
import { StyleSheet, Text, View } from 'react-native'
|
||||||
|
import { Feather } from '@expo/vector-icons'
|
||||||
|
|
||||||
|
import Emojis from './Emojis'
|
||||||
|
|
||||||
|
export default function Actioned ({
|
||||||
|
action,
|
||||||
|
name,
|
||||||
|
emojis,
|
||||||
|
notification = false
|
||||||
|
}) {
|
||||||
|
let icon
|
||||||
|
let content
|
||||||
|
switch (action) {
|
||||||
|
case 'favourite':
|
||||||
|
icon = (
|
||||||
|
<Feather name='heart' size={12} color='black' style={styles.icon} />
|
||||||
|
)
|
||||||
|
content = `${name} 喜欢了你的嘟嘟`
|
||||||
|
break
|
||||||
|
case 'follow':
|
||||||
|
icon = (
|
||||||
|
<Feather name='user-plus' size={12} color='black' style={styles.icon} />
|
||||||
|
)
|
||||||
|
content = `${name} 开始关注你`
|
||||||
|
break
|
||||||
|
case 'poll':
|
||||||
|
icon = (
|
||||||
|
<Feather
|
||||||
|
name='bar-chart-2'
|
||||||
|
size={12}
|
||||||
|
color='black'
|
||||||
|
style={styles.icon}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
content = `你参与的投票已结束`
|
||||||
|
break
|
||||||
|
case 'reblog':
|
||||||
|
icon = (
|
||||||
|
<Feather name='repeat' size={12} color='black' style={styles.icon} />
|
||||||
|
)
|
||||||
|
content = `${name} 转嘟了${notification ? '你的嘟嘟' : ''}`
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.actioned}>
|
||||||
|
{icon}
|
||||||
|
{content ? (
|
||||||
|
<View style={styles.content}>
|
||||||
|
<Emojis content={content} emojis={emojis} dimension={12} />
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
actioned: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
marginBottom: 8
|
||||||
|
},
|
||||||
|
icon: {
|
||||||
|
marginLeft: 50 - 12,
|
||||||
|
marginRight: 8
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
flexDirection: 'row'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Actioned.propTypes = {
|
||||||
|
action: PropTypes.oneOf(['favourite', 'follow', 'poll', 'reblog']).isRequired,
|
||||||
|
name: PropTypes.string,
|
||||||
|
emojis: PropTypes.arrayOf(propTypesEmoji),
|
||||||
|
notification: PropTypes.bool
|
||||||
|
}
|
@ -5,6 +5,7 @@ import { useNavigation } from '@react-navigation/native'
|
|||||||
|
|
||||||
export default function Avatar ({ uri, id }) {
|
export default function Avatar ({ uri, id }) {
|
||||||
const navigation = useNavigation()
|
const navigation = useNavigation()
|
||||||
|
// Need to fix go back root
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
style={styles.avatar}
|
style={styles.avatar}
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import propTypesEmoji from 'src/prop-types/emoji'
|
|
||||||
import { StyleSheet, Text, View } from 'react-native'
|
|
||||||
import { Feather } from '@expo/vector-icons'
|
|
||||||
|
|
||||||
import Emojis from './Emojis'
|
|
||||||
|
|
||||||
export default function Reblog ({ name, emojis }) {
|
|
||||||
return (
|
|
||||||
<View style={styles.reblog}>
|
|
||||||
<Feather name='repeat' size={12} color='black' style={styles.icon} />
|
|
||||||
<View style={styles.name}>
|
|
||||||
<Emojis content={name} emojis={emojis} dimension={12} />
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
reblog: {
|
|
||||||
flexDirection: 'row',
|
|
||||||
marginBottom: 8
|
|
||||||
},
|
|
||||||
icon: {
|
|
||||||
marginLeft: 50 - 12,
|
|
||||||
marginRight: 8
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
flexDirection: 'row'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
Reblog.propTypes = {
|
|
||||||
name: PropTypes.string.isRequired,
|
|
||||||
emojis: PropTypes.arrayOf(propTypesEmoji)
|
|
||||||
}
|
|
@ -1,10 +1,9 @@
|
|||||||
import React, { useMemo } from 'react'
|
import React, { useMemo } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import propTypesNotification from 'src/prop-types/notification'
|
import propTypesNotification from 'src/prop-types/notification'
|
||||||
import { Dimensions, Pressable, StyleSheet, View } from 'react-native'
|
import { Dimensions, Pressable, StyleSheet, Text, View } from 'react-native'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
|
|
||||||
import Reblog from './Toot/Reblog'
|
import Actioned from './Toot/Actioned'
|
||||||
import Avatar from './Toot/Avatar'
|
import Avatar from './Toot/Avatar'
|
||||||
import Header from './Toot/Header'
|
import Header from './Toot/Header'
|
||||||
import Content from './Toot/Content'
|
import Content from './Toot/Content'
|
||||||
@ -15,74 +14,66 @@ import Actions from './Toot/Actions'
|
|||||||
|
|
||||||
export default function TootNotification ({ toot }) {
|
export default function TootNotification ({ toot }) {
|
||||||
const navigation = useNavigation()
|
const navigation = useNavigation()
|
||||||
|
const actualAccount = toot.status ? toot.status.account : toot.account
|
||||||
let actualContent
|
|
||||||
if (toot.reblog) {
|
|
||||||
actualContent = toot.reblog
|
|
||||||
} else {
|
|
||||||
actualContent = toot
|
|
||||||
}
|
|
||||||
|
|
||||||
const tootView = useMemo(() => {
|
const tootView = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
<View style={styles.tootTimeline}>
|
<View style={styles.tootNotification}>
|
||||||
{toot.reblog && (
|
<Actioned
|
||||||
<Reblog
|
action={toot.type}
|
||||||
name={toot.account.display_name || toot.account.username}
|
name={toot.account.display_name || toot.account.username}
|
||||||
emojis={toot.account.emojis}
|
emojis={toot.account.emojis}
|
||||||
/>
|
notification
|
||||||
)}
|
/>
|
||||||
|
|
||||||
<View style={styles.toot}>
|
<View style={styles.toot}>
|
||||||
<Avatar
|
<Avatar uri={actualAccount.avatar} id={actualAccount.id} />
|
||||||
uri={actualContent.account.avatar}
|
|
||||||
id={actualContent.account.id}
|
|
||||||
/>
|
|
||||||
<View style={styles.details}>
|
<View style={styles.details}>
|
||||||
<Header
|
<Header
|
||||||
name={
|
name={actualAccount.display_name || actualAccount.username}
|
||||||
actualContent.account.display_name ||
|
emojis={actualAccount.emojis}
|
||||||
actualContent.account.username
|
account={actualAccount.acct}
|
||||||
}
|
|
||||||
emojis={actualContent.account.emojis}
|
|
||||||
account={actualContent.account.acct}
|
|
||||||
created_at={toot.created_at}
|
created_at={toot.created_at}
|
||||||
application={toot.application}
|
|
||||||
/>
|
/>
|
||||||
{/* Can pass toot info to next page to speed up performance */}
|
{/* Can pass toot info to next page to speed up performance */}
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={() =>
|
onPress={() => navigation.navigate('Toot', { toot: toot.id })}
|
||||||
navigation.navigate('Toot', { toot: actualContent.id })
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{actualContent.content ? (
|
{toot.status ? (
|
||||||
<Content
|
<>
|
||||||
content={actualContent.content}
|
{toot.status.content && (
|
||||||
emojis={actualContent.emojis}
|
<Content
|
||||||
mentions={actualContent.mentions}
|
content={toot.status.content}
|
||||||
spoiler_text={actualContent.spoiler_text}
|
emojis={toot.status.emojis}
|
||||||
tags={actualContent.tags}
|
mentions={toot.status.mentions}
|
||||||
style={{ flex: 1 }}
|
spoiler_text={toot.status.spoiler_text}
|
||||||
/>
|
tags={toot.status.tags}
|
||||||
|
style={{ flex: 1 }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{toot.status.poll && <Poll poll={toot.status.poll} />}
|
||||||
|
{toot.status.media_attachments && (
|
||||||
|
<Media
|
||||||
|
media_attachments={toot.status.media_attachments}
|
||||||
|
sensitive={toot.status.sensitive}
|
||||||
|
width={Dimensions.get('window').width - 24 - 50 - 8}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{toot.status.card && <Card card={toot.status.card} />}
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
{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>
|
</Pressable>
|
||||||
<Actions
|
{toot.status && (
|
||||||
replies_count={actualContent.replies_count}
|
<Actions
|
||||||
reblogs_count={actualContent.reblogs_count}
|
replies_count={toot.status.replies_count}
|
||||||
reblogged={actualContent.reblogged}
|
reblogs_count={toot.status.reblogs_count}
|
||||||
favourites_count={actualContent.favourites_count}
|
reblogged={toot.status.reblogged}
|
||||||
favourited={actualContent.favourited}
|
favourites_count={toot.status.favourites_count}
|
||||||
/>
|
favourited={toot.status.favourited}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
@ -93,7 +84,7 @@ export default function TootNotification ({ toot }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
tootTimeline: {
|
tootNotification: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
padding: 12
|
padding: 12
|
||||||
|
@ -3,7 +3,7 @@ import propTypesStatus from 'src/prop-types/status'
|
|||||||
import { Dimensions, Pressable, StyleSheet, View } from 'react-native'
|
import { Dimensions, Pressable, StyleSheet, View } from 'react-native'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
|
|
||||||
import Reblog from './Toot/Reblog'
|
import Actioned from './Toot/Actioned'
|
||||||
import Avatar from './Toot/Avatar'
|
import Avatar from './Toot/Avatar'
|
||||||
import Header from './Toot/Header'
|
import Header from './Toot/Header'
|
||||||
import Content from './Toot/Content'
|
import Content from './Toot/Content'
|
||||||
@ -26,7 +26,8 @@ export default function TootTimeline ({ toot }) {
|
|||||||
return (
|
return (
|
||||||
<View style={styles.tootTimeline}>
|
<View style={styles.tootTimeline}>
|
||||||
{toot.reblog && (
|
{toot.reblog && (
|
||||||
<Reblog
|
<Actioned
|
||||||
|
action='reblog'
|
||||||
name={toot.account.display_name || toot.account.username}
|
name={toot.account.display_name || toot.account.username}
|
||||||
emojis={toot.account.emojis}
|
emojis={toot.account.emojis}
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user