Skip to content

Commit

Permalink
Merge pull request #30 from p2devs/ps/bug-fixes
Browse files Browse the repository at this point in the history
fix: fix markdown link handling and implement delete functionality for offline comics
  • Loading branch information
pushpender-singh-ap authored Dec 31, 2024
2 parents 326a71e + 0aaf319 commit 7513974
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 69 deletions.
4 changes: 4 additions & 0 deletions ios/InkNest/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<false/>
<key>NSAllowsLocalNetworking</key>
<true/>
<key>NSAllowsArbitraryLoadsForMedia</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
<key>NSUserTrackingUsageDescription</key>
<string>We will be used to deliver personalized ads to you.</string>
Expand Down
87 changes: 20 additions & 67 deletions src/Components/UIComp/ChaptersView.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,34 @@
import React, {memo, useEffect, useState} from 'react';
import React, { memo, useState } from 'react';
import {
View,
Text,
StyleSheet,
TouchableOpacity,
FlatList,
ActivityIndicator,
Platform,
} from 'react-native';

import {useDispatch, useSelector} from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import FontAwesome6 from 'react-native-vector-icons/FontAwesome6';
import Entypo from 'react-native-vector-icons/Entypo';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import {
RewardedAd,
RewardedAdEventType,
TestIds,
} from 'react-native-google-mobile-ads';
import {
android_admob_reward_unit_id_download,
ios_admob_reward_unit_id_download,
} from '@env';
import analytics from '@react-native-firebase/analytics';

import {navigate} from '../../Navigation/NavigationService';
import { navigate } from '../../Navigation/NavigationService';
import GalleryPopup from './GalleryPopup';
import {updateData} from '../../Redux/Reducers';
import {NAVIGATION} from '../../Constants';
import { updateData } from '../../Redux/Reducers';
import { NAVIGATION } from '../../Constants';
import Image from './Image';
import {downloadComicBook} from '../../Redux/Actions/Download';
import {fetchComicBook} from '../../Redux/Actions/GlobalActions';
import { downloadComicBook, showRewardedAd } from '../../Redux/Actions/Download';
import { fetchComicBook } from '../../Redux/Actions/GlobalActions';

const adUnitId = __DEV__
? TestIds.REWARDED
: Platform.OS === 'ios'
? ios_admob_reward_unit_id_download
: android_admob_reward_unit_id_download;

const rewarded = RewardedAd.createForAdRequest(adUnitId);

