tooot/src/components/Timeline/Shared/HeaderNotification.tsx

133 lines
3.9 KiB
TypeScript
Raw Normal View History

2021-01-30 02:03:39 +01:00
import Icon from '@components/Icon'
import {
RelationshipIncoming,
RelationshipOutgoing
} from '@components/Relationship'
import { useNavigation } from '@react-navigation/native'
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
2021-01-01 16:48:16 +01:00
import { StyleConstants } from '@utils/styles/constants'
2021-01-30 02:03:39 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
2021-01-12 00:12:44 +01:00
import React, { useMemo } from 'react'
2021-01-30 02:03:39 +01:00
import { Pressable, StyleSheet, View } from 'react-native'
import HeaderSharedAccount from './HeaderShared/Account'
2021-01-01 23:10:47 +01:00
import HeaderSharedApplication from './HeaderShared/Application'
import HeaderSharedCreated from './HeaderShared/Created'
2021-01-11 21:36:57 +01:00
import HeaderSharedMuted from './HeaderShared/Muted'
2021-01-30 02:03:39 +01:00
import HeaderSharedVisibility from './HeaderShared/Visibility'
export interface Props {
2021-01-12 00:12:44 +01:00
queryKey: QueryKeyTimeline
notification: Mastodon.Notification
}
2021-02-27 16:33:54 +01:00
const TimelineHeaderNotification = React.memo(
({ queryKey, notification }: Props) => {
const navigation = useNavigation()
const { theme } = useTheme()
2021-01-30 02:03:39 +01:00
2021-02-27 16:33:54 +01:00
const actions = useMemo(() => {
switch (notification.type) {
case 'follow':
return <RelationshipOutgoing id={notification.account.id} />
case 'follow_request':
return <RelationshipIncoming id={notification.account.id} />
default:
if (notification.status) {
return (
<Pressable
style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
paddingBottom: StyleConstants.Spacing.S
}}
onPress={() =>
navigation.navigate('Screen-Actions', {
queryKey,
status: notification.status,
url: notification.status?.url || notification.status?.uri,
type: 'status'
})
}
children={
<Icon
name='MoreHorizontal'
color={theme.secondary}
size={StyleConstants.Font.Size.L}
/>
}
/>
)
}
}
}, [notification.type])
return (
<View style={styles.base}>
<View
style={{
flex:
notification.type === 'follow' ||
notification.type === 'follow_request'
? 1
: 4
}}
>
<HeaderSharedAccount
account={
notification.status
? notification.status.account
: notification.account
}
{...((notification.type === 'follow' ||
notification.type === 'follow_request') && { withoutName: true })}
/>
<View style={styles.meta}>
<HeaderSharedCreated created_at={notification.created_at} />
{notification.status?.visibility ? (
<HeaderSharedVisibility
visibility={notification.status.visibility}
/>
) : null}
<HeaderSharedMuted muted={notification.status?.muted} />
<HeaderSharedApplication
application={notification.status?.application}
2021-01-30 02:03:39 +01:00
/>
2021-02-27 16:33:54 +01:00
</View>
</View>
2021-01-30 02:03:39 +01:00
2021-02-27 16:33:54 +01:00
<View
style={[
styles.relationship,
2021-01-12 00:12:44 +01:00
notification.type === 'follow' ||
notification.type === 'follow_request'
2021-02-27 16:33:54 +01:00
? { flexShrink: 1 }
: { flex: 1 }
]}
>
{actions}
</View>
</View>
2021-02-27 16:33:54 +01:00
)
},
() => true
)
const styles = StyleSheet.create({
base: {
flex: 1,
2021-01-12 00:12:44 +01:00
flexDirection: 'row'
},
meta: {
flexDirection: 'row',
alignItems: 'center',
marginTop: StyleConstants.Spacing.XS,
marginBottom: StyleConstants.Spacing.S
},
relationship: {
marginLeft: StyleConstants.Spacing.M
}
})
2021-02-27 16:33:54 +01:00
export default TimelineHeaderNotification