11import React , { useState , useEffect } from 'react' ;
2- import { TextInput , View , Text , TouchableOpacity , StyleSheet , PermissionsAndroid , Platform , Modal } from 'react-native' ;
2+ import { TextInput , View , Text , TouchableOpacity , StyleSheet , Modal } from 'react-native' ;
33import RNFS from 'react-native-fs' ;
4+ import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome' ;
5+ import { faCamera , faCalendar , faSave , faPen , faUserGroup , faFileImport , faGear } from '@fortawesome/free-solid-svg-icons' ;
6+ import { faGoogle , faMicrosoft , faLinkedin , faTwitter } from '@fortawesome/free-brands-svg-icons' ;
47import { launchCamera , CameraOptions } from 'react-native-image-picker' ;
58import { request , PERMISSIONS , RESULTS } from 'react-native-permissions' ;
69import { Calendar , DateData } from 'react-native-calendars' ;
710import SQLite , { SQLiteDatabase , Transaction , ResultSet } from 'react-native-sqlite-storage' ;
11+ import { PermissionsAndroid , Platform , Alert , Linking } from 'react-native' ;
12+ import { GoogleSignin , statusCodes } from '@react-native-google-signin/google-signin' ;
813
914const App = ( ) => {
1015 const [ inputText , setInputText ] = useState ( '' ) ;
1116 const [ isCalendarVisible , setIsCalendarVisible ] = useState ( false ) ;
17+ const [ isLoginVisible , setIsLoginVisible ] = useState ( false ) ;
1218 const [ selectedDate , setSelectedDate ] = useState ( '' ) ;
1319 const [ dbData , setDbData ] = useState < any [ ] > ( [ ] ) ;
1420
@@ -32,7 +38,15 @@ const App = () => {
3238
3339 // In the useEffect:
3440 useEffect ( ( ) => {
35- const dbPath = `${ RNFS . DocumentDirectoryPath } /database_default.sqlite3` ;
41+
42+ GoogleSignin . configure ( {
43+ webClientId : "enter_web_client_id" , // Client ID from Google Developer Console
44+ offlineAccess : true , // if you want to access Google API on behalf of the user FROM YOUR SERVER
45+ scopes : [ 'profile' , 'email' , 'openid' ] , // array of scopes
46+ } ) ;
47+
48+ // requestPermissions();
49+ const dbPath = '/data/data/com.socialmediaschedulerapp/databases/database_default.sqlite3' ;
3650 console . log ( 'Database path:' , dbPath ) ;
3751
3852 const listDirectoryContents = async ( path : string ) => {
@@ -43,8 +57,8 @@ const App = () => {
4357 console . error ( 'Error reading directory:' , error ) ;
4458 }
4559 } ;
46-
47- listDirectoryContents ( RNFS . DocumentDirectoryPath ) ;
60+ console . log ( 'Document directory path:' , RNFS . DocumentDirectoryPath ) ;
61+ listDirectoryContents ( '/data/data/com.socialmediaschedulerapp/databases' ) ;
4862
4963 RNFS . exists ( dbPath )
5064 . then ( ( exists ) => {
@@ -60,7 +74,8 @@ const App = () => {
6074 console . log ( 'Error opening database:' , error ) ;
6175 }
6276 ) ;
63- } else {
77+ } else
78+ {
6479 const filePath = `${ RNFS . DocumentDirectoryPath } /database_default.sqlite3` ;
6580 RNFS . writeFile ( filePath , '' , 'utf8' )
6681 . then ( ( ) => {
@@ -171,6 +186,24 @@ const App = () => {
171186
172187 const fetchDbData = ( db : SQLiteDatabase ) => {
173188 db . transaction ( ( tx : Transaction ) => {
189+ // print all tables
190+ tx . executeSql ( "SELECT name FROM sqlite_master WHERE type='table'" , [ ] , ( tx : Transaction , results : ResultSet ) => {
191+ const rows = results . rows ;
192+ for ( let i = 0 ; i < rows . length ; i ++ ) {
193+ console . log ( 'Table:' , rows . item ( i ) . name ) ;
194+ }
195+ } ) ;
196+
197+ // fetch all data from all tables
198+ tx . executeSql ( 'SELECT * FROM users' , [ ] , ( tx : Transaction , results : ResultSet ) => {
199+ const rows = results . rows ;
200+ let data : any [ ] = [ ] ;
201+ for ( let i = 0 ; i < rows . length ; i ++ ) {
202+ data . push ( rows . item ( i ) ) ;
203+ }
204+ console . log ( 'Fetched data:' , data ) ;
205+ } ) ;
206+
174207 tx . executeSql ( 'SELECT * FROM content' , [ ] , ( tx : Transaction , results : ResultSet ) => {
175208 const rows = results . rows ;
176209 let data : any [ ] = [ ] ;
@@ -187,11 +220,17 @@ const App = () => {
187220 const requestPermissions = async ( ) => {
188221 if ( Platform . OS === 'android' ) {
189222 try {
190- const granted = await PermissionsAndroid . requestMultiple ( [
223+ const permissions = [
191224 PermissionsAndroid . PERMISSIONS . CAMERA ,
192225 PermissionsAndroid . PERMISSIONS . WRITE_EXTERNAL_STORAGE ,
193226 PermissionsAndroid . PERMISSIONS . READ_EXTERNAL_STORAGE ,
194- ] ) ;
227+ ] ;
228+ console . log ( 'Requesting permissions:' , permissions ) ; // Log the permissions being requested
229+
230+ const granted = await PermissionsAndroid . requestMultiple ( permissions ) ;
231+
232+ console . log ( 'Permissions granted:' , granted ) ; // Log the results
233+
195234 if (
196235 granted [ PermissionsAndroid . PERMISSIONS . CAMERA ] === PermissionsAndroid . RESULTS . GRANTED &&
197236 granted [ PermissionsAndroid . PERMISSIONS . WRITE_EXTERNAL_STORAGE ] === PermissionsAndroid . RESULTS . GRANTED &&
@@ -251,39 +290,82 @@ const App = () => {
251290 setIsCalendarVisible ( true ) ;
252291 } ;
253292
293+ const signUP = ( ) => {
294+ setIsLoginVisible ( true ) ;
295+ }
296+
297+ const handleLogin = async ( provider : string ) => {
298+ if ( provider === 'Google' ) {
299+ try {
300+ console . log ( 'Google login' ) ;
301+ await GoogleSignin . hasPlayServices ( ) ;
302+ const userInfo = await GoogleSignin . signIn ( ) ;
303+ console . log ( userInfo ) ;
304+ // You can now use the userInfo object, which contains user's information and tokens
305+ } catch ( error ) {
306+ if ( error instanceof Error && 'code' in error ) {
307+ if ( error . code === statusCodes . SIGN_IN_CANCELLED ) {
308+ console . log ( 'User cancelled the login process' ) ;
309+ } else if ( error . code === statusCodes . IN_PROGRESS ) {
310+ console . log ( 'Login is already in progress' ) ;
311+ } else if ( error . code === statusCodes . PLAY_SERVICES_NOT_AVAILABLE ) {
312+ console . log ( 'Play Services not available or outdated' ) ;
313+ } else {
314+ console . log ( 'Some other error occurred' , error ) ;
315+ }
316+ } else {
317+ console . log ( 'An unknown error occurred' , error ) ;
318+ }
319+ }
320+ }
321+ } ;
322+
254323 const onDayPress = ( day : DateData ) => {
255324 setSelectedDate ( day . dateString ) ;
256- setIsCalendarVisible ( false ) ;
325+ // setIsCalendarVisible(false);
257326 console . log ( 'Selected date: ' , day . dateString ) ;
258327 } ;
259328
260329 return (
261330 < View style = { styles . container } >
262331 < Text style = { styles . title } > Social media scheduler</ Text >
263- < View style = { styles . captureContainer } >
264- < TouchableOpacity onPress = { takePicture } style = { styles . capture } >
265- < Text style = { styles . captureText } > SNAP</ Text >
266- </ TouchableOpacity >
267- </ View >
268332
269333 < View style = { styles . captureContainer } >
270- < TouchableOpacity onPress = { capturePost } style = { styles . capture } >
271- < Text style = { styles . captureText } > POST</ Text >
334+ { /* <TouchableOpacity onPress={schedulePost} style={styles.capture}> */ }
335+ < TouchableOpacity onPress = { signUP } style = { styles . capture } >
336+ < Text style = { styles . captureText } > Sign Up</ Text >
272337 </ TouchableOpacity >
273338 </ View >
274339
275- < View style = { styles . captureContainer } >
276- < TouchableOpacity onPress = { schedulePost } style = { styles . capture } >
277- < Text style = { styles . captureText } > SCHEDULE</ Text >
340+ { /* login modal */ }
341+ < Modal
342+ presentationStyle = "fullScreen"
343+ // visible={isCalendarVisible}
344+ visible = { isLoginVisible }
345+ animationType = "slide"
346+ onRequestClose = { ( ) => setIsLoginVisible ( false ) }
347+ >
348+ < View style = { styles . modalContainer } >
349+ < Text style = { styles . title } > Login</ Text >
350+ < TouchableOpacity style = { styles . loginButton } onPress = { ( ) => handleLogin ( 'Google' ) } >
351+ < FontAwesomeIcon icon = { faGoogle } size = { 24 } />
352+ < Text style = { styles . loginText } > Login with Google</ Text >
353+ </ TouchableOpacity >
354+ < TouchableOpacity style = { styles . loginButton } onPress = { ( ) => handleLogin ( 'Microsoft' ) } >
355+ < FontAwesomeIcon icon = { faMicrosoft } size = { 24 } />
356+ < Text style = { styles . loginText } > Login with Microsoft</ Text >
357+ </ TouchableOpacity >
358+ < TouchableOpacity style = { styles . loginButton } onPress = { ( ) => handleLogin ( 'LinkedIn' ) } >
359+ < FontAwesomeIcon icon = { faLinkedin } size = { 24 } />
360+ < Text style = { styles . loginText } > Login with LinkedIn</ Text >
361+ </ TouchableOpacity >
362+ < TouchableOpacity style = { styles . loginButton } onPress = { ( ) => handleLogin ( 'Twitter' ) } >
363+ < FontAwesomeIcon icon = { faTwitter } size = { 24 } />
364+ < Text style = { styles . loginText } > Login with Twitter</ Text >
278365 </ TouchableOpacity >
279366 </ View >
367+ </ Modal >
280368
281- < TextInput
282- style = { styles . textInput }
283- placeholder = "Enter text to save"
284- value = { inputText }
285- onChangeText = { setInputText }
286- />
287369
288370 < Modal
289371 presentationStyle = "fullScreen"
@@ -307,16 +389,49 @@ const App = () => {
307389 } ,
308390 } }
309391 />
392+
393+
394+
395+ < View style = { styles . footerNavBar } >
396+ < TouchableOpacity style = { styles . navButton } >
397+ < FontAwesomeIcon icon = { faUserGroup } size = { 24 } />
398+ < Text > Accounts</ Text >
399+ </ TouchableOpacity >
400+
401+ < TouchableOpacity style = { [ styles . navButton ] } disabled = { true } >
402+ < FontAwesomeIcon icon = { faFileImport } style = { styles . disabledText } size = { 24 } />
403+ < Text style = { styles . disabledText } > Import</ Text >
404+ </ TouchableOpacity >
405+
406+ < TouchableOpacity style = { [ styles . navButton ] } disabled = { true } onPress = { capturePost } >
407+ < FontAwesomeIcon icon = { faPen } style = { styles . disabledText } size = { 24 } />
408+ < Text style = { styles . disabledText } > Post/Tweet</ Text >
409+ </ TouchableOpacity >
410+
411+ < TouchableOpacity style = { [ styles . navButton ] } disabled = { true } onPress = { takePicture } >
412+ { /* <TouchableOpacity style={[styles.navButton]} onPress={takePicture}> */ }
413+ < FontAwesomeIcon icon = { faCamera } style = { styles . disabledText } size = { 24 } />
414+ < Text style = { styles . disabledText } > Camera</ Text >
415+ </ TouchableOpacity >
416+
417+
418+ < TouchableOpacity style = { styles . navButton } >
419+ < FontAwesomeIcon icon = { faGear } size = { 24 } />
420+ < Text > Settings</ Text >
421+ </ TouchableOpacity >
422+
423+ </ View >
424+
310425 </ Modal >
311426
312- < View >
427+ { /* <View>
313428 <Text style={styles.title}>Database Data:</Text>
314429 {dbData.map((item, index) => (
315430 <Text key={index} style={styles.dbText}>
316431 {JSON.stringify(item)}
317432 </Text>
318433 ))}
319- </ View >
434+ </View> */ }
320435 </ View >
321436 ) ;
322437} ;
@@ -375,6 +490,40 @@ const styles = StyleSheet.create({
375490 dbText : {
376491 color : 'white' ,
377492 } ,
493+ footerNavBar : {
494+ flexDirection : 'row' ,
495+ justifyContent : 'space-around' ,
496+ alignItems : 'center' ,
497+ height : 60 ,
498+ backgroundColor : '#f8f8f8' ,
499+ borderTopWidth : 1 ,
500+ borderColor : '#e7e7e7' ,
501+ position : 'absolute' ,
502+ bottom : 0 ,
503+ width : '100%' ,
504+ } ,
505+ navButton : {
506+ justifyContent : 'center' ,
507+ alignItems : 'center' ,
508+ } ,
509+ disabledButton : {
510+ backgroundColor : '#d3d3d3' , // Grey background for disabled state
511+ } ,
512+ disabledText : {
513+ color : '#a9a9a9' , // Grey text color for disabled state
514+ } ,
515+ loginButton : {
516+ flexDirection : 'row' ,
517+ alignItems : 'center' ,
518+ padding : 10 ,
519+ margin : 10 ,
520+ backgroundColor : '#f0f0f0' ,
521+ borderRadius : 5 ,
522+ } ,
523+ loginText : {
524+ marginLeft : 10 ,
525+ fontSize : 18 ,
526+ }
378527} ) ;
379528
380529
0 commit comments