import React, { useState, useCallback } from "react"; import { StyleSheet, Text, View, RefreshControl, ActivityIndicator, ToastAndroid, } from "react-native"; import { FlatList } from "react-native-gesture-handler"; import { useFocusEffect } from "@react-navigation/native"; import Appbar from "./components/Appbar"; import NovelCover from "../../components/common/NovelCover"; import { connect } from "react-redux"; import { useSelector } from "react-redux"; import { getLibraryNovels, searchLibraryNovels, } from "../../redux/actions/library"; const LibraryScreen = ({ navigation, novels, loading, getLibraryNovels, searchLibraryNovels, }) => { const theme = useSelector((state) => state.themeReducer.theme); // const itemsPerRow = useSelector((state) => state.settingsReducer.itemsPerRow); const [refreshing, setRefreshing] = useState(false); const [searchBar, setSearchBar] = useState(false); const [searchText, setSearchText] = useState(""); useFocusEffect( useCallback(() => { setSearchBar(false); getLibraryNovels(); }, []) ); const onRefresh = () => { ToastAndroid.show("Updating library", ToastAndroid.SHORT); setRefreshing(true); getLibraryNovels(); setRefreshing(false); }; return ( <> item.novelUrl} renderItem={({ item }) => ( navigation.navigate("NovelItem", { ...item, navigatingFrom: 1, }) } /> )} refreshControl={ } ListEmptyComponent={ !loading ? ( !searchBar ? ( Σ(ಠ_ಠ) Your library is empty. Add series to your library from Browse. ) : ( searchBar && searchText !== "" && ( {`"${searchText}" not in library`} ) ) ) : ( ) } /> ); }; const mapStateToProps = (state) => ({ novels: state.libraryReducer.novels, loading: state.libraryReducer.loading, }); export default connect(mapStateToProps, { getLibraryNovels, searchLibraryNovels, })(LibraryScreen); const styles = StyleSheet.create({ container: { flex: 1, padding: 4, }, });