From ce83648f9da3a93018fc7845bec1d35c1519028d Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 22 Jul 2022 12:32:52 -0500 Subject: Add liked-by and reposted-by views --- src/view/com/post-thread/PostRepostedBy.tsx | 141 ++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 src/view/com/post-thread/PostRepostedBy.tsx (limited to 'src/view/com/post-thread/PostRepostedBy.tsx') diff --git a/src/view/com/post-thread/PostRepostedBy.tsx b/src/view/com/post-thread/PostRepostedBy.tsx new file mode 100644 index 000000000..98c24ef86 --- /dev/null +++ b/src/view/com/post-thread/PostRepostedBy.tsx @@ -0,0 +1,141 @@ +import React, {useState, useEffect} from 'react' +import {observer} from 'mobx-react-lite' +import { + ActivityIndicator, + FlatList, + Image, + StyleSheet, + Text, + TouchableOpacity, + View, +} from 'react-native' +import {OnNavigateContent} from '../../routes/types' +import { + RepostedByViewModel, + RepostedByViewItemModel, +} from '../../../state/models/reposted-by-view' +import {useStores} from '../../../state' +import {s} from '../../lib/styles' +import {AVIS} from '../../lib/assets' + +export const PostRepostedBy = observer(function PostRepostedBy({ + uri, + onNavigateContent, +}: { + uri: string + onNavigateContent: OnNavigateContent +}) { + const store = useStores() + const [view, setView] = useState() + + useEffect(() => { + if (view?.params.uri === uri) { + console.log('Reposted by doing nothing') + return // no change needed? or trigger refresh? + } + console.log('Fetching Reposted by', uri) + const newView = new RepostedByViewModel(store, {uri}) + setView(newView) + newView + .setup() + .catch(err => console.error('Failed to fetch reposted by', err)) + }, [uri, view?.params.uri, store]) + + // loading + // = + if ( + !view || + (view.isLoading && !view.isRefreshing) || + view.params.uri !== uri + ) { + return ( + + + + ) + } + + // error + // = + if (view.hasError) { + return ( + + {view.error} + + ) + } + + // loaded + // = + const renderItem = ({item}: {item: RepostedByViewItemModel}) => ( + + ) + return ( + + item._reactKey} + renderItem={renderItem} + /> + + ) +}) + +const RepostedByItem = ({ + item, + onNavigateContent, +}: { + item: RepostedByViewItemModel + onNavigateContent: OnNavigateContent +}) => { + const onPressOuter = () => { + onNavigateContent('Profile', { + name: item.name, + }) + } + return ( + + + + + + + {item.displayName} + @{item.name} + + + + ) +} + +const styles = StyleSheet.create({ + outer: { + borderTopWidth: 1, + borderTopColor: '#e8e8e8', + backgroundColor: '#fff', + }, + layout: { + flexDirection: 'row', + }, + layoutAvi: { + width: 60, + paddingLeft: 10, + paddingTop: 10, + paddingBottom: 10, + }, + avi: { + width: 40, + height: 40, + borderRadius: 30, + resizeMode: 'cover', + }, + layoutContent: { + flex: 1, + paddingRight: 10, + paddingTop: 10, + paddingBottom: 10, + }, +}) -- cgit 1.4.1