Compare commits

...

1 Commits

Author SHA1 Message Date
Reinaldo Neto a9d9021615 Chore: Migrate VisitorNavigationView to Typescript 2021-11-28 18:30:08 -03:00
1 changed files with 21 additions and 17 deletions

View File

@ -1,8 +1,9 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { FlatList, StyleSheet, Text } from 'react-native'; import { FlatList, StyleSheet, Text } from 'react-native';
import PropTypes from 'prop-types'; import { StackNavigationProp } from '@react-navigation/stack';
import { RouteProp } from '@react-navigation/native';
import { withTheme } from '../theme'; import { useTheme } from '../theme';
import RocketChat from '../lib/rocketchat'; import RocketChat from '../lib/rocketchat';
import { themes } from '../constants/colors'; import { themes } from '../constants/colors';
import openLink from '../utils/openLink'; import openLink from '../utils/openLink';
@ -21,19 +22,23 @@ const styles = StyleSheet.create({
} }
}); });
const Item = ({ item }) => ( const Item = ({ item }: { item: { navigation?: { page?: any } } }) => (
<List.Item <List.Item
title={item.navigation?.page?.title || I18n.t('Empty_title')} title={item.navigation?.page?.title || I18n.t('Empty_title')}
onPress={() => openLink(item.navigation?.page?.location?.href)} onPress={() => openLink(item.navigation?.page?.location?.href)}
translateTitle={false} translateTitle={false}
/> />
); );
Item.propTypes = {
item: PropTypes.object
};
const VisitorNavigationView = ({ route, theme }) => { interface IVisitorNavigationViewProps {
let offset; navigation: StackNavigationProp<any, 'VisitorNavigationView'>;
route: RouteProp<{ VisitorNavigationView: { rid: string } }, 'VisitorNavigationView'>;
}
const VisitorNavigationView = ({ navigation, route }: IVisitorNavigationViewProps): JSX.Element => {
const { theme } = useTheme();
let offset: number;
let total = 0; let total = 0;
const [pages, setPages] = useState([]); const [pages, setPages] = useState([]);
@ -53,6 +58,12 @@ const VisitorNavigationView = ({ route, theme }) => {
} }
}; };
useEffect(() => {
navigation.setOptions({
title: I18n.t('Navigation_history')
});
}, []);
useEffect(() => { useEffect(() => {
getPages(); getPages();
}, []); }, []);
@ -67,7 +78,7 @@ const VisitorNavigationView = ({ route, theme }) => {
<SafeAreaView> <SafeAreaView>
<FlatList <FlatList
data={pages} data={pages}
renderItem={({ item }) => <Item item={item} theme={theme} />} renderItem={({ item }) => <Item item={item} />}
ItemSeparatorComponent={List.Separator} ItemSeparatorComponent={List.Separator}
ListFooterComponent={List.Separator} ListFooterComponent={List.Separator}
ListHeaderComponent={List.Separator} ListHeaderComponent={List.Separator}
@ -82,12 +93,5 @@ const VisitorNavigationView = ({ route, theme }) => {
</SafeAreaView> </SafeAreaView>
); );
}; };
VisitorNavigationView.propTypes = {
theme: PropTypes.string,
route: PropTypes.object
};
VisitorNavigationView.navigationOptions = {
title: I18n.t('Navigation_history')
};
export default withTheme(VisitorNavigationView); export default VisitorNavigationView;