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

164 lines
4.9 KiB
TypeScript
Raw Normal View History

import contextMenuAccount from '@components/ContextMenu/account'
import contextMenuInstance from '@components/ContextMenu/instance'
import contextMenuShare from '@components/ContextMenu/share'
import contextMenuStatus from '@components/ContextMenu/status'
2021-01-30 02:03:39 +01:00
import Icon from '@components/Icon'
import {
RelationshipIncoming,
RelationshipOutgoing
} from '@components/Relationship'
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'
import React, { useMemo } from 'react'
2022-04-30 21:29:08 +02:00
import { Pressable, View } from 'react-native'
import ContextMenu, { ContextMenuAction } from 'react-native-context-menu-view'
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 {
queryKey?: QueryKeyTimeline
notification: Mastodon.Notification
}
const TimelineHeaderNotification = ({ queryKey, notification }: Props) => {
2022-04-30 21:29:08 +02:00
const { colors } = useTheme()
2021-01-30 02:03:39 +01:00
const contextMenuActions: ContextMenuAction[] = []
const status = notification.status
const shareOnPress =
status && status?.visibility !== 'direct'
? contextMenuShare({
actions: contextMenuActions,
type: 'status',
url: status.url || status.uri
})
: null
const statusOnPress = contextMenuStatus({
actions: contextMenuActions,
status,
queryKey
})
const accountOnPress = contextMenuAccount({
actions: contextMenuActions,
type: 'status',
queryKey,
id: status?.account.id
})
const instanceOnPress = contextMenuInstance({
actions: contextMenuActions,
status,
queryKey
})
2022-06-07 20:07:14 +02:00
2022-04-30 21:29:08 +02: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
}}
children={
2022-06-07 20:07:14 +02:00
<ContextMenu
dropdownMenuMode
actions={contextMenuActions}
onPress={({ nativeEvent: { index } }) => {
for (const on of [
shareOnPress,
statusOnPress,
accountOnPress,
instanceOnPress
]) {
on && on(index)
}
}}
2022-06-07 20:07:14 +02:00
children={
<Icon
name='MoreHorizontal'
color={colors.secondary}
size={StyleConstants.Font.Size.L}
/>
}
2022-04-30 21:29:08 +02:00
/>
}
/>
)
}
}
}, [notification.type])
2021-02-27 16:33:54 +01:00
2022-04-30 21:29:08 +02:00
return (
<View style={{ flex: 1, flexDirection: 'row' }}>
<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 })}
/>
2021-02-27 16:33:54 +01:00
<View
style={{
2022-04-30 21:29:08 +02:00
flexDirection: 'row',
alignItems: 'center',
marginTop: StyleConstants.Spacing.XS,
marginBottom: StyleConstants.Spacing.S
2021-02-27 16:33:54 +01:00
}}
>
2022-04-30 21:29:08 +02:00
<HeaderSharedCreated
2022-06-03 23:27:22 +02:00
created_at={
notification.status?.created_at || notification.created_at
}
2022-04-30 21:29:08 +02:00
edited_at={notification.status?.edited_at}
2021-02-27 16:33:54 +01:00
/>
2022-04-30 21:29:08 +02:00
{notification.status?.visibility ? (
<HeaderSharedVisibility
visibility={notification.status.visibility}
2021-01-30 02:03:39 +01:00
/>
2022-04-30 21:29:08 +02:00
) : null}
<HeaderSharedMuted muted={notification.status?.muted} />
<HeaderSharedApplication
application={notification.status?.application}
/>
</View>
</View>
2022-04-30 21:29:08 +02:00
<View
style={[
{ marginLeft: StyleConstants.Spacing.M },
notification.type === 'follow' ||
notification.type === 'follow_request'
? { flexShrink: 1 }
: { flex: 1 }
]}
>
{actions}
</View>
</View>
)
}
2021-02-27 16:33:54 +01:00
export default TimelineHeaderNotification