Skip to content

Commit 3ca72ac

Browse files
Refactor reward tracking in ComicDetails component (#56)
* refactor: remove reward tracking logic from Redux state and ComicDetails component * feat: add reward ads tracking and update state management in ComicDetails --------- Co-authored-by: Prem Kumar Sharma <[email protected]>
1 parent e3c19d8 commit 3ca72ac

File tree

3 files changed

+18
-32
lines changed

3 files changed

+18
-32
lines changed

src/Redux/Reducers/index.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const initialState = {
1212
AnimeWatched: {},
1313
AnimeBookMarks: {},
1414
DownloadComic: {},
15-
rewardShown: {}, // Track comics that have shown rewards during this session
1615
scrollPreference: 'horizontal', // Default scroll mode is horizontal
16+
hasRewardAdsShown: false,
1717
};
1818

1919
/**
@@ -192,18 +192,14 @@ const Reducers = createSlice({
192192
RemoveAnimeBookMark: (state, action) => {
193193
delete state.AnimeBookMarks[action?.payload?.url];
194194
},
195-
markRewardShown: (state, action) => {
196-
// Mark specific comic as having shown a reward
197-
state.rewardShown[action.payload] = true;
198-
},
199-
resetRewards: (state) => {
200-
// Reset all reward tracking (e.g., on app restart)
201-
state.rewardShown = {};
202-
},
203195
setScrollPreference: (state, action) => {
204196
// Update user's preferred comic reading scroll mode
205197
state.scrollPreference = action.payload;
206198
},
199+
rewardAdsShown: (state, action) => {
200+
// Update the flag indicating whether reward ads have been shown
201+
state.hasRewardAdsShown = action.payload;
202+
},
207203
},
208204
});
209205

@@ -226,8 +222,7 @@ export const {
226222
DownloadComicBook,
227223
DeleteDownloadedComicBook,
228224
clearHistory,
229-
markRewardShown,
230-
resetRewards,
231225
setScrollPreference,
226+
rewardAdsShown,
232227
} = Reducers.actions;
233228
export default Reducers.reducer;

src/Redux/Store/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Reducers from '../Reducers';
66
const persistConfig = {
77
key: 'root',
88
storage: storage,
9-
blacklist: ['error', 'status', 'loading', 'downTime'],
9+
blacklist: ['error', 'status', 'loading', 'downTime', 'hasRewardAdsShown'],
1010
};
1111

1212
const persistedReducer = persistReducer(persistConfig, Reducers);

src/Screens/Comic/Details/index.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import ChapterCard from './ChapterCard';
1313
import HeaderComponent from './Components/HeaderComponent';
1414
import {AppendAd} from '../../../InkNest-Externals/Ads/AppendAd';
1515
import PaginationFooter from './Components/FooterPagination';
16+
import {rewardAdsShown} from '../../../Redux/Reducers';
1617
import {showRewardedAd} from '../../../InkNest-Externals/Redux/Actions/Download';
17-
import {markRewardShown} from '../../../Redux/Reducers';
1818

1919
export function ComicDetails({route, navigation}) {
2020
const [PageLink, setPageLink] = useState(route?.params?.link);
@@ -34,7 +34,7 @@ export function ComicDetails({route, navigation}) {
3434
const loading = useSelector(state => state.data.loading);
3535
const error = useSelector(state => state.data.error);
3636
const ComicDetail = useSelector(state => state.data.dataByUrl[PageLink]);
37-
const rewardShown = useSelector(state => state.data.rewardShown);
37+
const hasRewardAdsShown = useSelector(state => state.data.hasRewardAdsShown);
3838

3939
const reverseChapterList = () => {
4040
if (getVersion() === forIosValue && forIosLoading === false) {
@@ -70,27 +70,18 @@ export function ComicDetails({route, navigation}) {
7070
}
7171
};
7272

73-
// Check and show reward for first visit
7473
useEffect(() => {
75-
const showRewardForFirstVisit = async () => {
76-
// Only show reward if it hasn't been shown for this comic yet
77-
if (PageLink && !rewardShown[PageLink]) {
78-
crashlytics().log('Comic Details First Visit Reward Shown');
79-
analytics().logEvent('comic_details_first_visit_reward', {
80-
pageLink: PageLink,
81-
});
82-
83-
// Show the reward
74+
(async () => {
75+
if (!hasRewardAdsShown) {
76+
crashlytics().log('Reward Ads Shown');
77+
analytics().logEvent('Reward_Ads_Shown');
8478
await showRewardedAd();
85-
86-
// Mark this comic as having shown a reward
87-
dispatch(markRewardShown(PageLink));
79+
dispatch(rewardAdsShown(!hasRewardAdsShown));
8880
}
89-
};
90-
91-
showRewardForFirstVisit();
92-
}, [PageLink, rewardShown]);
93-
81+
})();
82+
}, [hasRewardAdsShown]);
83+
84+
9485
useEffect(() => {
9586
if (getVersion() === forIosValue && forIosLoading === false) {
9687
} else {

0 commit comments

Comments
 (0)