const ChaptersView = ({chapter, Bookmark, ComicDetail}) => {
const ChaptersView = ({ chapter, Bookmark, ComicDetail }) => {
const dispatch = useDispatch();
const ComicBook = useSelector(state => state.data.dataByUrl[chapter.link]);
const isComicDownload = Boolean(
useSelector(
state =>
state?.data?.DownloadComic?.[ComicDetail?.link]?.comicBooks?.[
chapter?.link
chapter?.link
],
),
);
Expand All @@ -56,34 +37,6 @@ const ChaptersView = ({chapter, Bookmark, ComicDetail}) => {
const [OpenModal, setOpenModal] = useState(null);
const [LoadingStatus, setLoadStatus] = useState(false);

useEffect(() => {
const unsubscribeLoaded = rewarded.addAdEventListener(
RewardedAdEventType.LOADED,
() => {
console.log('Ad loaded');
},
);
const unsubscribeEarned = rewarded.addAdEventListener(
RewardedAdEventType.EARNED_REWARD,
reward => {
console.log('User earned reward of ', reward);
},
);

// Start loading the rewarded ad straight away
rewarded.load();

// Unsubscribe from events on unmount
return () => {
unsubscribeLoaded();
unsubscribeEarned();
};
}, [LoadingStatus]);

const loadAdd = async () => {
rewarded.show();
};

const RemoveBookMark = (link, removeItem) => {
//find the item and remove from book mark Bookmarks is a list of numbers
console.log(link, removeItem, Bookmarks);
Expand All @@ -93,7 +46,7 @@ const ChaptersView = ({chapter, Bookmark, ComicDetail}) => {
dispatch(
updateData({
url: link,
data: {BookmarkPages: NewBookmarksList},
data: { BookmarkPages: NewBookmarksList },
}),
);
};
Expand All @@ -116,7 +69,7 @@ const ChaptersView = ({chapter, Bookmark, ComicDetail}) => {
dispatch(
downloadComicBook({
comicDetails: ComicDetail,
comicBook: {...data, link: chapter.link},
comicBook: { ...data, link: chapter.link },
setLoadStatus,
}),
);
Expand Down Expand Up @@ -150,7 +103,7 @@ const ChaptersView = ({chapter, Bookmark, ComicDetail}) => {
});
}}
numberOfLines={2}
style={[styles.label, {width: '70%'}]}>
style={[styles.label, { width: '70%' }]}>
{chapter.title}
</Text>
<View
Expand All @@ -173,14 +126,14 @@ const ChaptersView = ({chapter, Bookmark, ComicDetail}) => {
<FlatList
horizontal
data={Bookmarks}
contentContainerStyle={{gap: 12, marginVertical: 12}}
contentContainerStyle={{ gap: 12, marginVertical: 12 }}
keyExtractor={(item, index) => index.toString()}
renderItem={({item, index}) => {
renderItem={({ item, index }) => {
let comicImage = ComicBook?.images[item];
return (
<TouchableOpacity
onPress={() => {
setOpenModal({index, item});
setOpenModal({ index, item });
}}
style={{
borderRadius: 5,
Expand All @@ -192,7 +145,7 @@ const ChaptersView = ({chapter, Bookmark, ComicDetail}) => {
height: 100,
}}>
<Image
source={{uri: comicImage}}
source={{ uri: comicImage }}
style={{
width: 100,
height: 100,
Expand Down Expand Up @@ -229,10 +182,10 @@ const ChaptersView = ({chapter, Bookmark, ComicDetail}) => {
});
}}
style={styles.chapter}>
<Text style={[styles.label, {width: '80%'}]}>
<Text style={[styles.label, { width: '80%' }]}>
{chapter?.title}
{chapter?.date ? ` (${chapter?.date.split('/')[2]})` : ''}
<Text style={{color: 'steelblue'}}>
<Text style={{ color: 'steelblue' }}>
{ComicBook
? ` - (${ComicBook?.lastReadPage + 1}/${ComicBook?.images.length})`
: ''}
Expand All @@ -248,7 +201,7 @@ const ChaptersView = ({chapter, Bookmark, ComicDetail}) => {
color={'black'}
onPress={() => {
LoadingComic();
loadAdd();
showRewardedAd();
}}
/>
) : (
Expand All @@ -261,7 +214,7 @@ const ChaptersView = ({chapter, Bookmark, ComicDetail}) => {
}}
/>
)}
<View style={{flexDirection: 'row', gap: 12}}>
<View style={{ flexDirection: 'row', gap: 12 }}>
{!numbersBookmarks ? null : (
<View
style={{
Expand Down
3 changes: 2 additions & 1 deletion src/Components/UIComp/MarkDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const parseMarkdown = (text) => {
} else if (line.startsWith('[') && line.includes('](')) {
const endIndex = line.indexOf('](');
const text = line.substring(1, endIndex);
const url = line.substring(endIndex + 2, line.length - 1);
const url = line.substring(endIndex + 2, line.length - 1).replace(/[()]/g, '')

return <Text key={index} style={styles.link} onPress={() => Linking.openURL(url)}> {text}</Text >;
} else {
return <Text key={index} style={styles.paragraph} > {line}</Text >;
Expand Down
11 changes: 10 additions & 1 deletion src/Redux/Reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,17 @@ const Reducers = createSlice({
},
DownloadComicBook: (state, action) => {
const { link, data, title, } = action.payload;

state.DownloadComic[link] = { title, link, comicBooks: { ...state.DownloadComic[link]?.comicBooks, [data.link]: data } };
},
DeleteDownloadedComicBook: (state, action) => {
const { comicBooksLink, ChapterLink } = action.payload;
delete state.DownloadComic[comicBooksLink]?.comicBooks[ChapterLink];
if (Object.keys(state.DownloadComic[comicBooksLink]?.comicBooks).length === 0) {
delete state.DownloadComic[comicBooksLink];
}

},
pushHistory: (state, action) => {
// state.history.push(action.payload);
state.history[action.payload.link] = action.payload;
Expand Down Expand Up @@ -173,5 +181,6 @@ export const {
AddAnimeBookMark,
RemoveAnimeBookMark,
DownloadComicBook,
DeleteDownloadedComicBook
} = Reducers.actions;
export default Reducers.reducer;

0 comments on commit 7513974

Please sign in to comment.