Update interfaces and minor tweaks to DiscussionsView screen and components

This commit is contained in:
Gerzon Z 2022-01-24 13:40:39 -04:00
parent 0a6e5d3fb0
commit ce8a208e42
3 changed files with 13 additions and 44 deletions

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { StyleSheet, Text, View, ViewStyle } from 'react-native'; import { StyleSheet, Text, View } from 'react-native';
import { TThreadModel } from '../../definitions/IThread'; import { TThreadModel } from '../../definitions/IThread';
import { CustomIcon } from '../../lib/Icons'; import { CustomIcon } from '../../lib/Icons';
@ -10,6 +10,7 @@ import { useTheme } from '../../theme';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
flex: 1, flex: 1,
marginTop: 8,
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center' alignItems: 'center'
}, },
@ -31,23 +32,19 @@ const styles = StyleSheet.create({
interface IDiscussionDetails { interface IDiscussionDetails {
item: TThreadModel; item: TThreadModel;
user: {
id: string;
};
date: string; date: string;
style: ViewStyle;
} }
const DiscussionDetails = ({ item, date, style }: IDiscussionDetails) => { const DiscussionDetails = ({ item, date }: IDiscussionDetails): JSX.Element => {
const { theme } = useTheme(); const { theme } = useTheme();
let { dcount } = item; let { dcount } = item;
if (dcount! >= 1000) { if (dcount && dcount >= 1000) {
dcount = '+999'; dcount = '+999';
} }
return ( return (
<View style={[styles.container, style]}> <View style={[styles.container]}>
<View style={styles.detailsContainer}> <View style={styles.detailsContainer}>
<View style={styles.detailContainer}> <View style={styles.detailContainer}>
<CustomIcon name={'discussions'} size={24} color={themes[theme!].auxiliaryText} /> <CustomIcon name={'discussions'} size={24} color={themes[theme!].auxiliaryText} />

View File

@ -39,9 +39,6 @@ const styles = StyleSheet.create({
avatar: { avatar: {
marginRight: 8 marginRight: 8
}, },
discussionDetails: {
marginTop: 8
},
messageContainer: { messageContainer: {
flexDirection: 'row' flexDirection: 'row'
}, },
@ -53,21 +50,17 @@ const styles = StyleSheet.create({
interface IItem { interface IItem {
item: TThreadModel; item: TThreadModel;
baseUrl: string; baseUrl: string;
user: {
id: string;
token: string;
};
onPress: { onPress: {
(...args: any[]): void; (...args: any[]): void;
stop(): void; stop(): void;
}; };
} }
const Item = ({ item, baseUrl, user, onPress }: IItem): JSX.Element => { const Item = ({ item, baseUrl, onPress }: IItem): JSX.Element => {
const { theme } = useTheme(); const { theme } = useTheme();
const username = item?.u?.username; const username = item?.u?.username;
let messageTime: string; let messageTime = '';
let messageDate: string; let messageDate = '';
if (item?.ts) { if (item?.ts) {
messageTime = moment(item.ts).format('LT'); messageTime = moment(item.ts).format('LT');
@ -102,7 +95,7 @@ const Item = ({ item, baseUrl, user, onPress }: IItem): JSX.Element => {
/> />
) : null} ) : null}
</View> </View>
<DiscussionDetails item={item} user={user} date={messageDate!} style={styles.discussionDetails} /> {messageDate ? <DiscussionDetails item={item} date={messageDate} /> : null}
</View> </View>
</View> </View>
</Touchable> </Touchable>

View File

@ -5,7 +5,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { HeaderBackButton, StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack'; import { HeaderBackButton, StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
import { RouteProp } from '@react-navigation/core'; import { RouteProp } from '@react-navigation/core';
import { SubscriptionType } from '../../definitions'; import { IApplicationState, SubscriptionType } from '../../definitions';
import { ChatsStackParamList } from '../../stacks/types'; import { ChatsStackParamList } from '../../stacks/types';
import ActivityIndicator from '../../containers/ActivityIndicator'; import ActivityIndicator from '../../containers/ActivityIndicator';
import I18n from '../../i18n'; import I18n from '../../i18n';
@ -34,31 +34,11 @@ interface IDiscussionsViewProps {
item: TThreadModel; item: TThreadModel;
} }
interface IDiscussionsViewState {
login: {
user: {
id: string;
token: string;
};
};
server: {
server: string;
};
settings: {
UI_Use_Real_Name: boolean;
Message_TimeFormat: string;
};
app: {
isMasterDetail: boolean;
};
}
const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Element => { const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Element => {
const rid = route.params?.rid; const rid = route.params?.rid;
const user = useSelector((state: IDiscussionsViewState) => state.login?.user); const baseUrl = useSelector((state: IApplicationState) => state.server?.server);
const baseUrl = useSelector((state: IDiscussionsViewState) => state.server?.server); const isMasterDetail = useSelector((state: IApplicationState) => state.app?.isMasterDetail);
const isMasterDetail = useSelector((state: IDiscussionsViewState) => state.app?.isMasterDetail);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [discussions, setDiscussions] = useState([]); const [discussions, setDiscussions] = useState([]);
@ -187,7 +167,6 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem
<Item <Item
{...{ {...{
item, item,
user,
baseUrl baseUrl
}} }}
onPress={onDiscussionPress} onPress={onDiscussionPress}
@ -209,7 +188,7 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem
contentContainerStyle={styles.contentContainer} contentContainerStyle={styles.contentContainer}
onEndReachedThreshold={0.5} onEndReachedThreshold={0.5}
removeClippedSubviews={isIOS} removeClippedSubviews={isIOS}
onEndReached={() => (searchTotal || total) > API_FETCH_COUNT ?? load()} onEndReached={() => (isSearching ? searchTotal : total) > API_FETCH_COUNT ?? load()}
ItemSeparatorComponent={List.Separator} ItemSeparatorComponent={List.Separator}
ListFooterComponent={loading ? <ActivityIndicator theme={theme} /> : null} ListFooterComponent={loading ? <ActivityIndicator theme={theme} /> : null}
scrollIndicatorInsets={{ right: 1 }} scrollIndicatorInsets={{ right: 1 }}