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

116 lines
3.5 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-02-13 01:26:02 +01:00
import Icon from '@components/Icon'
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
2020-12-13 14:04:25 +01:00
import { StyleConstants } from '@utils/styles/constants'
2021-02-13 01:26:02 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
2022-08-08 23:00:46 +02:00
import React from 'react'
2021-04-09 21:43:12 +02:00
import { useTranslation } from 'react-i18next'
2022-08-08 23:00:46 +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-02-13 01:26:02 +01:00
import HeaderSharedVisibility from './HeaderShared/Visibility'
2020-10-25 01:35:41 +02:00
2020-10-31 21:04:46 +01:00
export interface Props {
2021-01-07 19:13:09 +01:00
queryKey?: QueryKeyTimeline
2020-12-03 01:28:56 +01:00
status: Mastodon.Status
highlighted: boolean
2020-10-31 21:04:46 +01:00
}
2022-06-06 22:49:43 +02:00
const TimelineHeaderDefault = ({ queryKey, status, highlighted }: Props) => {
2022-06-26 22:56:21 +02:00
if (!queryKey) return null
2022-06-06 22:49:43 +02:00
const { t } = useTranslation('componentContextMenu')
2022-04-30 21:29:08 +02:00
const { colors } = useTheme()
2021-01-30 01:29:15 +01:00
const actions: ContextMenuAction[] = []
const shareOnPress =
status.visibility !== 'direct'
? contextMenuShare({
actions,
type: 'status',
url: status.url || status.uri
})
: null
const statusOnPress = contextMenuStatus({
actions,
status,
queryKey
})
const accountOnPress = contextMenuAccount({
actions,
type: 'status',
queryKey,
id: status.account.id
})
const instanceOnPress = contextMenuInstance({
actions,
status,
queryKey
})
2022-06-06 22:49:43 +02:00
2022-04-30 21:29:08 +02:00
return (
<View style={{ flex: 1, flexDirection: 'row' }}>
2022-06-06 22:49:43 +02:00
<View style={{ flex: 7 }}>
2022-04-30 21:29:08 +02:00
<HeaderSharedAccount account={status.account} />
<View
style={{
flexDirection: 'row',
alignItems: 'center',
marginTop: StyleConstants.Spacing.XS,
marginBottom: StyleConstants.Spacing.S
}}
>
<HeaderSharedCreated
created_at={status.created_at}
edited_at={status.edited_at}
highlighted={highlighted}
2021-02-27 16:33:54 +01:00
/>
2022-04-30 21:29:08 +02:00
<HeaderSharedVisibility visibility={status.visibility} />
<HeaderSharedMuted muted={status.muted} />
<HeaderSharedApplication application={status.application} />
</View>
2021-02-27 16:33:54 +01:00
</View>
2020-10-25 01:35:41 +02:00
2022-04-30 21:29:08 +02:00
{queryKey ? (
<Pressable
2022-06-06 22:49:43 +02:00
accessibilityHint={t('accessibilityHint')}
2022-04-30 21:29:08 +02:00
style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
2022-06-06 22:49:43 +02:00
marginBottom: StyleConstants.Spacing.L
2022-04-30 21:29:08 +02:00
}}
hitSlop={StyleConstants.Font.Size.M}
2022-06-06 22:49:43 +02:00
>
<ContextMenu
2022-06-07 20:07:14 +02:00
dropdownMenuMode
actions={actions}
onPress={({ nativeEvent: { index } }) => {
for (const on of [shareOnPress, statusOnPress, accountOnPress, instanceOnPress]) {
on && on(index)
}
}}
2022-06-06 22:49:43 +02:00
children={
<Icon
name='MoreHorizontal'
color={colors.secondary}
size={StyleConstants.Font.Size.L}
/>
}
style={{ width: '100%', height: '100%', paddingHorizontal: StyleConstants.Font.Size.M }}
2022-06-06 22:49:43 +02:00
/>
</Pressable>
2022-04-30 21:29:08 +02:00
) : null}
</View>
)
}
2020-10-25 01:35:41 +02:00
2021-02-27 16:33:54 +01:00
export default TimelineHeaderDefault