2020-05-08 17:36:10 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { FlatList, StyleSheet, Text } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import { withTheme } from '../theme';
|
|
|
|
import RocketChat from '../lib/rocketchat';
|
|
|
|
import { themes } from '../constants/colors';
|
|
|
|
import openLink from '../utils/openLink';
|
|
|
|
import I18n from '../i18n';
|
|
|
|
import debounce from '../utils/debounce';
|
2020-10-30 13:59:44 +00:00
|
|
|
import * as List from '../containers/List';
|
|
|
|
import SafeAreaView from '../containers/SafeAreaView';
|
2021-10-01 18:12:19 +00:00
|
|
|
import sharedStyles from './Styles';
|
2020-05-08 17:36:10 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
noResult: {
|
|
|
|
fontSize: 16,
|
|
|
|
paddingVertical: 56,
|
2020-11-30 21:47:05 +00:00
|
|
|
...sharedStyles.textSemibold,
|
|
|
|
...sharedStyles.textAlignCenter
|
2020-05-08 17:36:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-10-30 13:59:44 +00:00
|
|
|
const Item = ({ item }) => (
|
|
|
|
<List.Item
|
2020-05-08 17:36:10 +00:00
|
|
|
title={item.navigation?.page?.title || I18n.t('Empty_title')}
|
|
|
|
onPress={() => openLink(item.navigation?.page?.location?.href)}
|
2020-10-30 13:59:44 +00:00
|
|
|
translateTitle={false}
|
2020-05-08 17:36:10 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
Item.propTypes = {
|
2020-10-30 13:59:44 +00:00
|
|
|
item: PropTypes.object
|
2020-05-08 17:36:10 +00:00
|
|
|
};
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
const VisitorNavigationView = ({ route, theme }) => {
|
2020-05-08 17:36:10 +00:00
|
|
|
let offset;
|
|
|
|
let total = 0;
|
|
|
|
const [pages, setPages] = useState([]);
|
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
const getPages = async () => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const rid = route.params?.rid;
|
2020-05-08 17:36:10 +00:00
|
|
|
if (rid) {
|
|
|
|
try {
|
|
|
|
const result = await RocketChat.getPagesLivechat(rid, offset);
|
|
|
|
if (result.success) {
|
|
|
|
setPages(result.pages);
|
|
|
|
offset = result.pages.length;
|
|
|
|
({ total } = result);
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// do nothig
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
useEffect(() => {
|
|
|
|
getPages();
|
|
|
|
}, []);
|
2020-05-08 17:36:10 +00:00
|
|
|
|
|
|
|
const onEndReached = debounce(() => {
|
|
|
|
if (pages.length <= total) {
|
|
|
|
getPages();
|
|
|
|
}
|
|
|
|
}, 300);
|
|
|
|
|
|
|
|
return (
|
2020-10-30 13:59:44 +00:00
|
|
|
<SafeAreaView>
|
|
|
|
<FlatList
|
|
|
|
data={pages}
|
|
|
|
renderItem={({ item }) => <Item item={item} theme={theme} />}
|
|
|
|
ItemSeparatorComponent={List.Separator}
|
|
|
|
ListFooterComponent={List.Separator}
|
|
|
|
ListHeaderComponent={List.Separator}
|
|
|
|
contentContainerStyle={List.styles.contentContainerStyleFlatList}
|
2021-10-01 18:12:19 +00:00
|
|
|
ListEmptyComponent={() => (
|
|
|
|
<Text style={[styles.noResult, { color: themes[theme].titleText }]}>{I18n.t('No_results_found')}</Text>
|
|
|
|
)}
|
2020-10-30 13:59:44 +00:00
|
|
|
keyExtractor={item => item}
|
|
|
|
onEndReached={onEndReached}
|
|
|
|
onEndReachedThreshold={5}
|
|
|
|
/>
|
|
|
|
</SafeAreaView>
|
2020-05-08 17:36:10 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
VisitorNavigationView.propTypes = {
|
|
|
|
theme: PropTypes.string,
|
2020-06-15 14:00:46 +00:00
|
|
|
route: PropTypes.object
|
2020-05-08 17:36:10 +00:00
|
|
|
};
|
|
|
|
VisitorNavigationView.navigationOptions = {
|
|
|
|
title: I18n.t('Navigation_history')
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withTheme(VisitorNavigationView);
|