import React, {useCallback, useEffect, useState} from 'react'; import { ActivityIndicator, Platform, RefreshControl, useWindowDimensions, View, } from 'react-native'; import {TouchableWithoutFeedback} from 'react-native-gesture-handler'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; import {DataProvider, LayoutProvider, RecyclerListView} from 'recyclerlistview'; import {useTracked} from '../../provider'; import {Actions} from '../../provider/Actions'; import {DDS} from '../../services/DeviceDetection'; import {eSendEvent, ToastEvent} from '../../services/EventManager'; import {dHeight} from '../../utils'; import {db} from '../../utils/DB'; import { eOpenJumpToDialog, eOpenLoginDialog, eScrollEvent, } from '../../utils/Events'; import {SIZE} from '../../utils/SizeUtils'; import {sleep} from '../../utils/TimeUtils'; import {Button} from '../Button'; import {HeaderMenu} from '../Header/HeaderMenu'; import Seperator from '../Seperator'; import TagItem from '../TagItem'; import Heading from '../Typography/Heading'; import Paragraph from '../Typography/Paragraph'; import {ListHeaderComponent} from './ListHeaderComponent'; import {NotebookItemWrapper} from './NotebookItemWrapper'; import {NoteItemWrapper} from './NoteItemWrapper'; const header = { type: 'MAIN_HEADER', }; const SimpleList = ({ data, type, customRefresh, customRefreshing, refreshCallback, sortMenuButton, scrollRef, jumpToDialog, placeholderData, loading, }) => { const [state, dispatch] = useTracked(); const {colors, searchResults} = state; const [refreshing, setRefreshing] = useState(false); const [dataProvider, setDataProvider] = useState( new DataProvider((r1, r2) => { return r1 !== r2; }).cloneWithRows([header, {type: 'empty'}]), ); const insets = useSafeAreaInsets(); const {width, fontScale} = useWindowDimensions(); const listData = data; const dataType = type; const _onScroll = (event) => { if (!event) return; let y = event.nativeEvent.contentOffset.y; eSendEvent(eScrollEvent, y); }; useEffect(() => { loadData(); }, [listData, searchResults.results]); const loadData = () => { if (listData || listData.length === 0) { setDataProvider(dataProvider.cloneWithRows([header, ...listData])); } }; const RenderSectionHeader = ({item, index}) => ( { if (jumpToDialog) { eSendEvent(eOpenJumpToDialog); } }} hitSlop={{top: 10, left: 10, right: 30, bottom: 15}} style={{ height: '100%', justifyContent: 'center', }}> {item.title} {index === 1 && sortMenuButton ? : null} ); const _onRefresh = useCallback(async () => { if (Platform.OS === 'ios') { dispatch({ type: Actions.SYNCING, syncing: true, }); } else { setRefreshing(true); } try { let user = await db.user.get(); dispatch({type: Actions.USER, user: user}); await db.sync(); ToastEvent.show('Sync Complete', 'success'); } catch (e) { ToastEvent.show( 'You must login to sync.', 'error', 'global', 5000, () => { eSendEvent(eOpenLoginDialog); }, 'Login', ); } finally { if (Platform.OS === 'ios') { dispatch({ type: Actions.SYNCING, syncing: false, }); } else { setRefreshing(false); } if (refreshCallback) { refreshCallback(); } } dispatch({type: Actions.ALL}); }, []); const _ListEmptyComponent = ( {placeholderData.heading} {loading ? placeholderData.loading : placeholderData.paragraph} {placeholderData.button && !loading ? (