2021-01-16 00:00:31 +01:00
|
|
|
import GracefullyImage from '@components/GracefullyImage'
|
|
|
|
import Icon from '@components/Icon'
|
|
|
|
import { useNavigation } from '@react-navigation/native'
|
2021-01-24 02:25:43 +01:00
|
|
|
import { StackNavigationProp } from '@react-navigation/stack'
|
2021-08-29 15:25:38 +02:00
|
|
|
import { TabLocalStackParamList } from '@utils/navigation/navigators'
|
2022-12-18 23:32:57 +01:00
|
|
|
import { useTimelineQuery } from '@utils/queryHooks/timeline'
|
2022-12-31 00:07:28 +01:00
|
|
|
import { flattenPages } from '@utils/queryHooks/utils'
|
2021-01-16 00:00:31 +01:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2023-01-02 02:08:12 +01:00
|
|
|
import React, { useContext } from 'react'
|
2022-12-29 00:36:35 +01:00
|
|
|
import { Dimensions, Pressable, View } from 'react-native'
|
2023-01-06 14:00:50 +01:00
|
|
|
import { FlatList } from 'react-native-gesture-handler'
|
2023-01-02 02:08:12 +01:00
|
|
|
import AccountContext from './Context'
|
2021-01-16 00:00:31 +01:00
|
|
|
|
2023-01-02 02:08:12 +01:00
|
|
|
const AccountAttachments: React.FC = () => {
|
|
|
|
const { account } = useContext(AccountContext)
|
2021-01-16 00:00:31 +01:00
|
|
|
|
2023-01-02 02:08:12 +01:00
|
|
|
if (account?.suspended) return null
|
2021-01-16 00:00:31 +01:00
|
|
|
|
2022-12-14 23:37:41 +01:00
|
|
|
const navigation = useNavigation<StackNavigationProp<TabLocalStackParamList>>()
|
|
|
|
const { colors } = useTheme()
|
2021-01-31 03:09:35 +01:00
|
|
|
|
2022-12-14 23:37:41 +01:00
|
|
|
const DISPLAY_AMOUNT = 6
|
2021-01-16 00:00:31 +01:00
|
|
|
|
2022-12-18 21:16:21 +01:00
|
|
|
const width = (Dimensions.get('window').width - StyleConstants.Spacing.Global.PagePadding * 2) / 4
|
2021-01-16 00:00:31 +01:00
|
|
|
|
2022-12-18 23:32:57 +01:00
|
|
|
const { data } = useTimelineQuery({
|
2022-12-14 23:37:41 +01:00
|
|
|
page: 'Account',
|
2023-01-02 02:08:12 +01:00
|
|
|
id: account?.id,
|
2022-12-15 01:41:34 +01:00
|
|
|
exclude_reblogs: false,
|
2023-01-02 02:08:12 +01:00
|
|
|
only_media: true,
|
|
|
|
options: { enabled: !!account?.id }
|
2022-12-14 23:37:41 +01:00
|
|
|
})
|
2021-01-16 00:00:31 +01:00
|
|
|
|
2022-12-31 00:07:28 +01:00
|
|
|
const flattenData = flattenPages(data)
|
|
|
|
.filter(status => !(status as Mastodon.Status).sensitive)
|
|
|
|
.splice(0, DISPLAY_AMOUNT)
|
2021-01-16 00:00:31 +01:00
|
|
|
|
2023-01-02 02:08:12 +01:00
|
|
|
if (!flattenData.length) return null
|
|
|
|
|
|
|
|
return (
|
2023-01-06 14:00:50 +01:00
|
|
|
<View
|
2023-01-02 02:08:12 +01:00
|
|
|
style={{
|
|
|
|
flex: 1,
|
|
|
|
height: width + StyleConstants.Spacing.Global.PagePadding * 2,
|
2022-12-14 23:37:41 +01:00
|
|
|
paddingVertical: StyleConstants.Spacing.Global.PagePadding,
|
|
|
|
borderTopWidth: 1,
|
|
|
|
borderTopColor: colors.border
|
2023-01-02 02:08:12 +01:00
|
|
|
}}
|
|
|
|
>
|
2023-01-06 14:00:50 +01:00
|
|
|
<FlatList
|
|
|
|
horizontal
|
|
|
|
data={flattenData}
|
|
|
|
renderItem={({ item, index }) => {
|
|
|
|
if (index === DISPLAY_AMOUNT - 1) {
|
|
|
|
return (
|
|
|
|
<Pressable
|
|
|
|
onPress={() => {
|
|
|
|
account && navigation.push('Tab-Shared-Attachments', { account })
|
|
|
|
}}
|
|
|
|
children={
|
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
marginHorizontal: StyleConstants.Spacing.Global.PagePadding,
|
|
|
|
backgroundColor: colors.backgroundOverlayInvert,
|
|
|
|
width: width,
|
|
|
|
height: width,
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center'
|
|
|
|
}}
|
|
|
|
children={
|
|
|
|
<Icon
|
2023-01-25 00:15:46 +01:00
|
|
|
name='more-horizontal'
|
2023-01-06 14:00:50 +01:00
|
|
|
color={colors.primaryOverlay}
|
|
|
|
size={StyleConstants.Font.Size.L * 1.5}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<GracefullyImage
|
2023-02-08 01:10:59 +01:00
|
|
|
sources={{
|
|
|
|
preview: {
|
|
|
|
uri: item.media_attachments[0]?.preview_url,
|
|
|
|
width: item.media_attachments[0]?.meta?.small?.width,
|
|
|
|
height: item.media_attachments[0]?.meta?.small?.height
|
|
|
|
},
|
|
|
|
default: {
|
|
|
|
uri: item.media_attachments[0]?.url,
|
|
|
|
width: item.media_attachments[0]?.meta?.original?.width,
|
|
|
|
height: item.media_attachments[0]?.meta?.original?.height
|
|
|
|
},
|
|
|
|
remote: {
|
|
|
|
uri: item.media_attachments[0]?.remote_url,
|
|
|
|
width: item.media_attachments[0]?.meta?.original?.width,
|
|
|
|
height: item.media_attachments[0]?.meta?.original?.height
|
|
|
|
},
|
|
|
|
blurhash: item.media_attachments[0]?.blurhash
|
2023-01-06 14:00:50 +01:00
|
|
|
}}
|
2023-02-08 01:10:59 +01:00
|
|
|
dimension={{ width, height: width }}
|
2023-01-06 14:00:50 +01:00
|
|
|
style={{ marginLeft: StyleConstants.Spacing.Global.PagePadding }}
|
|
|
|
onPress={() => navigation.push('Tab-Shared-Toot', { toot: item })}
|
2023-01-29 17:28:49 +01:00
|
|
|
dim
|
2023-01-06 14:00:50 +01:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
showsHorizontalScrollIndicator={false}
|
|
|
|
/>
|
|
|
|
</View>
|
2022-12-14 23:37:41 +01:00
|
|
|
)
|
|
|
|
}
|
2021-01-16 00:00:31 +01:00
|
|
|
|
|
|
|
export default AccountAttachments
|