From 28b65e35d2d6427cfc06ccdcf358de478b1c4dca Mon Sep 17 00:00:00 2001 From: Rajarshee Chatterjee Date: Thu, 17 Aug 2023 22:24:09 +0530 Subject: [PATCH] Refactor App Update Checker --- App.js | 4 +- src/components/NewUpdateDialog.tsx | 58 +++++++++-------- src/hooks/githubUpdateChecker.js | 57 ---------------- src/hooks/index.ts | 1 + src/hooks/reduxHooks.js | 7 -- src/hooks/useReleaseChecker.ts | 65 +++++++++++++++++++ ...BottomNavigator.js => BottomNavigator.tsx} | 1 - src/navigators/Main.js | 5 -- 8 files changed, 100 insertions(+), 98 deletions(-) delete mode 100644 src/hooks/githubUpdateChecker.js create mode 100644 src/hooks/useReleaseChecker.ts rename src/navigators/{BottomNavigator.js => BottomNavigator.tsx} (98%) diff --git a/App.js b/App.js index 12b9d158..72ee6e50 100644 --- a/App.js +++ b/App.js @@ -12,13 +12,14 @@ import { Provider as PaperProvider } from 'react-native-paper'; import { Provider } from 'react-redux'; import { PersistGate } from 'redux-persist/lib/integration/react'; import * as Notifications from 'expo-notifications'; +import { BottomSheetModalProvider } from '@gorhom/bottom-sheet'; import { createDatabase } from '@database/db'; import { persistor, store } from '@redux/store'; import AppErrorBoundary from '@components/AppErrorBoundary/AppErrorBoundary'; +import NewUpdateDialog from '@components/NewUpdateDialog'; import Main from './src/navigators/Main'; -import { BottomSheetModalProvider } from '@gorhom/bottom-sheet'; // Initialize trackers import './src/services/Trackers/index'; @@ -49,6 +50,7 @@ const App = () => { +
diff --git a/src/components/NewUpdateDialog.tsx b/src/components/NewUpdateDialog.tsx index 32715afa..94f04fbb 100644 --- a/src/components/NewUpdateDialog.tsx +++ b/src/components/NewUpdateDialog.tsx @@ -1,52 +1,57 @@ -import React, { useState } from 'react'; -import { StyleSheet, View, Text, Dimensions } from 'react-native'; +import React, { useEffect } from 'react'; +import { ScrollView, StyleSheet, View, Text, Dimensions } from 'react-native'; import { Portal, Modal } from 'react-native-paper'; import * as Linking from 'expo-linking'; -import { ScrollView } from 'react-native-gesture-handler'; -import Button from './Button/Button'; + +import { Button } from '@components'; + +import { useBoolean, useReleaseChecker, useTheme } from '@hooks'; import { getString } from '@strings/translations'; -import { useTheme } from '@hooks/useTheme'; - -interface NewUpdateDialogProps { - newVersion: { - tag_name: string; - body: string; - downloadUrl: string; - }; -} - -const NewUpdateDialog: React.FC = ({ newVersion }) => { - const [newUpdateDialog, showNewUpdateDialog] = useState(true); - +const NewUpdateDialog: React.FC = () => { const theme = useTheme(); + const newRelease = useReleaseChecker(); + + const { + value: isVisible, + setFalse: hideModal, + setValue: setModalVisible, + } = useBoolean(); + + useEffect(() => { + setModalVisible(Boolean(newRelease)); + }, [newRelease]); + const modalHeight = Dimensions.get('window').height / 2; + if (!newRelease) { + return null; + } + return ( showNewUpdateDialog(false)} + visible={isVisible} + onDismiss={hideModal} contentContainerStyle={[ styles.containerStyle, { backgroundColor: theme.overlay3 }, ]} > - {`${getString('common.newUpdateAvailable')} ${newVersion.tag_name}`} + {`${getString('common.newUpdateAvailable')} ${newRelease?.tagName}`} - {newVersion.body} + + {newRelease?.changelog} + -