From a9c44ced4fc66eafa8f810a6ef31efe903d08078 Mon Sep 17 00:00:00 2001 From: Rajarshee Chatterjee Date: Sun, 14 May 2023 09:42:12 +0530 Subject: [PATCH] Minor Tracker Fixes --- .gitignore | 3 ++- src/components/List/List.tsx | 13 +++++++++++++ src/hooks/reduxHooks.js | 7 ------- src/redux/hooks/index.ts | 3 +++ src/screens/novel/NovelScreen.js | 16 ++++++++++------ .../novel/components/Tracker/TrackSheet.js | 8 +++----- src/screens/reader/ReaderScreen.js | 10 ++++------ src/services/Trackers/aniList.ts | 2 +- src/services/Trackers/myAnimeList.ts | 6 ++++-- 9 files changed, 40 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index d7d7035c..07ba9d28 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ npm-debug.* *.mobileprovision *.orig.* web-build/ +.env # macOS .DS_Store @@ -76,4 +77,4 @@ web-build/ src/sources/en/generators/ # jenv -.java-version \ No newline at end of file +.java-version diff --git a/src/components/List/List.tsx b/src/components/List/List.tsx index eb7ca8bb..c00090fb 100644 --- a/src/components/List/List.tsx +++ b/src/components/List/List.tsx @@ -9,6 +9,7 @@ interface ListItemProps { title: string; description?: string | null; icon?: string; + right?: string; onPress?: () => void; theme: ThemeColors; } @@ -35,6 +36,7 @@ const Item: React.FC = ({ icon, onPress, theme, + right, }) => ( = ({ ) : undefined } + right={ + right + ? () => ( + + ) + : undefined + } onPress={onPress} rippleColor={theme.rippleColor} style={styles.listItemCtn} diff --git a/src/hooks/reduxHooks.js b/src/hooks/reduxHooks.js index ee37adb2..e020cfc3 100644 --- a/src/hooks/reduxHooks.js +++ b/src/hooks/reduxHooks.js @@ -85,17 +85,10 @@ const usePosition = (novelId, chapterId) => { return position; }; -const useTrackingStatus = () => { - const tracker = useSelector(state => state.trackerReducer); - - return tracker; -}; - export { useSettings, usePreferences, useContinueReading, - useTrackingStatus, useNovel, useChapter, useSavedSettings, diff --git a/src/redux/hooks/index.ts b/src/redux/hooks/index.ts index 1a830b5e..8ea0399e 100644 --- a/src/redux/hooks/index.ts +++ b/src/redux/hooks/index.ts @@ -25,3 +25,6 @@ export const useDownloadQueue = () => export const useSourcesReducer = () => useAppSelector((state: RootState) => state.sourceReducerV2); + +export const useTrackerReducer = () => + useAppSelector(state => state.trackerReducer); diff --git a/src/screens/novel/NovelScreen.js b/src/screens/novel/NovelScreen.js index e3c02c6c..37ac26b2 100644 --- a/src/screens/novel/NovelScreen.js +++ b/src/screens/novel/NovelScreen.js @@ -59,6 +59,7 @@ import useBoolean from '@hooks/useBoolean'; import { useCategorySettings } from '@hooks/useSettings'; import { openChapter } from '../../utils/handleNavigateParams'; import NovelScreenLoading from './components/LoadingAnimation/NovelScreenLoading'; +import { useTrackerReducer } from '@redux/hooks'; const Novel = ({ route, navigation }) => { const item = route.params; @@ -71,6 +72,7 @@ const Novel = ({ route, navigation }) => { const { novel, chapters, loading, updating } = useNovel(); const { downloadQueue } = useSelector(state => state.downloadsReducer); + const { tracker } = useTrackerReducer(); const [selected, setSelected] = useState([]); const [downloadMenu, showDownloadMenu] = useState(false); @@ -713,12 +715,14 @@ const Novel = ({ route, navigation }) => { filter={filter} showChapterTitles={showChapterTitles} /> - + {tracker ? ( + + ) : null} ); diff --git a/src/screens/novel/components/Tracker/TrackSheet.js b/src/screens/novel/components/Tracker/TrackSheet.js index 1196cf20..cdbeb9a4 100644 --- a/src/screens/novel/components/Tracker/TrackSheet.js +++ b/src/screens/novel/components/Tracker/TrackSheet.js @@ -3,7 +3,8 @@ import { StyleSheet, View, ToastAndroid } from 'react-native'; import { overlay, Portal } from 'react-native-paper'; import BottomSheet from '@components/BottomSheet/BottomSheet'; -import { useSelector, useDispatch } from 'react-redux'; +import { useDispatch } from 'react-redux'; +import { useTrackerReducer } from '@redux/hooks'; import { updateTracker } from '../../../../redux/tracker/tracker.actions'; import TrackSearchDialog from './TrackSearchDialog'; @@ -13,10 +14,7 @@ import SetTrackChaptersDialog from './SetTrackChaptersDialog'; import { AddTrackingCard, TrackedItemCard } from './TrackerCards'; const TrackSheet = ({ bottomSheetRef, novelId, novelName, theme }) => { - const tracker = useSelector(state => state.trackerReducer.tracker); - const trackedNovels = useSelector( - state => state.trackerReducer.trackedNovels, - ); + const { tracker, trackedNovels } = useTrackerReducer(); const dispatch = useDispatch(); const [trackItem, setTrackItem] = useState(); diff --git a/src/screens/reader/ReaderScreen.js b/src/screens/reader/ReaderScreen.js index 7d64ba1f..aabdfefd 100644 --- a/src/screens/reader/ReaderScreen.js +++ b/src/screens/reader/ReaderScreen.js @@ -12,11 +12,9 @@ import { } from '../../database/queries/ChapterQueries'; import { fetchChapter } from '../../services/Source/source'; import { showToast } from '../../hooks/showToast'; -import { - usePosition, - useSettings, - useTrackingStatus, -} from '../../hooks/reduxHooks'; +import { usePosition, useSettings } from '../../hooks/reduxHooks'; +import { useTrackerReducer } from '@redux/hooks'; + import { useTheme } from '@hooks/useTheme'; import { updateChaptersRead } from '../../redux/tracker/tracker.actions'; import { markChapterReadAction } from '../../redux/novel/novel.actions'; @@ -98,7 +96,7 @@ const ChapterContent = ({ route, navigation }) => { const position = usePosition(novelId, chapterId); const minScroll = useRef(0); - const { tracker, trackedNovels } = useTrackingStatus(); + const { tracker, trackedNovels } = useTrackerReducer(); const isTracked = trackedNovels.find(obj => obj.novelId === novelId); const [chapter, setChapter] = useState({}); diff --git a/src/services/Trackers/aniList.ts b/src/services/Trackers/aniList.ts index 19492b4e..818509f8 100644 --- a/src/services/Trackers/aniList.ts +++ b/src/services/Trackers/aniList.ts @@ -7,7 +7,7 @@ import { } from './index'; const apiEndpoint = 'https://graphql.anilist.co'; -const clientId = '9085'; +const clientId = process.env.ANILIST_CLIENT_ID; const authUrl = `https://anilist.co/api/v2/oauth/authorize?client_id=${clientId}&response_type=token`; const redirectUri = Linking.createURL(''); const searchQuery = `query($search: String) { diff --git a/src/services/Trackers/myAnimeList.ts b/src/services/Trackers/myAnimeList.ts index 81046736..fdaa98f2 100644 --- a/src/services/Trackers/myAnimeList.ts +++ b/src/services/Trackers/myAnimeList.ts @@ -3,7 +3,7 @@ import * as WebBrowser from 'expo-web-browser'; import qs from 'qs'; import { createTracker, type UserListStatus } from './index'; -const clientId = 'd2f499825d64b0213bb77e78193ccbb1'; +const clientId = process.env.MYANIMELIST_CLIENT_ID; const baseOAuthUrl = 'https://myanimelist.net/v1/oauth2/authorize'; const tokenUrl = 'https://myanimelist.net/v1/oauth2/token'; const baseApiUrl = 'https://api.myanimelist.net/v2'; @@ -110,6 +110,7 @@ export const myAnimeListTracker = createTracker('MyAnimeList', { const response = await fetch(url, { headers: { Authorization: `Bearer ${auth.accessToken}`, + 'Content-Type': 'application/x-www-form-urlencoded', }, }); @@ -122,7 +123,7 @@ export const myAnimeListTracker = createTracker('MyAnimeList', { }; }, updateUserListEntry: async (id, payload, auth) => { - let status = normalizedToMal[payload.status]; + let status = normalizedToMal[payload.status] || normalizedToMal.CURRENT; let repeating = false; if (status.includes(';')) { const split = status.split(';'); @@ -135,6 +136,7 @@ export const myAnimeListTracker = createTracker('MyAnimeList', { method: 'PUT', headers: { Authorization: `Bearer ${auth.accessToken}`, + 'Content-Type': 'application/x-www-form-urlencoded', }, body: qs.stringify({ status,