Skip to content

Commit

Permalink
Bug fixes and UI Update in Settings,History,Home,BookMarks and Server…
Browse files Browse the repository at this point in the history
… Down (#18)
  • Loading branch information
PremSharma01 authored Aug 4, 2024
1 parent 21543ef commit 055d372
Show file tree
Hide file tree
Showing 24 changed files with 608 additions and 117 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1866,4 +1866,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 9fcb03d491101702682929068cf6ea51908a88f3

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
16 changes: 16 additions & 0 deletions src/Components/Func/HomeFunc.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,20 @@ export const FetchAnimeData = async (link, dispatch, baseUrl) => {
if (dispatch) dispatch(checkDownTime(error));
return [];
}
}

export const checkServerDown = async ( url, dispatch) => {
dispatch(fetchDataStart());
try {
const response = await APICaller.get(url);
//set DownTime to false
console.log(response.status, 'response');
dispatch(checkDownTime(response));
return false;
} catch (error) {
//set DownTime to true
console.log('Error checking server down:', error.message);
dispatch(checkDownTime(error));
return true;
}
}
2 changes: 1 addition & 1 deletion src/Components/Gallery/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ const GalleryComponent = <T extends any>(

useImperativeHandle(ref, () => ({
setIndex(newIndex: number, animated?: boolean) {
refs.current?.[index].reset(false);
if (refs?.current) refs.current?.[index].reset(false);
setIndex(newIndex);
currentIndex.value = newIndex;
if (animated) {
Expand Down
11 changes: 9 additions & 2 deletions src/Components/UIComp/DownTime.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React from "react";
import { View, Text, StyleSheet, ActivityIndicator } from "react-native";
import { useDispatch, useSelector } from "react-redux";
import { fetchComicsData } from "../Func/HomeFunc";
import { checkServerDown } from "../Func/HomeFunc";
import Button from "./Button";
import { AnimeHostName, ComicHostName } from "../../Utils/APIs";

const DownTime = () => {
const dispatch = useDispatch();
const loading = useSelector(state => state.data.loading);
const animeActive = useSelector(state => state?.data?.Anime);
const baseUrl = useSelector(state => state.data.baseUrl);
return (
<View style={styles.container} >
{loading ?
Expand All @@ -18,7 +21,11 @@ const DownTime = () => {
<Button
title="Retry"
onPress={() => {
fetchComicsData(`https://readallcomics.com/`, dispatch);
if (animeActive) {
checkServerDown(AnimeHostName[baseUrl], dispatch)
} else {
checkServerDown(ComicHostName[baseUrl], dispatch)
}
}}
textSize={20}
/>}
Expand Down
18 changes: 14 additions & 4 deletions src/Components/UIComp/GalleryPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import FontAwesome6 from 'react-native-vector-icons/FontAwesome6';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';

import Gallery from '../Gallery/src';
import { navigate } from '../../Navigation/NavigationService';
import { navigate, replace } from '../../Navigation/NavigationService';
import { NAVIGATION } from '../../Constants';

const GalleryPopup = ({ images, setClose, isOpen, link, BookMarkRemove }) => {
Expand Down Expand Up @@ -130,13 +130,21 @@ const GalleryPopup = ({ images, setClose, isOpen, link, BookMarkRemove }) => {
placeholderTextColor={'#fff3'}
placeholder="Jump to"
keyboardType="numeric"
value={PageIndex + 1}
value={jumpToPage}
ref={InputRef}
onChangeText={(text) => {
if (text === '') return;
//check text should be number full number no decimal or negative or any other character
if (text.match(/[^0-9]/g)) {
setJumpToPage(text.replace(/[^0-9]/g, ''));
return Alert.alert('Please enter a valid page number');
}
let index = parseInt(text) - 1;
//check is vaild number
if (isNaN(index)) return Alert.alert('Please enter a valid number');
if (isNaN(index)) {
setJumpToPage(index.replace(/[^0-9]/g, ''));
return Alert.alert('Please enter a valid page number');
}
if (index < 0 || index >= images.length) return Alert.alert('Invalid page number');
setJumpToPage(index);
}}
Expand All @@ -151,7 +159,9 @@ const GalleryPopup = ({ images, setClose, isOpen, link, BookMarkRemove }) => {
</Text>
<TouchableOpacity
style={{ marginLeft: 10 }}
disabled={jumpToPage === ""}
onPress={() => {
if (jumpToPage === "") return;
GalleryRef.current?.setIndex(jumpToPage);
InputRef.current?.clear();
InputRef.current?.blur();
Expand All @@ -160,7 +170,7 @@ const GalleryPopup = ({ images, setClose, isOpen, link, BookMarkRemove }) => {
<MaterialCommunityIcons
name="book-open-page-variant-outline"
size={24}
color="#fff"
color={!jumpToPage ? "#fff3" : "#fff"}
/>
</TouchableOpacity>
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/Constants/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const NAVIGATION = {
comicDetails: 'ComicDetails',
comicBook: 'ComicBook',
search: 'Search',
bookmarks: 'Bookmarks',
bookmarks: 'History',
localComic: "LocalComic",
settings: 'Settings',
bottomNavigation: 'BottomNavigation',
Expand Down
42 changes: 23 additions & 19 deletions src/Navigation/BottomNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import Feather from 'react-native-vector-icons/Feather';
import FontAwesome6 from 'react-native-vector-icons/FontAwesome6';
import Ionicons from 'react-native-vector-icons/Ionicons';

import { Bookmarks, Search, Settings } from '../Screens';
import { Search, Settings } from '../Screens';
import { NAVIGATION } from '../Constants';
import { useSelector } from 'react-redux';
import { AnimeHome } from '../Screens/Anime';
import { Home, LocalComic } from '../Screens/Comic';
import { AnimeBookmarks, AnimeHome } from '../Screens/Anime';
import { ComicBookmarks, Home, LocalComic } from '../Screens/Comic';
import { View, StyleSheet } from 'react-native';
import DownTime from '../Components/UIComp/DownTime';

const BottomTab = createBottomTabNavigator();

Expand Down Expand Up @@ -58,8 +59,11 @@ const TabBarIcon = props => {
}
};


export function BottomNavigation() {
const animeActive = useSelector(state => state?.data?.Anime);
const downTime = useSelector(state => state.data.downTime);

return (
<BottomTab.Navigator
initialRouteName="Home"
Expand Down Expand Up @@ -87,7 +91,7 @@ export function BottomNavigation() {
}}>
<BottomTab.Screen
name={NAVIGATION.home}
component={animeActive ? AnimeHome : Home}
component={downTime ? DownTime : animeActive ? AnimeHome : Home}
options={{
tabBarIcon: ({ focused, color }) => (
<TabBarIcon focused={focused} tintColor={color} name="home" />
Expand All @@ -114,21 +118,21 @@ export function BottomNavigation() {
),
}}
/>}
{animeActive ? null : (
<BottomTab.Screen
name={NAVIGATION.bookmarks}
component={Bookmarks}
options={{
tabBarIcon: ({ focused, color }) => (
<TabBarIcon
focused={focused}
tintColor={color}
name="book-bookmark"
/>
),
}}
/>
)}

<BottomTab.Screen
name={NAVIGATION.bookmarks}
component={animeActive ? AnimeBookmarks : ComicBookmarks}
options={{
tabBarIcon: ({ focused, color }) => (
<TabBarIcon
focused={focused}
tintColor={color}
name="book-bookmark"
/>
),
}}
/>


<BottomTab.Screen
name={NAVIGATION.settings}
Expand Down
5 changes: 0 additions & 5 deletions src/Navigation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {AppNavigation} from './AppNavigation';
import {navigationRef} from './NavigationService';
import {PermissionsAndroid, Platform, StatusBar} from 'react-native';
import {useDispatch, useSelector} from 'react-redux';
import DownTime from '../Components/UIComp/DownTime';
import {ClearError} from '../Redux/Reducers';
import analytics from '@react-native-firebase/analytics';
import {useNetInfo} from '@react-native-community/netinfo';
Expand All @@ -15,7 +14,6 @@ import crashlytics from '@react-native-firebase/crashlytics';
import {firebase as fire} from '@react-native-firebase/analytics';

export function RootNavigation() {
const downTime = useSelector(state => state.data.downTime);
const dispatch = useDispatch();
const {type, isConnected} = useNetInfo();

Expand Down Expand Up @@ -72,9 +70,6 @@ export function RootNavigation() {
return <Network />;
}

if (downTime) {
return <DownTime />;
}

return (
<NavigationContainer
Expand Down
13 changes: 12 additions & 1 deletion src/Redux/Reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const initialState = {
baseUrl: 's3taku',
Anime: true,
AnimeWatched: {},
AnimeBookMarks: {},
};

const Reducers = createSlice({
Expand Down Expand Up @@ -65,13 +66,21 @@ const Reducers = createSlice({
},
SwtichBaseUrl: (state, action) => {
state.baseUrl = action.payload;
state.downTime = false;
},
SwtichToAnime: state => {
state.Anime = !state.Anime;
state.downTime = false;
},
AnimeWatched: (state, action) => {
state.AnimeWatched[action?.payload?.AnimeName] = action?.payload
}
},
AddAnimeBookMark: (state, action) => {
state.AnimeBookMarks[action?.payload?.url] = action?.payload
},
RemoveAnimeBookMark: (state, action) => {
delete state.AnimeBookMarks[action?.payload?.url]
},
},
});

Expand All @@ -89,5 +98,7 @@ export const {
SwtichBaseUrl,
SwtichToAnime,
AnimeWatched,
AddAnimeBookMark,
RemoveAnimeBookMark,
} = Reducers.actions;
export default Reducers.reducer;
119 changes: 119 additions & 0 deletions src/Screens/Anime/Bookmarks/BookMarks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import React from 'react';
import {
View,
Text,
StyleSheet,
TouchableOpacity,
// Image,
FlatList,
Dimensions,
} from 'react-native';

import { useDispatch, useSelector } from 'react-redux';
import { SafeAreaView } from 'react-native-safe-area-context';
import FontAwesome6 from 'react-native-vector-icons/FontAwesome6';

import { RemoveAnimeBookMark, updateData } from '../../../Redux/Reducers';
import { heightPercentageToDP } from 'react-native-responsive-screen';
import Header from '../../../Components/UIComp/Header';
import Image from '../../../Components/UIComp/Image';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import { NAVIGATION } from '../../../Constants';

export function Bookmarks({ navigation }) {
const dispatch = useDispatch();
const data = useSelector(state => state.data.AnimeBookMarks);
return (
<FlatList
showsVerticalScrollIndicator={false}
data={Object.values(data)}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => {
return (
<TouchableOpacity
onPress={async () => {
navigation.navigate(NAVIGATION.animeDetails, {
link: item.url,
title: item.title,
});
}}
style={{
flexDirection: 'row',
justifyContent: 'space-between',
// alignItems: 'center',
padding: 10,
borderBottomColor: '#fff',
borderBottomWidth: 0.5,
}}>
<Image source={{ uri: item?.imageUrl }} style={styles.image} />
<View
style={{
width: Dimensions.get('window').width - 150,
alignItems: 'flex-start',
paddingHorizontal: 10,
gap: 2,
}}>
<Text style={styles.title} numberOfLines={2}>{item.title}</Text>
<Text style={styles.text} numberOfLines={1}>
<Text>Type:</Text> {item?.type}
</Text>
<Text style={styles.text} numberOfLines={1}>
<Text>Other Names:</Text> {item?.otherNames}
</Text>
<Text style={styles.text} numberOfLines={1}>
<Text>Genres:</Text> {item?.genres}
</Text>
<Text style={styles.text} numberOfLines={1}>
<Text>Release Year:</Text> {item?.releaseYear}
</Text>
</View>
<TouchableOpacity
onPress={() => {
dispatch(RemoveAnimeBookMark({ url: item.url }));
}}>
<FontAwesome6
name="book-bookmark"
size={24}
color={'yellow'}
/>
</TouchableOpacity>
</TouchableOpacity>
);
}}
ListEmptyComponent={() => (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
height: heightPercentageToDP('80%'),
}}>
<MaterialCommunityIcons name="comment-bookmark-outline" size={heightPercentageToDP("10%")} color="gold" />
<Text style={[styles.title, { marginTop: 12 }]}>No Bookmarks Found</Text>
</View>
)}
/>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
},
title: {
color: 'white',
fontSize: 18,
fontWeight: 'bold',
marginBottom: 5,
},
image: {
width: 90,
height: 140,
borderRadius: 5,
},
text: {
color: 'white',
fontSize: 14,
marginBottom: 5,
},
});
Loading

0 comments on commit 055d372

Please sign in to comment.