* Rework notifications to sync locally in full and give users better control * Fix positioning of load more btn on web * Improve behavior of load more notifications btn * Fix to post rendering * Fix notification fetch abort condition * Add start of post-hiding by labels * Create a standard postcontainer and improve show/hide UI on posts * Add content hiding to expanded post form * Improve label rendering to give more context to users when appropriate * Fix rendering bug * Add user/profile labeling * Implement content filtering preferences * Filter notifications by content prefs * Update test-pds config * Bump deps
101 lines
2.4 KiB
TypeScript
101 lines
2.4 KiB
TypeScript
import React, {useEffect} from 'react'
|
|
import {observer} from 'mobx-react-lite'
|
|
import {ActivityIndicator, RefreshControl, StyleSheet, View} from 'react-native'
|
|
import {CenteredView, FlatList} from '../util/Views'
|
|
import {RepostedByModel, RepostedByItem} from 'state/models/lists/reposted-by'
|
|
import {ProfileCardWithFollowBtn} from '../profile/ProfileCard'
|
|
import {ErrorMessage} from '../util/error/ErrorMessage'
|
|
import {useStores} from 'state/index'
|
|
import {usePalette} from 'lib/hooks/usePalette'
|
|
|
|
export const PostRepostedBy = observer(function PostRepostedBy({
|
|
uri,
|
|
}: {
|
|
uri: string
|
|
}) {
|
|
const pal = usePalette('default')
|
|
const store = useStores()
|
|
const view = React.useMemo(
|
|
() => new RepostedByModel(store, {uri}),
|
|
[store, uri],
|
|
)
|
|
|
|
useEffect(() => {
|
|
view
|
|
.loadMore()
|
|
.catch(err => store.log.error('Failed to fetch reposts', err))
|
|
}, [view, store.log])
|
|
|
|
const onRefresh = () => {
|
|
view.refresh()
|
|
}
|
|
const onEndReached = () => {
|
|
view
|
|
.loadMore()
|
|
.catch(err =>
|
|
view?.rootStore.log.error('Failed to load more reposts', err),
|
|
)
|
|
}
|
|
|
|
if (!view.hasLoaded) {
|
|
return (
|
|
<CenteredView>
|
|
<ActivityIndicator />
|
|
</CenteredView>
|
|
)
|
|
}
|
|
|
|
// error
|
|
// =
|
|
if (view.hasError) {
|
|
return (
|
|
<CenteredView>
|
|
<ErrorMessage message={view.error} onPressTryAgain={onRefresh} />
|
|
</CenteredView>
|
|
)
|
|
}
|
|
|
|
// loaded
|
|
// =
|
|
const renderItem = ({item}: {item: RepostedByItem}) => (
|
|
<ProfileCardWithFollowBtn
|
|
key={item.did}
|
|
did={item.did}
|
|
handle={item.handle}
|
|
displayName={item.displayName}
|
|
avatar={item.avatar}
|
|
labels={item.labels}
|
|
isFollowedBy={!!item.viewer?.followedBy}
|
|
/>
|
|
)
|
|
return (
|
|
<FlatList
|
|
data={view.repostedBy}
|
|
keyExtractor={item => item.did}
|
|
refreshControl={
|
|
<RefreshControl
|
|
refreshing={view.isRefreshing}
|
|
onRefresh={onRefresh}
|
|
tintColor={pal.colors.text}
|
|
titleColor={pal.colors.text}
|
|
/>
|
|
}
|
|
onEndReached={onEndReached}
|
|
renderItem={renderItem}
|
|
initialNumToRender={15}
|
|
ListFooterComponent={() => (
|
|
<View style={styles.footer}>
|
|
{view.isLoading && <ActivityIndicator />}
|
|
</View>
|
|
)}
|
|
extraData={view.isLoading}
|
|
/>
|
|
)
|
|
})
|
|
|
|
const styles = StyleSheet.create({
|
|
footer: {
|
|
height: 200,
|
|
paddingTop: 20,
|
|
},
|
|
})
|