Update interfaces and minor tweaks to DiscussionsView screen and components
This commit is contained in:
parent
0a6e5d3fb0
commit
ce8a208e42
|
@ -1,5 +1,5 @@
|
|||
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 { CustomIcon } from '../../lib/Icons';
|
||||
|
@ -10,6 +10,7 @@ import { useTheme } from '../../theme';
|
|||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
marginTop: 8,
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center'
|
||||
},
|
||||
|
@ -31,23 +32,19 @@ const styles = StyleSheet.create({
|
|||
|
||||
interface IDiscussionDetails {
|
||||
item: TThreadModel;
|
||||
user: {
|
||||
id: string;
|
||||
};
|
||||
date: string;
|
||||
style: ViewStyle;
|
||||
}
|
||||
|
||||
const DiscussionDetails = ({ item, date, style }: IDiscussionDetails) => {
|
||||
const DiscussionDetails = ({ item, date }: IDiscussionDetails): JSX.Element => {
|
||||
const { theme } = useTheme();
|
||||
let { dcount } = item;
|
||||
|
||||
if (dcount! >= 1000) {
|
||||
if (dcount && dcount >= 1000) {
|
||||
dcount = '+999';
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={[styles.container, style]}>
|
||||
<View style={[styles.container]}>
|
||||
<View style={styles.detailsContainer}>
|
||||
<View style={styles.detailContainer}>
|
||||
<CustomIcon name={'discussions'} size={24} color={themes[theme!].auxiliaryText} />
|
||||
|
|
|
@ -39,9 +39,6 @@ const styles = StyleSheet.create({
|
|||
avatar: {
|
||||
marginRight: 8
|
||||
},
|
||||
discussionDetails: {
|
||||
marginTop: 8
|
||||
},
|
||||
messageContainer: {
|
||||
flexDirection: 'row'
|
||||
},
|
||||
|
@ -53,21 +50,17 @@ const styles = StyleSheet.create({
|
|||
interface IItem {
|
||||
item: TThreadModel;
|
||||
baseUrl: string;
|
||||
user: {
|
||||
id: string;
|
||||
token: string;
|
||||
};
|
||||
onPress: {
|
||||
(...args: any[]): void;
|
||||
stop(): void;
|
||||
};
|
||||
}
|
||||
|
||||
const Item = ({ item, baseUrl, user, onPress }: IItem): JSX.Element => {
|
||||
const Item = ({ item, baseUrl, onPress }: IItem): JSX.Element => {
|
||||
const { theme } = useTheme();
|
||||
const username = item?.u?.username;
|
||||
let messageTime: string;
|
||||
let messageDate: string;
|
||||
let messageTime = '';
|
||||
let messageDate = '';
|
||||
|
||||
if (item?.ts) {
|
||||
messageTime = moment(item.ts).format('LT');
|
||||
|
@ -102,7 +95,7 @@ const Item = ({ item, baseUrl, user, onPress }: IItem): JSX.Element => {
|
|||
/>
|
||||
) : null}
|
||||
</View>
|
||||
<DiscussionDetails item={item} user={user} date={messageDate!} style={styles.discussionDetails} />
|
||||
{messageDate ? <DiscussionDetails item={item} date={messageDate} /> : null}
|
||||
</View>
|
||||
</View>
|
||||
</Touchable>
|
||||
|
|
|
@ -5,7 +5,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|||
import { HeaderBackButton, StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
|
||||
import { RouteProp } from '@react-navigation/core';
|
||||
|
||||
import { SubscriptionType } from '../../definitions';
|
||||
import { IApplicationState, SubscriptionType } from '../../definitions';
|
||||
import { ChatsStackParamList } from '../../stacks/types';
|
||||
import ActivityIndicator from '../../containers/ActivityIndicator';
|
||||
import I18n from '../../i18n';
|
||||
|
@ -34,31 +34,11 @@ interface IDiscussionsViewProps {
|
|||
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 rid = route.params?.rid;
|
||||
|
||||
const user = useSelector((state: IDiscussionsViewState) => state.login?.user);
|
||||
const baseUrl = useSelector((state: IDiscussionsViewState) => state.server?.server);
|
||||
const isMasterDetail = useSelector((state: IDiscussionsViewState) => state.app?.isMasterDetail);
|
||||
const baseUrl = useSelector((state: IApplicationState) => state.server?.server);
|
||||
const isMasterDetail = useSelector((state: IApplicationState) => state.app?.isMasterDetail);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [discussions, setDiscussions] = useState([]);
|
||||
|
@ -187,7 +167,6 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem
|
|||
<Item
|
||||
{...{
|
||||
item,
|
||||
user,
|
||||
baseUrl
|
||||
}}
|
||||
onPress={onDiscussionPress}
|
||||
|
@ -209,7 +188,7 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem
|
|||
contentContainerStyle={styles.contentContainer}
|
||||
onEndReachedThreshold={0.5}
|
||||
removeClippedSubviews={isIOS}
|
||||
onEndReached={() => (searchTotal || total) > API_FETCH_COUNT ?? load()}
|
||||
onEndReached={() => (isSearching ? searchTotal : total) > API_FETCH_COUNT ?? load()}
|
||||
ItemSeparatorComponent={List.Separator}
|
||||
ListFooterComponent={loading ? <ActivityIndicator theme={theme} /> : null}
|
||||
scrollIndicatorInsets={{ right: 1 }}
|
||||
|
|
Loading…
Reference in New Issue