tooot/src/screens/Tabs/Shared/Account/Attachments.tsx

118 lines
4.1 KiB
TypeScript
Raw Normal View History

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'
import { Dimensions, Pressable, View } from 'react-native'
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 (
<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
}}
>
<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
name='more-horizontal'
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-02-08 01:10:59 +01:00
dimension={{ width, height: width }}
style={{ marginLeft: StyleConstants.Spacing.Global.PagePadding }}
onPress={() => navigation.push('Tab-Shared-Toot', { toot: item })}
2023-01-29 17:28:49 +01:00
dim
/>
)
}
}}
showsHorizontalScrollIndicator={false}
/>
</View>
2022-12-14 23:37:41 +01:00
)
}
2021-01-16 00:00:31 +01:00
export default AccountAttachments