From 7f48e37d64fe00c802dc4c15b9d2ede3ac6e0ecc Mon Sep 17 00:00:00 2001 From: YoussefFouadd Date: Sun, 25 Aug 2024 15:58:22 +0300 Subject: [PATCH 01/10] Adding buttons to ReactNative --- examples/default/src/navigation/HomeStack.tsx | 17 ++ .../src/screens/CrashReportingScreen.tsx | 24 +- .../src/screens/FeatureRequestsScreen.tsx | 28 ++- examples/default/src/screens/HomeScreen.tsx | 1 + .../default/src/screens/LegacyModeScreen.tsx | 228 +++++++++++++++++ .../default/src/screens/SettingsScreen.tsx | 14 +- .../default/src/screens/apm/APMScreen.tsx | 38 ++- .../default/src/screens/apm/HttpScreen.tsx | 236 ++++++++++++++++++ .../default/src/screens/apm/NetworkScreen.tsx | 14 +- 9 files changed, 594 insertions(+), 6 deletions(-) create mode 100644 examples/default/src/screens/LegacyModeScreen.tsx create mode 100644 examples/default/src/screens/apm/HttpScreen.tsx diff --git a/examples/default/src/navigation/HomeStack.tsx b/examples/default/src/navigation/HomeStack.tsx index b4a8ca3e6..94f99d422 100644 --- a/examples/default/src/navigation/HomeStack.tsx +++ b/examples/default/src/navigation/HomeStack.tsx @@ -26,6 +26,10 @@ import { TracesScreen } from '../screens/apm/TracesScreen'; import { NetworkScreen } from '../screens/apm/NetworkScreen'; import { FlowsScreen } from '../screens/apm/FlowsScreen'; import { SessionReplayScreen } from '../screens/SessionReplayScreen'; +import { LegacyModeScreen } from '../screens/LegacyModeScreen'; +import { HttpScreen } from '../screens/apm/HttpScreen'; + + export type HomeStackParamList = { Home: undefined; @@ -45,6 +49,9 @@ export type HomeStackParamList = { LargeImageList: undefined; SessionReplay: undefined; BackAndForthScreen: BackAndForthScreenProp; + LegacyMode:undefined; + HttpScreen:undefined; + // APM // APM: undefined; @@ -132,6 +139,16 @@ export const HomeStackNavigator: React.FC = () => { + + ); }; diff --git a/examples/default/src/screens/CrashReportingScreen.tsx b/examples/default/src/screens/CrashReportingScreen.tsx index c5a53567f..68c32519f 100644 --- a/examples/default/src/screens/CrashReportingScreen.tsx +++ b/examples/default/src/screens/CrashReportingScreen.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { Alert, Platform, ScrollView, StyleSheet, Text, View } from 'react-native'; +import { Alert, Platform, ScrollView, StyleSheet, Text, View,Switch,ToastAndroid } from 'react-native'; import { CrashReporting, NonFatalErrorLevel } from 'instabug-reactnative'; @@ -25,6 +25,7 @@ const styles = StyleSheet.create({ }, }); + export const CrashReportingScreen: React.FC = () => { function throwHandledException(error: Error) { try { @@ -61,6 +62,7 @@ export const CrashReportingScreen: React.FC = () => { throw error; } } + const [isEnabled, setIsEnabled] = useState(false); const [userAttributeKey, setUserAttributeKey] = useState(''); const [userAttributeValue, setUserAttributeValue] = useState(''); @@ -70,6 +72,21 @@ export const CrashReportingScreen: React.FC = () => { NonFatalErrorLevel.error, ); + const toggleSwitch = (value: boolean) => { + setIsEnabled(value); + + // Update APM state here + CrashReporting.setEnabled(value); + // Show Toast message + + if (Platform.OS === 'android') { + ToastAndroid.show('Crash Reporting set to ' + value, ToastAndroid.SHORT); + } else { + Alert.alert('Crash Reporting set to ' + value); + } + + } + function sendCrash() { try { const error = new Error(crashNameValue); @@ -99,6 +116,11 @@ export const CrashReportingScreen: React.FC = () => { return ( + Crash Reporting Enabled: +
{ + const [isEnabled, setIsEnabled] = useState(false); + + + const toggleSwitch = (value: boolean) => { + setIsEnabled(value); + + // Update APM state here + FeatureRequests.setEmailFieldRequired(value, [ActionType.requestNewFeature]); + // Show Toast message + + if (Platform.OS === 'android') { + ToastAndroid.show('Email field required set to ' + value, ToastAndroid.SHORT); + } else { + Alert.alert('Email field required set to ' + value); + } + + }; return ( + Email field Required: + FeatureRequests.show()} /> ); diff --git a/examples/default/src/screens/HomeScreen.tsx b/examples/default/src/screens/HomeScreen.tsx index 690d41cc2..7a5aeeb46 100644 --- a/examples/default/src/screens/HomeScreen.tsx +++ b/examples/default/src/screens/HomeScreen.tsx @@ -19,6 +19,7 @@ export const HomeScreen: React.FC navigation.navigate('UserSteps')} /> navigation.navigate('APM')} /> navigation.navigate('SessionReplay')} /> + navigation.navigate('LegacyMode')} /> ); }; diff --git a/examples/default/src/screens/LegacyModeScreen.tsx b/examples/default/src/screens/LegacyModeScreen.tsx new file mode 100644 index 000000000..14721b798 --- /dev/null +++ b/examples/default/src/screens/LegacyModeScreen.tsx @@ -0,0 +1,228 @@ +import React from 'react'; + +import {useState } from 'react'; +import {Text,Switch,ToastAndroid,Platform, ActivityIndicator,Alert,View,StyleSheet } from 'react-native'; +import Instabug, { WelcomeMessageMode,BugReporting,APM, InvocationOption, ReportType } from 'instabug-reactnative'; + + +import { ListTile } from '../components/ListTile'; +import axios from 'axios'; + +import { Screen } from '../components/Screen'; + + + + +export const LegacyModeScreen: React.FC = () => { + const [loading, setLoading] = useState(false); + const [response, setResponse] = useState(null); + + const logInstabug = (log:string): Promise => { + return new Promise((resolve) => { + setTimeout(() => { + Instabug.logDebug(log); + resolve(); + }, 100); // Simulate some asynchronous operation + }); +}; +// const logNetwork = (event:string): Promise => { +// return new Promise((resolve) => { +// setTimeout(() => { +// Instabug.logUserEvent(event); +// resolve(); +// }, 100); // Simulate some asynchronous operation +// }); +// }; +const logUserEvent = (event:string): Promise => { + return new Promise((resolve) => { + setTimeout(() => { + Instabug.logUserEvent(event); + resolve(); + }, 100); // Simulate some asynchronous operation + }); +}; +const addTag = (tag:string): Promise => { + return new Promise((resolve) => { + setTimeout(() => { + Instabug.appendTags([tag]); + resolve(); + }, 100); // Simulate some asynchronous operation + }); +}; +const addUserAttributes = (key:string,value:string): Promise => { + return new Promise((resolve) => { + setTimeout(() => { + Instabug.setUserAttribute(key,value); + resolve(); + }, 100); // Simulate some asynchronous operation + }); +}; + + const getInstabugLogs = async (numberOfLogs: number) => { + setLoading(true); + try { + const logPromises = []; + for (let i = 0; i < numberOfLogs; i++) { + logPromises.push(logInstabug(`log ${i}`)); + } + + await Promise.all(logPromises); + // Logs completed + if (Platform.OS === 'android') { + ToastAndroid.show('Succeeded', ToastAndroid.SHORT); + } else { + Alert.alert('Success', 'Succeeded'); + } + + } catch (error) { + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } finally { + setLoading(false); + } +}; + + + // const getNetworkLogs = async (numberOfLogs: number) => { + + // setLoading(true); + // try { + // const logPromises = []; + // for (let i = 0; i < numberOfLogs; i++) { + // logPromises.push(logNetwork(`log ${i}`)); + // } + + // await Promise.all(logPromises); + // // Logs completed + // if (Platform.OS === 'android') { + // ToastAndroid.show('Succeeded', ToastAndroid.SHORT); + // } else { + // Alert.alert('Success', 'Succeeded'); + // } + + // } catch (error) { + // if (Platform.OS === 'android') { + // ToastAndroid.show('Failed', ToastAndroid.SHORT); + // } else { + // Alert.alert('Error', 'Failed'); + // } + // } finally { + // setLoading(false); + // } + + // } + + + + const getUserEvents = async (numberOfLogs: number) => { + setLoading(true); + try { + const logPromises = []; + for (let i = 0; i < numberOfLogs; i++) { + logPromises.push(logUserEvent(`test user event ${i}`)); + } + + await Promise.all(logPromises); + // Logs completed + if (Platform.OS === 'android') { + ToastAndroid.show('Succeeded', ToastAndroid.SHORT); + } else { + Alert.alert('Success', 'Succeeded'); + } + + } catch (error) { + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } finally { + setLoading(false); + } +}; + + + const getTags = async (numberOfLogs: number) => { + + setLoading(true); + try { + const logPromises = []; + for (let i = 0; i < numberOfLogs; i++) { + logPromises.push(addTag(`test tag ${i}`)); + } + + await Promise.all(logPromises); + // Logs completed + if (Platform.OS === 'android') { + ToastAndroid.show('Succeeded', ToastAndroid.SHORT); + } else { + Alert.alert('Success', 'Succeeded'); + } + + } catch (error) { + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } finally { + setLoading(false); + } + + } + + + const getUserAttributes = async (numberOfLogs: number) => { + + setLoading(true); + try { + const logPromises = []; + for (let i = 0; i < numberOfLogs; i++) { + logPromises.push(addUserAttributes(`user${i}`, `user${i} value`)); + } + + await Promise.all(logPromises); + // Logs completed + if (Platform.OS === 'android') { + ToastAndroid.show('Succeeded', ToastAndroid.SHORT); + } else { + Alert.alert('Success', 'Succeeded'); + } + + } catch (error) { + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } finally { + setLoading(false); + } + + } + + // Similar functions for PUT, DELETE, etc. can be added here + + return ( + + + {loading && } + + getInstabugLogs(10)} /> + {/* getNetworkLogs(10)} /> */} + getUserEvents(10)} /> + getTags(10)} /> + getUserAttributes(10)} /> + + {response && {JSON.stringify(response)}} + + + + + + ); +}; + diff --git a/examples/default/src/screens/SettingsScreen.tsx b/examples/default/src/screens/SettingsScreen.tsx index 6390bb7a0..06b2b1f03 100644 --- a/examples/default/src/screens/SettingsScreen.tsx +++ b/examples/default/src/screens/SettingsScreen.tsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; -import Instabug, { BugReporting, ColorTheme, InvocationEvent } from 'instabug-reactnative'; +import Instabug, { BugReporting, ColorTheme, InvocationEvent,Locale,ReproStepsMode} from 'instabug-reactnative'; import { InputGroup, InputLeftAddon, useToast, VStack, Button } from 'native-base'; import { ListTile } from '../components/ListTile'; @@ -193,6 +193,18 @@ export const SettingsScreen: React.FC = () => { onValueChange={Instabug.setColorTheme} /> + {Instabug.setLocale(Locale.arabic)}} /> + { + Instabug.setReproStepsConfig({ + all: ReproStepsMode.disabled, + }); + }} /> + { + Instabug.addExperiments(['exp1','exp2']);; + }} /> + { + Instabug.removeExperiments(['exp1','exp2']);; + }} /> diff --git a/examples/default/src/screens/apm/APMScreen.tsx b/examples/default/src/screens/apm/APMScreen.tsx index 2bc4dbca0..71280c6af 100644 --- a/examples/default/src/screens/apm/APMScreen.tsx +++ b/examples/default/src/screens/apm/APMScreen.tsx @@ -1,14 +1,50 @@ import type { NativeStackScreenProps } from '@react-navigation/native-stack'; import type { HomeStackParamList } from '../../navigation/HomeStack'; -import React from 'react'; +import React,{useState} from 'react'; import { ListTile } from '../../components/ListTile'; import { Screen } from '../../components/Screen'; +import { Text,Switch,Alert,ToastAndroid,Platform } from 'react-native'; +import { APM } from 'instabug-reactnative'; + + + export const APMScreen: React.FC> = ({ navigation, }) => { + + const [isEnabled, setIsEnabled] = useState(false); + + const toggleSwitch = (value: boolean) => { + setIsEnabled(value); + + // Update APM state here + APM.setEnabled(value); + + // Show Toast message + + if (Platform.OS === 'android') { + ToastAndroid.show('Set APM enabled to ' + value, ToastAndroid.SHORT); + } else { + Alert.alert('Set APM enabled to ' + value); + } + + }; + + return ( + Enable APM: + + {/* Enable Cold Launch: + */} + APM.endAppLaunch()} /> navigation.navigate('NetworkTraces')} /> navigation.navigate('ExecutionTraces')} /> navigation.navigate('AppFlows')} /> diff --git a/examples/default/src/screens/apm/HttpScreen.tsx b/examples/default/src/screens/apm/HttpScreen.tsx new file mode 100644 index 000000000..887fc1b5c --- /dev/null +++ b/examples/default/src/screens/apm/HttpScreen.tsx @@ -0,0 +1,236 @@ +import React from 'react'; + +import {useState } from 'react'; +import {Text,Switch,ToastAndroid,Platform, ActivityIndicator,Alert,View } from 'react-native'; +import Instabug, { BugReporting,APM, InvocationOption, ReportType } from 'instabug-reactnative'; + +import { ListTile } from '../../components/ListTile'; +import axios from 'axios'; + +import { Screen } from '../../components/Screen'; + + + + + +export const HttpScreen: React.FC = () => { + const [isEnabled, setIsEnabled] = useState(false); + const [loadingGet, setLoading] = useState(false); + const [loadingPost, setLoading2] = useState(false); + const [loadingDelete, setLoading3] = useState(false); + const [loadingPut, setLoading4] = useState(false); + const [isSecureConnection, setIsSecureConnection] = useState(false); + + const [loading, setLoadingP] = useState(false); + + + + const toggleSwitch = (value: boolean) => { + setIsEnabled(value); + + // Update APM state here + APM.setEnabled(value); + + // Show Toast message + Alert.alert("Set APM enabled to " + value); + }; + + + const makeGetCall = async () => { + // setIsSecureConnection(!isSecureConnection); + setLoading(true); + // const url = `http${isSecureConnection ? 's' : ''}://httpbin.org/anything`; + const url = `https://httpbin.org/anything`; + try { + const response = await fetch(url, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }); + + const responseBody = await response.json(); + console.log('Response:', responseBody); + + setLoading(false); + + // Show success message + if (Platform.OS === 'android') { + ToastAndroid.show('Succeeded', ToastAndroid.SHORT); + } else { + Alert.alert('Success', 'Succeeded'); + } + } catch (error) { + console.error('Error:', error); + setLoading(false); + + // Show error message + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } + }; + + const makePostCall = async () => { + // setIsSecureConnection(!isSecureConnection); + setLoading2(true); + // const url = `http${isSecureConnection ? 's' : ''}://httpbin.org/anything`; + const url = `https://httpbin.org/post`; + // Create the body for the POST request + const requestBody = { + name: 'Islam' + }; + try { + const response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(requestBody), + }); + + const responseBody = await response.json(); + console.log('Response:', responseBody); + + setLoading2(false); + + // Show success message + if (Platform.OS === 'android') { + ToastAndroid.show('Succeeded', ToastAndroid.SHORT); + } else { + Alert.alert('Success', 'Succeeded'); + } + } catch (error) { + console.error('Error:', error); + setLoading2(false); + + // Show error message + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } + }; + + + const makeDeleteCall = async () => { + // setIsSecureConnection(!isSecureConnection); + setLoading3(true); + // const url = `http${isSecureConnection ? 's' : ''}://httpbin.org/anything`; + const url = `https://httpbin.org/delete`; + // Create the body for the POST request + try { + const response = await fetch(url, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + }); + + const responseBody = await response.json(); + console.log('Response:', responseBody); + + setLoading3(false); + + // Show success message + if (Platform.OS === 'android') { + ToastAndroid.show('Succeeded', ToastAndroid.SHORT); + } else { + Alert.alert('Success', 'Succeeded'); + } + } catch (error) { + console.error('Error:', error); + setLoading3(false); + + // Show error message + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } + }; + + const makePutCall = async () => { + // setIsSecureConnection(!isSecureConnection); + setLoading4(true); + // const url = `http${isSecureConnection ? 's' : ''}://httpbin.org/anything`; + const url = `https://httpbin.org/put`; + // Create the body for the POST request + const requestBody = { + name: 'Islam' + }; + // Create the body for the POST request + try { + const response = await fetch(url, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(requestBody), + }); + + const responseBody = await response.json(); + console.log('Response:', responseBody); + + setLoading4(false); + + // Show success message + if (Platform.OS === 'android') { + ToastAndroid.show('Succeeded', ToastAndroid.SHORT); + } else { + Alert.alert('Success', 'Succeeded'); + } + } catch (error) { + console.error('Error:', error); + setLoading4(false); + + // Show error message + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } + }; + + + + + + return ( + + + + {loadingGet && } + + + {loadingPost && } + + + {loadingDelete && } + + + {loadingPut && } + + + + + + + + + + ); +}; + + + + + + + + diff --git a/examples/default/src/screens/apm/NetworkScreen.tsx b/examples/default/src/screens/apm/NetworkScreen.tsx index 40ad2b5fa..d5235e884 100644 --- a/examples/default/src/screens/apm/NetworkScreen.tsx +++ b/examples/default/src/screens/apm/NetworkScreen.tsx @@ -8,8 +8,17 @@ import { HStack, VStack } from 'native-base'; import { gql, request } from 'graphql-request'; import { CustomButton } from '../../components/CustomButton'; import axios from 'axios'; +import type { HomeStackParamList } from '../../navigation/HomeStack'; +import type { NativeStackScreenProps } from '@react-navigation/native-stack'; +import { ListTile } from '../../components/ListTile'; + + + + + export const NetworkScreen: React.FC> = ({ + navigation, + }) => { -export const NetworkScreen: React.FC = () => { const [endpointUrl, setEndpointUrl] = useState(''); const { width, height } = useWindowDimensions(); const defaultRequestUrl = 'https://jsonplaceholder.typicode.com/posts/1'; @@ -128,6 +137,9 @@ export const NetworkScreen: React.FC = () => { ))}
+ navigation.navigate('HttpScreen')} /> + +
); From b1bf9f40ec1bacd75080fc8273309b4840a8ca37 Mon Sep 17 00:00:00 2001 From: YoussefFouadd Date: Sun, 25 Aug 2024 18:24:25 +0300 Subject: [PATCH 02/10] Code Refactor --- .../default/src/screens/LegacyModeScreen.tsx | 67 ++--------- .../default/src/screens/apm/HttpScreen.tsx | 113 ++++++++++++------ 2 files changed, 90 insertions(+), 90 deletions(-) diff --git a/examples/default/src/screens/LegacyModeScreen.tsx b/examples/default/src/screens/LegacyModeScreen.tsx index 14721b798..8b1c0fefb 100644 --- a/examples/default/src/screens/LegacyModeScreen.tsx +++ b/examples/default/src/screens/LegacyModeScreen.tsx @@ -1,18 +1,12 @@ import React from 'react'; - import {useState } from 'react'; -import {Text,Switch,ToastAndroid,Platform, ActivityIndicator,Alert,View,StyleSheet } from 'react-native'; -import Instabug, { WelcomeMessageMode,BugReporting,APM, InvocationOption, ReportType } from 'instabug-reactnative'; - - +import {Text,ToastAndroid,Platform, ActivityIndicator,Alert } from 'react-native'; +import Instabug from 'instabug-reactnative'; import { ListTile } from '../components/ListTile'; -import axios from 'axios'; - import { Screen } from '../components/Screen'; - export const LegacyModeScreen: React.FC = () => { const [loading, setLoading] = useState(false); const [response, setResponse] = useState(null); @@ -22,23 +16,16 @@ export const LegacyModeScreen: React.FC = () => { setTimeout(() => { Instabug.logDebug(log); resolve(); - }, 100); // Simulate some asynchronous operation + }, 100); }); }; -// const logNetwork = (event:string): Promise => { -// return new Promise((resolve) => { -// setTimeout(() => { -// Instabug.logUserEvent(event); -// resolve(); -// }, 100); // Simulate some asynchronous operation -// }); -// }; + const logUserEvent = (event:string): Promise => { return new Promise((resolve) => { setTimeout(() => { Instabug.logUserEvent(event); resolve(); - }, 100); // Simulate some asynchronous operation + }, 100); }); }; const addTag = (tag:string): Promise => { @@ -46,7 +33,7 @@ const addTag = (tag:string): Promise => { setTimeout(() => { Instabug.appendTags([tag]); resolve(); - }, 100); // Simulate some asynchronous operation + }, 100); }); }; const addUserAttributes = (key:string,value:string): Promise => { @@ -54,14 +41,14 @@ const addUserAttributes = (key:string,value:string): Promise => { setTimeout(() => { Instabug.setUserAttribute(key,value); resolve(); - }, 100); // Simulate some asynchronous operation + }, 100); }); }; const getInstabugLogs = async (numberOfLogs: number) => { setLoading(true); try { - const logPromises = []; + const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { logPromises.push(logInstabug(`log ${i}`)); } @@ -85,42 +72,10 @@ const addUserAttributes = (key:string,value:string): Promise => { } }; - - // const getNetworkLogs = async (numberOfLogs: number) => { - - // setLoading(true); - // try { - // const logPromises = []; - // for (let i = 0; i < numberOfLogs; i++) { - // logPromises.push(logNetwork(`log ${i}`)); - // } - - // await Promise.all(logPromises); - // // Logs completed - // if (Platform.OS === 'android') { - // ToastAndroid.show('Succeeded', ToastAndroid.SHORT); - // } else { - // Alert.alert('Success', 'Succeeded'); - // } - - // } catch (error) { - // if (Platform.OS === 'android') { - // ToastAndroid.show('Failed', ToastAndroid.SHORT); - // } else { - // Alert.alert('Error', 'Failed'); - // } - // } finally { - // setLoading(false); - // } - - // } - - - const getUserEvents = async (numberOfLogs: number) => { setLoading(true); try { - const logPromises = []; + const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { logPromises.push(logUserEvent(`test user event ${i}`)); } @@ -149,7 +104,7 @@ const addUserAttributes = (key:string,value:string): Promise => { setLoading(true); try { - const logPromises = []; + const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { logPromises.push(addTag(`test tag ${i}`)); } @@ -179,7 +134,7 @@ const addUserAttributes = (key:string,value:string): Promise => { setLoading(true); try { - const logPromises = []; + const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { logPromises.push(addUserAttributes(`user${i}`, `user${i} value`)); } diff --git a/examples/default/src/screens/apm/HttpScreen.tsx b/examples/default/src/screens/apm/HttpScreen.tsx index 887fc1b5c..b7066e826 100644 --- a/examples/default/src/screens/apm/HttpScreen.tsx +++ b/examples/default/src/screens/apm/HttpScreen.tsx @@ -1,12 +1,7 @@ import React from 'react'; - import {useState } from 'react'; -import {Text,Switch,ToastAndroid,Platform, ActivityIndicator,Alert,View } from 'react-native'; -import Instabug, { BugReporting,APM, InvocationOption, ReportType } from 'instabug-reactnative'; - +import {Text,Switch,ToastAndroid,Platform, ActivityIndicator,Alert } from 'react-native'; import { ListTile } from '../../components/ListTile'; -import axios from 'axios'; - import { Screen } from '../../components/Screen'; @@ -19,27 +14,15 @@ export const HttpScreen: React.FC = () => { const [loadingPost, setLoading2] = useState(false); const [loadingDelete, setLoading3] = useState(false); const [loadingPut, setLoading4] = useState(false); + const [loadingPatch, setLoading5] = useState(false); + const [loadingDownloadImage, setLoading6] = useState(false); + const [isSecureConnection, setIsSecureConnection] = useState(false); const [loading, setLoadingP] = useState(false); - - - const toggleSwitch = (value: boolean) => { - setIsEnabled(value); - - // Update APM state here - APM.setEnabled(value); - - // Show Toast message - Alert.alert("Set APM enabled to " + value); - }; - - const makeGetCall = async () => { - // setIsSecureConnection(!isSecureConnection); setLoading(true); - // const url = `http${isSecureConnection ? 's' : ''}://httpbin.org/anything`; const url = `https://httpbin.org/anything`; try { const response = await fetch(url, { @@ -73,10 +56,9 @@ export const HttpScreen: React.FC = () => { } }; + const makePostCall = async () => { - // setIsSecureConnection(!isSecureConnection); setLoading2(true); - // const url = `http${isSecureConnection ? 's' : ''}://httpbin.org/anything`; const url = `https://httpbin.org/post`; // Create the body for the POST request const requestBody = { @@ -117,11 +99,8 @@ export const HttpScreen: React.FC = () => { const makeDeleteCall = async () => { - // setIsSecureConnection(!isSecureConnection); setLoading3(true); - // const url = `http${isSecureConnection ? 's' : ''}://httpbin.org/anything`; const url = `https://httpbin.org/delete`; - // Create the body for the POST request try { const response = await fetch(url, { method: 'DELETE', @@ -135,7 +114,6 @@ export const HttpScreen: React.FC = () => { setLoading3(false); - // Show success message if (Platform.OS === 'android') { ToastAndroid.show('Succeeded', ToastAndroid.SHORT); } else { @@ -145,7 +123,6 @@ export const HttpScreen: React.FC = () => { console.error('Error:', error); setLoading3(false); - // Show error message if (Platform.OS === 'android') { ToastAndroid.show('Failed', ToastAndroid.SHORT); } else { @@ -155,15 +132,11 @@ export const HttpScreen: React.FC = () => { }; const makePutCall = async () => { - // setIsSecureConnection(!isSecureConnection); setLoading4(true); - // const url = `http${isSecureConnection ? 's' : ''}://httpbin.org/anything`; const url = `https://httpbin.org/put`; - // Create the body for the POST request const requestBody = { name: 'Islam' }; - // Create the body for the POST request try { const response = await fetch(url, { method: 'PUT', @@ -178,7 +151,6 @@ export const HttpScreen: React.FC = () => { setLoading4(false); - // Show success message if (Platform.OS === 'android') { ToastAndroid.show('Succeeded', ToastAndroid.SHORT); } else { @@ -188,7 +160,6 @@ export const HttpScreen: React.FC = () => { console.error('Error:', error); setLoading4(false); - // Show error message if (Platform.OS === 'android') { ToastAndroid.show('Failed', ToastAndroid.SHORT); } else { @@ -196,7 +167,74 @@ export const HttpScreen: React.FC = () => { } } }; + + const makePatchCall = async () => { + + setLoading5(true); + const url = 'https://httpbin.org/patch'; + + const jsonInputString = JSON.stringify({ name: 'Islam' }); + + try { + const response = await fetch(url, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json', + }, + body: jsonInputString, + }); + + setLoading5(false); + + if (Platform.OS === 'android') { + ToastAndroid.show('Succeeded', ToastAndroid.SHORT); + } else { + Alert.alert('Success', 'Succeeded'); + } + } catch (error) { + console.error('Error:', error); + setLoading5(false); + + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } + }; + + const makeDownloadImageCall = async () => { + setLoading6(true); + const url = `https://httpbin.org/image/jpeg`; + try { + const response = await fetch(url, { + method: 'GET', + headers: { + 'Content-Type': 'image/jpeg', + }, + }); + + const responseBody = await response.blob(); + console.log('Response:', responseBody); + + setLoading6(false); + + if (Platform.OS === 'android') { + ToastAndroid.show('Succeeded', ToastAndroid.SHORT); + } else { + Alert.alert('Success', 'Succeeded'); + } + } catch (error) { + console.error('Error:', error); + setLoading6(false); + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } + }; @@ -216,6 +254,13 @@ export const HttpScreen: React.FC = () => { {loadingPut && } + + {loadingPatch && } + + + + {loadingDownloadImage && } + From a0b08f8ba5e7cd1483c8e80fcbf94b262dc7125e Mon Sep 17 00:00:00 2001 From: YoussefFouadd Date: Sun, 25 Aug 2024 18:52:25 +0300 Subject: [PATCH 03/10] Code Refactoring --- examples/default/src/screens/apm/HttpScreen.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/default/src/screens/apm/HttpScreen.tsx b/examples/default/src/screens/apm/HttpScreen.tsx index b7066e826..93461fa4d 100644 --- a/examples/default/src/screens/apm/HttpScreen.tsx +++ b/examples/default/src/screens/apm/HttpScreen.tsx @@ -7,7 +7,6 @@ import { Screen } from '../../components/Screen'; - export const HttpScreen: React.FC = () => { const [isEnabled, setIsEnabled] = useState(false); const [loadingGet, setLoading] = useState(false); From b7a2ce07f98fb5089723a9f9d0070726d66e2391 Mon Sep 17 00:00:00 2001 From: YoussefFouadd Date: Mon, 26 Aug 2024 11:21:25 +0300 Subject: [PATCH 04/10] Fix prettier issues --- examples/default/src/navigation/HomeStack.tsx | 13 +- .../src/screens/CrashReportingScreen.tsx | 26 ++- .../src/screens/FeatureRequestsScreen.tsx | 13 +- .../default/src/screens/LegacyModeScreen.tsx | 204 ++++++++---------- .../default/src/screens/SettingsScreen.tsx | 42 +++- .../default/src/screens/apm/APMScreen.tsx | 19 +- .../default/src/screens/apm/HttpScreen.tsx | 81 +++---- .../default/src/screens/apm/NetworkScreen.tsx | 12 +- 8 files changed, 181 insertions(+), 229 deletions(-) diff --git a/examples/default/src/navigation/HomeStack.tsx b/examples/default/src/navigation/HomeStack.tsx index 94f99d422..716ea05d9 100644 --- a/examples/default/src/navigation/HomeStack.tsx +++ b/examples/default/src/navigation/HomeStack.tsx @@ -29,8 +29,6 @@ import { SessionReplayScreen } from '../screens/SessionReplayScreen'; import { LegacyModeScreen } from '../screens/LegacyModeScreen'; import { HttpScreen } from '../screens/apm/HttpScreen'; - - export type HomeStackParamList = { Home: undefined; BugReporting: undefined; @@ -49,9 +47,8 @@ export type HomeStackParamList = { LargeImageList: undefined; SessionReplay: undefined; BackAndForthScreen: BackAndForthScreenProp; - LegacyMode:undefined; - HttpScreen:undefined; - + LegacyMode: undefined; + HttpScreen: undefined; // APM // APM: undefined; @@ -144,11 +141,7 @@ export const HomeStackNavigator: React.FC = () => { component={LegacyModeScreen} options={{ title: 'LegacyMode' }} /> - + ); }; diff --git a/examples/default/src/screens/CrashReportingScreen.tsx b/examples/default/src/screens/CrashReportingScreen.tsx index 68c32519f..acda41e6a 100644 --- a/examples/default/src/screens/CrashReportingScreen.tsx +++ b/examples/default/src/screens/CrashReportingScreen.tsx @@ -1,5 +1,14 @@ import React, { useState } from 'react'; -import { Alert, Platform, ScrollView, StyleSheet, Text, View,Switch,ToastAndroid } from 'react-native'; +import { + Alert, + Platform, + ScrollView, + StyleSheet, + Text, + View, + Switch, + ToastAndroid, +} from 'react-native'; import { CrashReporting, NonFatalErrorLevel } from 'instabug-reactnative'; @@ -25,7 +34,6 @@ const styles = StyleSheet.create({ }, }); - export const CrashReportingScreen: React.FC = () => { function throwHandledException(error: Error) { try { @@ -74,18 +82,17 @@ export const CrashReportingScreen: React.FC = () => { const toggleSwitch = (value: boolean) => { setIsEnabled(value); - + // Update APM state here CrashReporting.setEnabled(value); // Show Toast message - + if (Platform.OS === 'android') { ToastAndroid.show('Crash Reporting set to ' + value, ToastAndroid.SHORT); } else { Alert.alert('Crash Reporting set to ' + value); } - - } + }; function sendCrash() { try { @@ -116,11 +123,8 @@ export const CrashReportingScreen: React.FC = () => { return ( - Crash Reporting Enabled: - + Crash Reporting Enabled: +
{ const [isEnabled, setIsEnabled] = useState(false); - const toggleSwitch = (value: boolean) => { setIsEnabled(value); @@ -23,15 +22,11 @@ export const FeatureRequestsScreen: React.FC = () => { } else { Alert.alert('Email field required set to ' + value); } - }; return ( Email field Required: - + FeatureRequests.show()} /> ); diff --git a/examples/default/src/screens/LegacyModeScreen.tsx b/examples/default/src/screens/LegacyModeScreen.tsx index 8b1c0fefb..661f8ea43 100644 --- a/examples/default/src/screens/LegacyModeScreen.tsx +++ b/examples/default/src/screens/LegacyModeScreen.tsx @@ -1,183 +1,165 @@ import React from 'react'; -import {useState } from 'react'; -import {Text,ToastAndroid,Platform, ActivityIndicator,Alert } from 'react-native'; +import { useState } from 'react'; +import { Text, ToastAndroid, Platform, ActivityIndicator, Alert } from 'react-native'; import Instabug from 'instabug-reactnative'; import { ListTile } from '../components/ListTile'; import { Screen } from '../components/Screen'; - - export const LegacyModeScreen: React.FC = () => { const [loading, setLoading] = useState(false); const [response, setResponse] = useState(null); - const logInstabug = (log:string): Promise => { + const logInstabug = (log: string): Promise => { return new Promise((resolve) => { - setTimeout(() => { - Instabug.logDebug(log); - resolve(); - }, 100); + setTimeout(() => { + Instabug.logDebug(log); + resolve(); + }, 100); }); -}; + }; -const logUserEvent = (event:string): Promise => { - return new Promise((resolve) => { + const logUserEvent = (event: string): Promise => { + return new Promise((resolve) => { setTimeout(() => { Instabug.logUserEvent(event); - resolve(); + resolve(); }, 100); - }); -}; -const addTag = (tag:string): Promise => { - return new Promise((resolve) => { + }); + }; + const addTag = (tag: string): Promise => { + return new Promise((resolve) => { setTimeout(() => { Instabug.appendTags([tag]); - resolve(); - }, 100); - }); -}; -const addUserAttributes = (key:string,value:string): Promise => { - return new Promise((resolve) => { + resolve(); + }, 100); + }); + }; + const addUserAttributes = (key: string, value: string): Promise => { + return new Promise((resolve) => { setTimeout(() => { - Instabug.setUserAttribute(key,value); - resolve(); - }, 100); - }); -}; + Instabug.setUserAttribute(key, value); + resolve(); + }, 100); + }); + }; const getInstabugLogs = async (numberOfLogs: number) => { setLoading(true); try { const logPromises: Promise[] = []; - for (let i = 0; i < numberOfLogs; i++) { - logPromises.push(logInstabug(`log ${i}`)); - } + for (let i = 0; i < numberOfLogs; i++) { + logPromises.push(logInstabug(`log ${i}`)); + } - await Promise.all(logPromises); - // Logs completed - if (Platform.OS === 'android') { + await Promise.all(logPromises); + // Logs completed + if (Platform.OS === 'android') { ToastAndroid.show('Succeeded', ToastAndroid.SHORT); } else { Alert.alert('Success', 'Succeeded'); } - - } catch (error) { - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } - } finally { - setLoading(false); + } catch (error) { + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } finally { + setLoading(false); } -}; + }; const getUserEvents = async (numberOfLogs: number) => { setLoading(true); try { const logPromises: Promise[] = []; - for (let i = 0; i < numberOfLogs; i++) { - logPromises.push(logUserEvent(`test user event ${i}`)); - } + for (let i = 0; i < numberOfLogs; i++) { + logPromises.push(logUserEvent(`test user event ${i}`)); + } - await Promise.all(logPromises); - // Logs completed - if (Platform.OS === 'android') { + await Promise.all(logPromises); + // Logs completed + if (Platform.OS === 'android') { ToastAndroid.show('Succeeded', ToastAndroid.SHORT); } else { Alert.alert('Success', 'Succeeded'); } - - } catch (error) { - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } - } finally { - setLoading(false); + } catch (error) { + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } finally { + setLoading(false); } -}; - + }; const getTags = async (numberOfLogs: number) => { - setLoading(true); try { const logPromises: Promise[] = []; - for (let i = 0; i < numberOfLogs; i++) { - logPromises.push(addTag(`test tag ${i}`)); - } + for (let i = 0; i < numberOfLogs; i++) { + logPromises.push(addTag(`test tag ${i}`)); + } - await Promise.all(logPromises); - // Logs completed - if (Platform.OS === 'android') { + await Promise.all(logPromises); + // Logs completed + if (Platform.OS === 'android') { ToastAndroid.show('Succeeded', ToastAndroid.SHORT); } else { Alert.alert('Success', 'Succeeded'); } - - } catch (error) { - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } - } finally { - setLoading(false); + } catch (error) { + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } finally { + setLoading(false); } - - } - + }; const getUserAttributes = async (numberOfLogs: number) => { - setLoading(true); try { const logPromises: Promise[] = []; - for (let i = 0; i < numberOfLogs; i++) { - logPromises.push(addUserAttributes(`user${i}`, `user${i} value`)); - } + for (let i = 0; i < numberOfLogs; i++) { + logPromises.push(addUserAttributes(`user${i}`, `user${i} value`)); + } - await Promise.all(logPromises); - // Logs completed - if (Platform.OS === 'android') { + await Promise.all(logPromises); + // Logs completed + if (Platform.OS === 'android') { ToastAndroid.show('Succeeded', ToastAndroid.SHORT); } else { Alert.alert('Success', 'Succeeded'); } - - } catch (error) { - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } - } finally { - setLoading(false); + } catch (error) { + if (Platform.OS === 'android') { + ToastAndroid.show('Failed', ToastAndroid.SHORT); + } else { + Alert.alert('Error', 'Failed'); + } + } finally { + setLoading(false); } - - } + }; // Similar functions for PUT, DELETE, etc. can be added here return ( + {loading && } - {loading && } - - getInstabugLogs(10)} /> - {/* getNetworkLogs(10)} /> */} - getUserEvents(10)} /> - getTags(10)} /> - getUserAttributes(10)} /> + getInstabugLogs(10)} /> + {/* getNetworkLogs(10)} /> */} + getUserEvents(10)} /> + getTags(10)} /> + getUserAttributes(10)} /> - {response && {JSON.stringify(response)}} - - + {response && {JSON.stringify(response)}} - - ); }; - diff --git a/examples/default/src/screens/SettingsScreen.tsx b/examples/default/src/screens/SettingsScreen.tsx index 06b2b1f03..764753e70 100644 --- a/examples/default/src/screens/SettingsScreen.tsx +++ b/examples/default/src/screens/SettingsScreen.tsx @@ -1,6 +1,12 @@ import React, { useState } from 'react'; -import Instabug, { BugReporting, ColorTheme, InvocationEvent,Locale,ReproStepsMode} from 'instabug-reactnative'; +import Instabug, { + BugReporting, + ColorTheme, + InvocationEvent, + Locale, + ReproStepsMode, +} from 'instabug-reactnative'; import { InputGroup, InputLeftAddon, useToast, VStack, Button } from 'native-base'; import { ListTile } from '../components/ListTile'; @@ -193,18 +199,32 @@ export const SettingsScreen: React.FC = () => { onValueChange={Instabug.setColorTheme} /> - {Instabug.setLocale(Locale.arabic)}} /> - { + { + Instabug.setLocale(Locale.arabic); + }} + /> + { Instabug.setReproStepsConfig({ all: ReproStepsMode.disabled, - }); - }} /> - { - Instabug.addExperiments(['exp1','exp2']);; - }} /> - { - Instabug.removeExperiments(['exp1','exp2']);; - }} /> + }); + }} + /> + { + Instabug.addExperiments(['exp1', 'exp2']); + }} + /> + { + Instabug.removeExperiments(['exp1', 'exp2']); + }} + /> diff --git a/examples/default/src/screens/apm/APMScreen.tsx b/examples/default/src/screens/apm/APMScreen.tsx index 71280c6af..3cd0e86bb 100644 --- a/examples/default/src/screens/apm/APMScreen.tsx +++ b/examples/default/src/screens/apm/APMScreen.tsx @@ -1,25 +1,21 @@ import type { NativeStackScreenProps } from '@react-navigation/native-stack'; import type { HomeStackParamList } from '../../navigation/HomeStack'; -import React,{useState} from 'react'; +import React, { useState } from 'react'; import { ListTile } from '../../components/ListTile'; import { Screen } from '../../components/Screen'; -import { Text,Switch,Alert,ToastAndroid,Platform } from 'react-native'; +import { Text, Switch, Alert, ToastAndroid, Platform } from 'react-native'; import { APM } from 'instabug-reactnative'; - - - export const APMScreen: React.FC> = ({ navigation, }) => { - const [isEnabled, setIsEnabled] = useState(false); const toggleSwitch = (value: boolean) => { setIsEnabled(value); // Update APM state here - APM.setEnabled(value); + APM.setEnabled(value); // Show Toast message @@ -28,18 +24,13 @@ export const APMScreen: React.FC Enable APM: - - {/* Enable Cold Launch: + + {/* Enable Cold Launch: { const [isEnabled, setIsEnabled] = useState(false); const [loadingGet, setLoading] = useState(false); @@ -33,7 +30,7 @@ export const HttpScreen: React.FC = () => { const responseBody = await response.json(); console.log('Response:', responseBody); - + setLoading(false); // Show success message @@ -55,14 +52,13 @@ export const HttpScreen: React.FC = () => { } }; - const makePostCall = async () => { setLoading2(true); const url = `https://httpbin.org/post`; // Create the body for the POST request const requestBody = { - name: 'Islam' - }; + name: 'Islam', + }; try { const response = await fetch(url, { method: 'POST', @@ -74,7 +70,7 @@ export const HttpScreen: React.FC = () => { const responseBody = await response.json(); console.log('Response:', responseBody); - + setLoading2(false); // Show success message @@ -96,7 +92,6 @@ export const HttpScreen: React.FC = () => { } }; - const makeDeleteCall = async () => { setLoading3(true); const url = `https://httpbin.org/delete`; @@ -110,7 +105,7 @@ export const HttpScreen: React.FC = () => { const responseBody = await response.json(); console.log('Response:', responseBody); - + setLoading3(false); if (Platform.OS === 'android') { @@ -133,9 +128,9 @@ export const HttpScreen: React.FC = () => { const makePutCall = async () => { setLoading4(true); const url = `https://httpbin.org/put`; - const requestBody = { - name: 'Islam' - }; + const requestBody = { + name: 'Islam', + }; try { const response = await fetch(url, { method: 'PUT', @@ -147,7 +142,7 @@ export const HttpScreen: React.FC = () => { const responseBody = await response.json(); console.log('Response:', responseBody); - + setLoading4(false); if (Platform.OS === 'android') { @@ -166,24 +161,23 @@ export const HttpScreen: React.FC = () => { } } }; - + const makePatchCall = async () => { + setLoading5(true); + const url = 'https://httpbin.org/patch'; + + const jsonInputString = JSON.stringify({ name: 'Islam' }); + + try { + const response = await fetch(url, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json', + }, + body: jsonInputString, + }); - setLoading5(true); - const url = 'https://httpbin.org/patch'; - - const jsonInputString = JSON.stringify({ name: 'Islam' }); - - try { - const response = await fetch(url, { - method: 'PATCH', - headers: { - 'Content-Type': 'application/json', - }, - body: jsonInputString, - }); - - setLoading5(false); + setLoading5(false); if (Platform.OS === 'android') { ToastAndroid.show('Succeeded', ToastAndroid.SHORT); @@ -215,7 +209,7 @@ export const HttpScreen: React.FC = () => { const responseBody = await response.blob(); console.log('Response:', responseBody); - + setLoading6(false); if (Platform.OS === 'android') { @@ -235,12 +229,8 @@ export const HttpScreen: React.FC = () => { } }; - - - return ( - {loadingGet && } @@ -256,25 +246,8 @@ export const HttpScreen: React.FC = () => { {loadingPatch && } - {loadingDownloadImage && } - - - - - - - - ); }; - - - - - - - - diff --git a/examples/default/src/screens/apm/NetworkScreen.tsx b/examples/default/src/screens/apm/NetworkScreen.tsx index d5235e884..87c359dff 100644 --- a/examples/default/src/screens/apm/NetworkScreen.tsx +++ b/examples/default/src/screens/apm/NetworkScreen.tsx @@ -12,13 +12,9 @@ import type { HomeStackParamList } from '../../navigation/HomeStack'; import type { NativeStackScreenProps } from '@react-navigation/native-stack'; import { ListTile } from '../../components/ListTile'; - - - - export const NetworkScreen: React.FC> = ({ - navigation, - }) => { - +export const NetworkScreen: React.FC< + NativeStackScreenProps +> = ({ navigation }) => { const [endpointUrl, setEndpointUrl] = useState(''); const { width, height } = useWindowDimensions(); const defaultRequestUrl = 'https://jsonplaceholder.typicode.com/posts/1'; @@ -138,8 +134,6 @@ import { ListTile } from '../../components/ListTile';
navigation.navigate('HttpScreen')} /> - -
); From 0463c4aa84abed0ac21da45a129d70187215fafd Mon Sep 17 00:00:00 2001 From: YoussefFouadd Date: Mon, 26 Aug 2024 11:27:40 +0300 Subject: [PATCH 05/10] Code Refactor Latest --- examples/default/src/screens/apm/HttpScreen.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/default/src/screens/apm/HttpScreen.tsx b/examples/default/src/screens/apm/HttpScreen.tsx index 515288cdb..7579f43c3 100644 --- a/examples/default/src/screens/apm/HttpScreen.tsx +++ b/examples/default/src/screens/apm/HttpScreen.tsx @@ -1,11 +1,10 @@ import React from 'react'; import { useState } from 'react'; -import { Text, Switch, ToastAndroid, Platform, ActivityIndicator, Alert } from 'react-native'; +import { ToastAndroid, Platform, ActivityIndicator, Alert } from 'react-native'; import { ListTile } from '../../components/ListTile'; import { Screen } from '../../components/Screen'; export const HttpScreen: React.FC = () => { - const [isEnabled, setIsEnabled] = useState(false); const [loadingGet, setLoading] = useState(false); const [loadingPost, setLoading2] = useState(false); const [loadingDelete, setLoading3] = useState(false); @@ -13,9 +12,6 @@ export const HttpScreen: React.FC = () => { const [loadingPatch, setLoading5] = useState(false); const [loadingDownloadImage, setLoading6] = useState(false); - const [isSecureConnection, setIsSecureConnection] = useState(false); - - const [loading, setLoadingP] = useState(false); const makeGetCall = async () => { setLoading(true); From ea43f762334c20a2ae71bf0f82364f4cf2551e17 Mon Sep 17 00:00:00 2001 From: YoussefFouadd Date: Thu, 3 Oct 2024 11:09:14 +0300 Subject: [PATCH 06/10] Fix formatting issues --- examples/default/src/screens/LegacyModeScreen.tsx | 5 +---- examples/default/src/screens/apm/HttpScreen.tsx | 15 ++++++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/examples/default/src/screens/LegacyModeScreen.tsx b/examples/default/src/screens/LegacyModeScreen.tsx index 661f8ea43..4c6010b41 100644 --- a/examples/default/src/screens/LegacyModeScreen.tsx +++ b/examples/default/src/screens/LegacyModeScreen.tsx @@ -1,13 +1,12 @@ import React from 'react'; import { useState } from 'react'; -import { Text, ToastAndroid, Platform, ActivityIndicator, Alert } from 'react-native'; +import { ToastAndroid, Platform, ActivityIndicator, Alert } from 'react-native'; import Instabug from 'instabug-reactnative'; import { ListTile } from '../components/ListTile'; import { Screen } from '../components/Screen'; export const LegacyModeScreen: React.FC = () => { const [loading, setLoading] = useState(false); - const [response, setResponse] = useState(null); const logInstabug = (log: string): Promise => { return new Promise((resolve) => { @@ -158,8 +157,6 @@ export const LegacyModeScreen: React.FC = () => { getUserEvents(10)} /> getTags(10)} /> getUserAttributes(10)} /> - - {response && {JSON.stringify(response)}} ); }; diff --git a/examples/default/src/screens/apm/HttpScreen.tsx b/examples/default/src/screens/apm/HttpScreen.tsx index 7579f43c3..d85ddc34c 100644 --- a/examples/default/src/screens/apm/HttpScreen.tsx +++ b/examples/default/src/screens/apm/HttpScreen.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { useState } from 'react'; -import { ToastAndroid, Platform, ActivityIndicator, Alert } from 'react-native'; +import { ToastAndroid, Platform, ActivityIndicator, Alert } from 'react-native'; import { ListTile } from '../../components/ListTile'; import { Screen } from '../../components/Screen'; @@ -12,10 +12,9 @@ export const HttpScreen: React.FC = () => { const [loadingPatch, setLoading5] = useState(false); const [loadingDownloadImage, setLoading6] = useState(false); - const makeGetCall = async () => { setLoading(true); - const url = `https://httpbin.org/anything`; + const url = 'https://httpbin.org/anything'; try { const response = await fetch(url, { method: 'GET', @@ -50,7 +49,7 @@ export const HttpScreen: React.FC = () => { const makePostCall = async () => { setLoading2(true); - const url = `https://httpbin.org/post`; + const url = 'https://httpbin.org/post'; // Create the body for the POST request const requestBody = { name: 'Islam', @@ -90,7 +89,7 @@ export const HttpScreen: React.FC = () => { const makeDeleteCall = async () => { setLoading3(true); - const url = `https://httpbin.org/delete`; + const url = 'https://httpbin.org/delete'; try { const response = await fetch(url, { method: 'DELETE', @@ -123,7 +122,7 @@ export const HttpScreen: React.FC = () => { const makePutCall = async () => { setLoading4(true); - const url = `https://httpbin.org/put`; + const url = 'https://httpbin.org/put'; const requestBody = { name: 'Islam', }; @@ -173,6 +172,8 @@ export const HttpScreen: React.FC = () => { body: jsonInputString, }); + const responseBody = await response.json(); + console.log('Response:', responseBody); setLoading5(false); if (Platform.OS === 'android') { @@ -194,7 +195,7 @@ export const HttpScreen: React.FC = () => { const makeDownloadImageCall = async () => { setLoading6(true); - const url = `https://httpbin.org/image/jpeg`; + const url = 'https://httpbin.org/image/jpeg'; try { const response = await fetch(url, { method: 'GET', From 75c29273eec8016a5752308c287e982a7616415e Mon Sep 17 00:00:00 2001 From: YoussefFouadd Date: Sun, 6 Oct 2024 17:05:34 +0300 Subject: [PATCH 07/10] Resolving comments --- .../src/screens/FeatureRequestsScreen.tsx | 14 +- .../default/src/screens/LegacyModeScreen.tsx | 119 +++++---------- .../default/src/screens/apm/APMScreen.tsx | 19 +-- .../default/src/screens/apm/HttpScreen.tsx | 144 ++++-------------- .../default/src/screens/apm/NetworkScreen.tsx | 2 +- .../default/src/utils/showNotification.ts | 9 ++ 6 files changed, 86 insertions(+), 221 deletions(-) create mode 100644 examples/default/src/utils/showNotification.ts diff --git a/examples/default/src/screens/FeatureRequestsScreen.tsx b/examples/default/src/screens/FeatureRequestsScreen.tsx index ec42feba8..ad690429d 100644 --- a/examples/default/src/screens/FeatureRequestsScreen.tsx +++ b/examples/default/src/screens/FeatureRequestsScreen.tsx @@ -3,9 +3,10 @@ import React, { useState } from 'react'; import { FeatureRequests, ActionType } from 'instabug-reactnative'; import { ListTile } from '../components/ListTile'; -import { Text, Switch, Alert, ToastAndroid, Platform } from 'react-native'; +import { Text, Switch } from 'react-native'; import { Screen } from '../components/Screen'; +import { showNotification } from '../utils/showNotification'; export const FeatureRequestsScreen: React.FC = () => { const [isEnabled, setIsEnabled] = useState(false); @@ -13,15 +14,8 @@ export const FeatureRequestsScreen: React.FC = () => { const toggleSwitch = (value: boolean) => { setIsEnabled(value); - // Update APM state here - FeatureRequests.setEmailFieldRequired(value, [ActionType.requestNewFeature]); - // Show Toast message - - if (Platform.OS === 'android') { - ToastAndroid.show('Email field required set to ' + value, ToastAndroid.SHORT); - } else { - Alert.alert('Email field required set to ' + value); - } + FeatureRequests.setEmailFieldRequired(value, ActionType.requestNewFeature); + showNotification('Email status', 'Email field required set to ' + value); }; return ( diff --git a/examples/default/src/screens/LegacyModeScreen.tsx b/examples/default/src/screens/LegacyModeScreen.tsx index 4c6010b41..cad78605f 100644 --- a/examples/default/src/screens/LegacyModeScreen.tsx +++ b/examples/default/src/screens/LegacyModeScreen.tsx @@ -1,162 +1,117 @@ -import React from 'react'; -import { useState } from 'react'; -import { ToastAndroid, Platform, ActivityIndicator, Alert } from 'react-native'; +import React, { useState } from 'react'; +import { ActivityIndicator } from 'react-native'; import Instabug from 'instabug-reactnative'; import { ListTile } from '../components/ListTile'; import { Screen } from '../components/Screen'; +import { showNotification } from '../utils/showNotification'; export const LegacyModeScreen: React.FC = () => { const [loading, setLoading] = useState(false); - const logInstabug = (log: string): Promise => { + const addInstabugLog = (log: string): Promise => { return new Promise((resolve) => { - setTimeout(() => { - Instabug.logDebug(log); - resolve(); - }, 100); + Instabug.logDebug(log); + resolve(); }); }; - const logUserEvent = (event: string): Promise => { + const addUserEvent = (event: string): Promise => { return new Promise((resolve) => { - setTimeout(() => { - Instabug.logUserEvent(event); - resolve(); - }, 100); + Instabug.logUserEvent(event); + resolve(); }); }; const addTag = (tag: string): Promise => { return new Promise((resolve) => { - setTimeout(() => { - Instabug.appendTags([tag]); - resolve(); - }, 100); + Instabug.appendTags([tag]); + resolve(); }); }; const addUserAttributes = (key: string, value: string): Promise => { return new Promise((resolve) => { - setTimeout(() => { - Instabug.setUserAttribute(key, value); - resolve(); - }, 100); + Instabug.setUserAttribute(key, value); + resolve(); }); }; - const getInstabugLogs = async (numberOfLogs: number) => { + const addMultipleInstabugLogs = async (numberOfLogs: number) => { setLoading(true); try { const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { - logPromises.push(logInstabug(`log ${i}`)); + logPromises.push(addInstabugLog(`log ${i}`)); } - await Promise.all(logPromises); - // Logs completed - if (Platform.OS === 'android') { - ToastAndroid.show('Succeeded', ToastAndroid.SHORT); - } else { - Alert.alert('Success', 'Succeeded'); - } + showNotification('Success', 'Succeeded'); } catch (error) { - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } + showNotification('Error', 'Failed'); } finally { setLoading(false); } }; - const getUserEvents = async (numberOfLogs: number) => { + const addMultipleUserEvents = async (numberOfLogs: number) => { setLoading(true); try { const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { - logPromises.push(logUserEvent(`test user event ${i}`)); + logPromises.push(addUserEvent(`test user event ${i}`)); } - await Promise.all(logPromises); - // Logs completed - if (Platform.OS === 'android') { - ToastAndroid.show('Succeeded', ToastAndroid.SHORT); - } else { - Alert.alert('Success', 'Succeeded'); - } + showNotification('Success', 'Succeeded'); } catch (error) { - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } + showNotification('Error', 'Failed'); } finally { setLoading(false); } }; - const getTags = async (numberOfLogs: number) => { + const addMultipleTags = async (numberOfLogs: number) => { setLoading(true); try { const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { logPromises.push(addTag(`test tag ${i}`)); } - await Promise.all(logPromises); - // Logs completed - if (Platform.OS === 'android') { - ToastAndroid.show('Succeeded', ToastAndroid.SHORT); - } else { - Alert.alert('Success', 'Succeeded'); - } + showNotification('Success', 'Succeeded'); } catch (error) { - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } + showNotification('Error', 'Failed'); } finally { setLoading(false); } }; - const getUserAttributes = async (numberOfLogs: number) => { + const addMultipleUserAttributes = async (numberOfLogs: number) => { setLoading(true); try { const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { logPromises.push(addUserAttributes(`user${i}`, `user${i} value`)); } - await Promise.all(logPromises); - // Logs completed - if (Platform.OS === 'android') { - ToastAndroid.show('Succeeded', ToastAndroid.SHORT); - } else { - Alert.alert('Success', 'Succeeded'); - } + showNotification('Success', 'Succeeded'); } catch (error) { - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } + showNotification('Error', 'Failed'); } finally { setLoading(false); } }; - // Similar functions for PUT, DELETE, etc. can be added here - return ( {loading && } - getInstabugLogs(10)} /> - {/* getNetworkLogs(10)} /> */} - getUserEvents(10)} /> - getTags(10)} /> - getUserAttributes(10)} /> + addMultipleInstabugLogs(10)} + /> + addMultipleUserEvents(10)} /> + addMultipleTags(10)} /> + addMultipleUserAttributes(10)} + /> ); }; diff --git a/examples/default/src/screens/apm/APMScreen.tsx b/examples/default/src/screens/apm/APMScreen.tsx index 3cd0e86bb..0b04e6191 100644 --- a/examples/default/src/screens/apm/APMScreen.tsx +++ b/examples/default/src/screens/apm/APMScreen.tsx @@ -3,8 +3,9 @@ import type { HomeStackParamList } from '../../navigation/HomeStack'; import React, { useState } from 'react'; import { ListTile } from '../../components/ListTile'; import { Screen } from '../../components/Screen'; -import { Text, Switch, Alert, ToastAndroid, Platform } from 'react-native'; +import { Text, Switch } from 'react-native'; import { APM } from 'instabug-reactnative'; +import { showNotification } from '../../utils/showNotification'; export const APMScreen: React.FC> = ({ navigation, @@ -13,28 +14,14 @@ export const APMScreen: React.FC { setIsEnabled(value); - - // Update APM state here APM.setEnabled(value); - - // Show Toast message - - if (Platform.OS === 'android') { - ToastAndroid.show('Set APM enabled to ' + value, ToastAndroid.SHORT); - } else { - Alert.alert('Set APM enabled to ' + value); - } + showNotification('APM status', 'APM enabled set to ' + value); }; return ( Enable APM: - {/* Enable Cold Launch: - */} APM.endAppLaunch()} /> navigation.navigate('NetworkTraces')} /> navigation.navigate('ExecutionTraces')} /> diff --git a/examples/default/src/screens/apm/HttpScreen.tsx b/examples/default/src/screens/apm/HttpScreen.tsx index d85ddc34c..f3706f3ac 100644 --- a/examples/default/src/screens/apm/HttpScreen.tsx +++ b/examples/default/src/screens/apm/HttpScreen.tsx @@ -1,16 +1,11 @@ -import React from 'react'; -import { useState } from 'react'; -import { ToastAndroid, Platform, ActivityIndicator, Alert } from 'react-native'; +import React, { useState } from 'react'; +import { ActivityIndicator } from 'react-native'; import { ListTile } from '../../components/ListTile'; import { Screen } from '../../components/Screen'; +import { showNotification } from '../../utils/showNotification'; export const HttpScreen: React.FC = () => { - const [loadingGet, setLoading] = useState(false); - const [loadingPost, setLoading2] = useState(false); - const [loadingDelete, setLoading3] = useState(false); - const [loadingPut, setLoading4] = useState(false); - const [loadingPatch, setLoading5] = useState(false); - const [loadingDownloadImage, setLoading6] = useState(false); + const [loading, setLoading] = useState(false); const makeGetCall = async () => { setLoading(true); @@ -27,30 +22,17 @@ export const HttpScreen: React.FC = () => { console.log('Response:', responseBody); setLoading(false); - - // Show success message - if (Platform.OS === 'android') { - ToastAndroid.show('Succeeded', ToastAndroid.SHORT); - } else { - Alert.alert('Success', 'Succeeded'); - } + showNotification('Success', 'Succeeded'); } catch (error) { console.error('Error:', error); setLoading(false); - - // Show error message - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } + showNotification('Error', 'Failed'); } }; const makePostCall = async () => { - setLoading2(true); + setLoading(true); const url = 'https://httpbin.org/post'; - // Create the body for the POST request const requestBody = { name: 'Islam', }; @@ -66,29 +48,17 @@ export const HttpScreen: React.FC = () => { const responseBody = await response.json(); console.log('Response:', responseBody); - setLoading2(false); - - // Show success message - if (Platform.OS === 'android') { - ToastAndroid.show('Succeeded', ToastAndroid.SHORT); - } else { - Alert.alert('Success', 'Succeeded'); - } + setLoading(false); + showNotification('Success', 'Succeeded'); } catch (error) { console.error('Error:', error); - setLoading2(false); - - // Show error message - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } + setLoading(false); + showNotification('Error', 'Failed'); } }; const makeDeleteCall = async () => { - setLoading3(true); + setLoading(true); const url = 'https://httpbin.org/delete'; try { const response = await fetch(url, { @@ -101,27 +71,17 @@ export const HttpScreen: React.FC = () => { const responseBody = await response.json(); console.log('Response:', responseBody); - setLoading3(false); - - if (Platform.OS === 'android') { - ToastAndroid.show('Succeeded', ToastAndroid.SHORT); - } else { - Alert.alert('Success', 'Succeeded'); - } + setLoading(false); + showNotification('Success', 'Succeeded'); } catch (error) { console.error('Error:', error); - setLoading3(false); - - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } + setLoading(false); + showNotification('Error', 'Failed'); } }; const makePutCall = async () => { - setLoading4(true); + setLoading(true); const url = 'https://httpbin.org/put'; const requestBody = { name: 'Islam', @@ -138,27 +98,17 @@ export const HttpScreen: React.FC = () => { const responseBody = await response.json(); console.log('Response:', responseBody); - setLoading4(false); - - if (Platform.OS === 'android') { - ToastAndroid.show('Succeeded', ToastAndroid.SHORT); - } else { - Alert.alert('Success', 'Succeeded'); - } + setLoading(false); + showNotification('Success', 'Succeeded'); } catch (error) { console.error('Error:', error); - setLoading4(false); - - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } + setLoading(false); + showNotification('Error', 'Failed'); } }; const makePatchCall = async () => { - setLoading5(true); + setLoading(true); const url = 'https://httpbin.org/patch'; const jsonInputString = JSON.stringify({ name: 'Islam' }); @@ -174,27 +124,17 @@ export const HttpScreen: React.FC = () => { const responseBody = await response.json(); console.log('Response:', responseBody); - setLoading5(false); - - if (Platform.OS === 'android') { - ToastAndroid.show('Succeeded', ToastAndroid.SHORT); - } else { - Alert.alert('Success', 'Succeeded'); - } + setLoading(false); + showNotification('Success', 'Succeeded'); } catch (error) { console.error('Error:', error); - setLoading5(false); - - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } + setLoading(false); + showNotification('Error', 'Failed'); } }; const makeDownloadImageCall = async () => { - setLoading6(true); + setLoading(true); const url = 'https://httpbin.org/image/jpeg'; try { const response = await fetch(url, { @@ -207,44 +147,24 @@ export const HttpScreen: React.FC = () => { const responseBody = await response.blob(); console.log('Response:', responseBody); - setLoading6(false); - - if (Platform.OS === 'android') { - ToastAndroid.show('Succeeded', ToastAndroid.SHORT); - } else { - Alert.alert('Success', 'Succeeded'); - } + setLoading(false); + showNotification('Success', 'Succeeded'); } catch (error) { console.error('Error:', error); - setLoading6(false); - - if (Platform.OS === 'android') { - ToastAndroid.show('Failed', ToastAndroid.SHORT); - } else { - Alert.alert('Error', 'Failed'); - } + setLoading(false); + showNotification('Error', 'Failed'); } }; return ( + {loading && } - {loadingGet && } - - {loadingPost && } - - {loadingDelete && } - - {loadingPut && } - - {loadingPatch && } - - {loadingDownloadImage && } ); }; diff --git a/examples/default/src/screens/apm/NetworkScreen.tsx b/examples/default/src/screens/apm/NetworkScreen.tsx index 87c359dff..8aa20f49f 100644 --- a/examples/default/src/screens/apm/NetworkScreen.tsx +++ b/examples/default/src/screens/apm/NetworkScreen.tsx @@ -133,7 +133,7 @@ export const NetworkScreen: React.FC< ))} - navigation.navigate('HttpScreen')} /> + navigation.navigate('HttpScreen')} /> ); diff --git a/examples/default/src/utils/showNotification.ts b/examples/default/src/utils/showNotification.ts new file mode 100644 index 000000000..f7084b46e --- /dev/null +++ b/examples/default/src/utils/showNotification.ts @@ -0,0 +1,9 @@ +import { ToastAndroid, Platform, Alert } from 'react-native'; + +export function showNotification(title: string, message: string): void { + if (Platform.OS === 'android') { + ToastAndroid.show(message, ToastAndroid.SHORT); + } else { + Alert.alert(title, message); + } +} From 4942e6785048f31ce552a64562970cb84294b7d7 Mon Sep 17 00:00:00 2001 From: YoussefFouadd Date: Sun, 6 Oct 2024 17:14:25 +0300 Subject: [PATCH 08/10] Resolving last comment --- examples/default/src/screens/apm/HttpScreen.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/default/src/screens/apm/HttpScreen.tsx b/examples/default/src/screens/apm/HttpScreen.tsx index f3706f3ac..48f972ae4 100644 --- a/examples/default/src/screens/apm/HttpScreen.tsx +++ b/examples/default/src/screens/apm/HttpScreen.tsx @@ -139,9 +139,6 @@ export const HttpScreen: React.FC = () => { try { const response = await fetch(url, { method: 'GET', - headers: { - 'Content-Type': 'image/jpeg', - }, }); const responseBody = await response.blob(); From 919f6522b601e0a728b08857600c5c27880a46c8 Mon Sep 17 00:00:00 2001 From: YoussefFouadd Date: Mon, 7 Oct 2024 10:51:02 +0300 Subject: [PATCH 09/10] Removing Redundant Comment --- .../src/screens/CrashReportingScreen.tsx | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/examples/default/src/screens/CrashReportingScreen.tsx b/examples/default/src/screens/CrashReportingScreen.tsx index acda41e6a..397565ecd 100644 --- a/examples/default/src/screens/CrashReportingScreen.tsx +++ b/examples/default/src/screens/CrashReportingScreen.tsx @@ -1,14 +1,5 @@ import React, { useState } from 'react'; -import { - Alert, - Platform, - ScrollView, - StyleSheet, - Text, - View, - Switch, - ToastAndroid, -} from 'react-native'; +import { Alert, Platform, ScrollView, StyleSheet, Text, View, Switch } from 'react-native'; import { CrashReporting, NonFatalErrorLevel } from 'instabug-reactnative'; @@ -21,6 +12,7 @@ import { VerticalListTile } from '../components/VerticalListTile'; import { Button, VStack } from 'native-base'; import { InputField } from '../components/InputField'; import { Select } from '../components/Select'; +import { showNotification } from '../utils/showNotification'; const styles = StyleSheet.create({ inputWrapper: { @@ -82,16 +74,8 @@ export const CrashReportingScreen: React.FC = () => { const toggleSwitch = (value: boolean) => { setIsEnabled(value); - - // Update APM state here CrashReporting.setEnabled(value); - // Show Toast message - - if (Platform.OS === 'android') { - ToastAndroid.show('Crash Reporting set to ' + value, ToastAndroid.SHORT); - } else { - Alert.alert('Crash Reporting set to ' + value); - } + showNotification('Crash Reporting status', 'Crash Reporting enabled set to ' + value); }; function sendCrash() { From 6cd5325e1c99c7ec21d1d2bae7d8baa336af52bd Mon Sep 17 00:00:00 2001 From: YoussefFouadd Date: Mon, 7 Oct 2024 19:22:08 +0300 Subject: [PATCH 10/10] Resolving latest 2 comments --- .../default/src/screens/LegacyModeScreen.tsx | 42 ++----------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/examples/default/src/screens/LegacyModeScreen.tsx b/examples/default/src/screens/LegacyModeScreen.tsx index cad78605f..8790911c4 100644 --- a/examples/default/src/screens/LegacyModeScreen.tsx +++ b/examples/default/src/screens/LegacyModeScreen.tsx @@ -8,40 +8,12 @@ import { showNotification } from '../utils/showNotification'; export const LegacyModeScreen: React.FC = () => { const [loading, setLoading] = useState(false); - const addInstabugLog = (log: string): Promise => { - return new Promise((resolve) => { - Instabug.logDebug(log); - resolve(); - }); - }; - - const addUserEvent = (event: string): Promise => { - return new Promise((resolve) => { - Instabug.logUserEvent(event); - resolve(); - }); - }; - const addTag = (tag: string): Promise => { - return new Promise((resolve) => { - Instabug.appendTags([tag]); - resolve(); - }); - }; - const addUserAttributes = (key: string, value: string): Promise => { - return new Promise((resolve) => { - Instabug.setUserAttribute(key, value); - resolve(); - }); - }; - const addMultipleInstabugLogs = async (numberOfLogs: number) => { setLoading(true); try { - const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { - logPromises.push(addInstabugLog(`log ${i}`)); + Instabug.logDebug(`log ${i}`); } - await Promise.all(logPromises); showNotification('Success', 'Succeeded'); } catch (error) { showNotification('Error', 'Failed'); @@ -53,11 +25,9 @@ export const LegacyModeScreen: React.FC = () => { const addMultipleUserEvents = async (numberOfLogs: number) => { setLoading(true); try { - const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { - logPromises.push(addUserEvent(`test user event ${i}`)); + Instabug.logUserEvent(`test user event ${i}`); } - await Promise.all(logPromises); showNotification('Success', 'Succeeded'); } catch (error) { showNotification('Error', 'Failed'); @@ -69,11 +39,9 @@ export const LegacyModeScreen: React.FC = () => { const addMultipleTags = async (numberOfLogs: number) => { setLoading(true); try { - const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { - logPromises.push(addTag(`test tag ${i}`)); + Instabug.appendTags([`test tag ${i}`]); } - await Promise.all(logPromises); showNotification('Success', 'Succeeded'); } catch (error) { showNotification('Error', 'Failed'); @@ -85,11 +53,9 @@ export const LegacyModeScreen: React.FC = () => { const addMultipleUserAttributes = async (numberOfLogs: number) => { setLoading(true); try { - const logPromises: Promise[] = []; for (let i = 0; i < numberOfLogs; i++) { - logPromises.push(addUserAttributes(`user${i}`, `user${i} value`)); + Instabug.setUserAttribute(`user${i}`, `user${i} value`); } - await Promise.all(logPromises); showNotification('Success', 'Succeeded'); } catch (error) { showNotification('Error', 'Failed');