tooot/src/components/Timeline/Default.tsx

166 lines
5.2 KiB
TypeScript
Raw Normal View History

2021-01-24 02:25:43 +01:00
import analytics from '@components/analytics'
2021-02-08 23:47:20 +01:00
import TimelineActioned from '@components/Timeline/Shared/Actioned'
import TimelineActions from '@components/Timeline/Shared/Actions'
import TimelineAttachment from '@components/Timeline/Shared/Attachment'
import TimelineAvatar from '@components/Timeline/Shared/Avatar'
import TimelineCard from '@components/Timeline/Shared/Card'
import TimelineContent from '@components/Timeline/Shared/Content'
import TimelineHeaderDefault from '@components/Timeline/Shared/HeaderDefault'
import TimelinePoll from '@components/Timeline/Shared/Poll'
2020-12-30 14:33:33 +01:00
import { useNavigation } from '@react-navigation/native'
2021-01-24 02:25:43 +01:00
import { StackNavigationProp } from '@react-navigation/stack'
2021-01-07 19:13:09 +01:00
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
2021-02-20 19:12:44 +01:00
import { getInstanceAccount } from '@utils/slices/instancesSlice'
2020-12-13 14:04:25 +01:00
import { StyleConstants } from '@utils/styles/constants'
2021-02-08 23:47:20 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
2021-02-17 21:39:38 +01:00
import { uniqBy } from 'lodash'
2020-12-30 14:33:33 +01:00
import React, { useCallback } from 'react'
import { Pressable, StyleSheet, View } from 'react-native'
2020-12-20 17:53:24 +01:00
import { useSelector } from 'react-redux'
2021-03-15 00:18:44 +01:00
import TimelineActionsUsers from './Shared/ActionsUsers'
2021-03-14 01:35:38 +01:00
import TimelineFullConversation from './Shared/FullConversation'
2020-10-29 14:52:28 +01:00
2020-10-31 21:04:46 +01:00
export interface Props {
2021-03-09 10:35:53 +01:00
item: Mastodon.Status & { _pinned?: boolean } // For account page, internal property
2021-01-07 19:13:09 +01:00
queryKey?: QueryKeyTimeline
2021-02-13 01:26:02 +01:00
rootQueryKey?: QueryKeyTimeline
2021-01-24 02:25:43 +01:00
origin?: string
2020-12-12 22:19:18 +01:00
highlighted?: boolean
2021-01-04 18:29:02 +01:00
disableDetails?: boolean
disableOnPress?: boolean
2020-10-31 21:04:46 +01:00
}
2020-11-23 00:07:32 +01:00
// When the poll is long
2020-12-12 22:19:18 +01:00
const TimelineDefault: React.FC<Props> = ({
item,
queryKey,
2021-02-13 01:26:02 +01:00
rootQueryKey,
2021-01-24 02:25:43 +01:00
origin,
2021-01-04 18:29:02 +01:00
highlighted = false,
disableDetails = false,
2021-03-09 10:35:53 +01:00
disableOnPress = false
2020-12-12 22:19:18 +01:00
}) => {
2021-02-08 23:47:20 +01:00
const { theme } = useTheme()
2021-03-06 21:01:38 +01:00
const instanceAccount = useSelector(getInstanceAccount, () => true)
2021-01-24 02:25:43 +01:00
const navigation = useNavigation<
2021-01-30 01:29:15 +01:00
StackNavigationProp<Nav.TabLocalStackParamList>
2021-01-24 02:25:43 +01:00
>()
2020-10-29 14:52:28 +01:00
2020-11-22 00:46:23 +01:00
let actualStatus = item.reblog ? item.reblog : item
2020-10-29 14:52:28 +01:00
2021-01-24 02:25:43 +01:00
const onPress = useCallback(() => {
analytics('timeline_default_press', {
page: queryKey ? queryKey[1].page : origin
})
!disableOnPress &&
2020-12-19 18:21:37 +01:00
!highlighted &&
2021-01-30 01:29:15 +01:00
navigation.push('Tab-Shared-Toot', {
2021-02-13 01:26:02 +01:00
toot: actualStatus,
rootQueryKey: queryKey
2021-01-24 02:25:43 +01:00
})
}, [])
2020-12-27 18:43:49 +01:00
return (
2021-01-24 02:25:43 +01:00
<Pressable
style={[
styles.statusView,
{
backgroundColor: theme.backgroundDefault,
2021-01-24 02:25:43 +01:00
paddingBottom:
disableDetails && disableOnPress
? StyleConstants.Spacing.Global.PagePadding
: 0
}
]}
onPress={onPress}
>
2020-12-27 18:43:49 +01:00
{item.reblog ? (
<TimelineActioned action='reblog' account={item.account} />
2021-03-09 10:35:53 +01:00
) : item._pinned ? (
2020-12-27 18:43:49 +01:00
<TimelineActioned action='pinned' account={item.account} />
) : null}
<View style={styles.header}>
<TimelineAvatar
2021-01-04 18:29:02 +01:00
queryKey={disableOnPress ? undefined : queryKey}
2020-12-27 18:43:49 +01:00
account={actualStatus.account}
/>
<TimelineHeaderDefault
2021-01-04 18:29:02 +01:00
queryKey={disableOnPress ? undefined : queryKey}
2021-02-13 01:26:02 +01:00
rootQueryKey={disableOnPress ? undefined : rootQueryKey}
2020-12-27 18:43:49 +01:00
status={actualStatus}
/>
2020-12-27 18:43:49 +01:00
</View>
2020-12-12 22:19:18 +01:00
<View
2020-12-13 23:02:54 +01:00
style={{
paddingTop: highlighted ? StyleConstants.Spacing.S : 0,
paddingLeft: highlighted
? 0
2020-12-19 01:57:57 +01:00
: StyleConstants.Avatar.M + StyleConstants.Spacing.S
2020-12-13 23:02:54 +01:00
}}
2020-12-12 22:19:18 +01:00
>
2021-02-08 23:47:20 +01:00
{typeof actualStatus.content === 'string' &&
actualStatus.content.length > 0 && (
<TimelineContent
status={actualStatus}
highlighted={highlighted}
disableDetails={disableDetails}
/>
)}
2021-01-11 21:36:57 +01:00
{queryKey && actualStatus.poll ? (
2020-12-19 18:21:37 +01:00
<TimelinePoll
queryKey={queryKey}
2021-02-13 01:26:02 +01:00
rootQueryKey={rootQueryKey}
2021-01-11 21:36:57 +01:00
statusId={actualStatus.id}
2020-12-19 18:21:37 +01:00
poll={actualStatus.poll}
reblog={item.reblog ? true : false}
2021-02-20 19:12:44 +01:00
sameAccount={actualStatus.account.id === instanceAccount?.id}
2020-12-19 18:21:37 +01:00
/>
2021-01-11 21:36:57 +01:00
) : null}
2021-02-11 01:33:31 +01:00
{!disableDetails &&
Array.isArray(actualStatus.media_attachments) &&
actualStatus.media_attachments.length ? (
2020-12-30 14:33:33 +01:00
<TimelineAttachment status={actualStatus} />
2021-02-11 01:33:31 +01:00
) : null}
2021-01-04 18:29:02 +01:00
{!disableDetails && actualStatus.card && (
<TimelineCard card={actualStatus.card} />
)}
2021-03-14 21:48:28 +01:00
<TimelineFullConversation queryKey={queryKey} status={actualStatus} />
2020-12-12 22:19:18 +01:00
</View>
2021-03-15 00:18:44 +01:00
<TimelineActionsUsers status={actualStatus} highlighted={highlighted} />
2021-01-04 18:29:02 +01:00
{queryKey && !disableDetails && (
2021-03-16 23:15:37 +01:00
<TimelineActions
queryKey={queryKey}
rootQueryKey={rootQueryKey}
highlighted={highlighted}
status={actualStatus}
accts={uniqBy(
([actualStatus.account] as Mastodon.Account[] & Mastodon.Mention[])
.concat(actualStatus.mentions)
.filter(d => d?.id !== instanceAccount?.id),
2021-03-20 17:51:38 +01:00
d => d?.id
).map(d => d?.acct)}
2021-03-16 23:15:37 +01:00
reblog={item.reblog ? true : false}
/>
)}
2020-12-27 18:43:49 +01:00
</Pressable>
2020-12-03 01:28:56 +01:00
)
2020-10-29 14:52:28 +01:00
}
const styles = StyleSheet.create({
statusView: {
2020-12-01 00:44:28 +01:00
padding: StyleConstants.Spacing.Global.PagePadding,
2021-01-23 02:41:50 +01:00
paddingBottom: 0
2020-10-29 14:52:28 +01:00
},
2020-12-12 22:19:18 +01:00
header: {
2020-10-29 14:52:28 +01:00
flex: 1,
2020-12-12 22:19:18 +01:00
width: '100%',
2020-12-13 01:24:25 +01:00
flexDirection: 'row'
2020-10-29 14:52:28 +01:00
}
})
2020-12-19 18:21:37 +01:00
export default TimelineDefault