Skip to content

Commit

Permalink
fix: installation breaks due to lefthook in postinstall (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 committed Jun 5, 2023
1 parent 52092f6 commit e451443
Show file tree
Hide file tree
Showing 20 changed files with 1,427 additions and 1,324 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Expand Up @@ -21,7 +21,7 @@ jobs:
run: npm publish --dry-run

assert-lint:
name: Assert lint check passes and no lint warnings exist
name: Assert lint check passes and no lint errors exist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -37,7 +37,7 @@ jobs:
with:
check-name: 'eslint results'
only-pr-files: false
fail-on-warning: true
fail-on-warning: false
fail-on-error: true
markdown-report-on-step-summary: true
repo-token: "${{ secrets.GITHUB_TOKEN }}"
Expand Down
287 changes: 170 additions & 117 deletions Apps/APN/App.js
@@ -1,13 +1,21 @@
import React, {useEffect, useRef, useState} from 'react';
import { ActivityIndicator,Linking,StyleSheet} from 'react-native';
import React, { useEffect, useRef, useState, useCallback } from 'react';
import { ActivityIndicator, Linking, StyleSheet } from 'react-native';
import Login from './components/Login';
import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
import {
NavigationContainer,
useNavigationContainerRef,
} from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { CustomerIO, CustomerioConfig, CioLogLevel, CustomerIOEnv } from "customerio-reactnative";
import {
CustomerIO,
CustomerioConfig,
CioLogLevel,
CustomerIOEnv,
} from 'customerio-reactnative';
import Dashboard from './components/Dashboard';
import CustomDataScreen from './components/CustomDataScreen';
import SettingsScreen from './components/SettingsScreen'
import Env from "./env";
import SettingsScreen from './components/SettingsScreen';
import Env from './env';
import CioManager from './manager/CioManager';
import CioKeyValueStorage from './manager/KeyValueStorage';
import Deeplinks from './components/Deeplink';
Expand All @@ -16,29 +24,28 @@ import DefaultConstants from './util/DefaultConstants';
const Stack = createNativeStackNavigator();

export default function App() {

const [firstScreen, setFirstScreen] = useState(undefined)
const [firstScreen, setFirstScreen] = useState(undefined);
const [loading, setLoading] = useState(true);
const [isScreenTrackEnabled, setIsScreenTrackEnabled] = useState(null)
const [isDeviceAttrTrackEnabled, setIsDeviceAttrTrackEnabled] = useState(null)
const [isDebugModeEnabled, setIsDebugModeEnabled] = useState(null)
const [bgDelayValue, setBgDelayValue] = useState(null)
const [bgTasksValue, setBgTasksValue] = useState(null)
const [trackingUrl, setTrackingUrl] = useState(null)
const [isScreenTrackEnabled, setIsScreenTrackEnabled] = useState(null);
const [isDeviceAttrTrackEnabled, setIsDeviceAttrTrackEnabled] =
useState(null);
const [isDebugModeEnabled, setIsDebugModeEnabled] = useState(null);
const [bgDelayValue, setBgDelayValue] = useState(null);
const [bgTasksValue, setBgTasksValue] = useState(null);
const [trackingUrl, setTrackingUrl] = useState(null);

useEffect(() => {
(async () => {
const keyStorageObj = new CioKeyValueStorage()
const status = await keyStorageObj.getLoginStatus()
setLoading(false)
const keyStorageObj = new CioKeyValueStorage();
const status = await keyStorageObj.getLoginStatus();
setLoading(false);
if (JSON.parse(status)) {
setFirstScreen("Dashboard")
return
setFirstScreen('Dashboard');
return;
}
setFirstScreen("Login")

setFirstScreen('Login');
})();
}, [])
}, []);

// Automatic screen tracking
const navigationRef = useNavigationContainerRef();
Expand All @@ -50,69 +57,111 @@ const [trackingUrl, setTrackingUrl] = useState(null)
};
const linking = {
prefixes: ['apn-rn-sample://'],
config
config,
};

useEffect(() => {
fetchConfigsOrSetDefault()
}, [])
fetchConfigsOrSetDefault();
}, []);

useEffect(() => {
if(isDeviceAttrTrackEnabled !== null && isScreenTrackEnabled !== null && isDebugModeEnabled != null && bgDelayValue !== null && bgTasksValue !== null)
initialiseCioPackage()
}, [isDeviceAttrTrackEnabled, isScreenTrackEnabled, isDebugModeEnabled, bgDelayValue, bgTasksValue])

const fetchConfigsOrSetDefault = async() => {
const keyStorageObj = new CioKeyValueStorage()
const bgDelayValue = await keyStorageObj.getBGQSecondsDelay()
const bgTasksValue = await keyStorageObj.getBGQMinTasksInQueue()
const screenTrackValue = await keyStorageObj.getScreenTrack()
const deviceAttrValue = await keyStorageObj.getDeviceAttributesTrack()
const debugModeValue = await keyStorageObj.getDebugModeConfig()
const trackUrl = await keyStorageObj.getTrackingUrl()
if (
isDeviceAttrTrackEnabled !== null &&
isScreenTrackEnabled !== null &&
isDebugModeEnabled != null &&
bgDelayValue !== null &&
bgTasksValue !== null
)
initialiseCioPackage();
}, [
isDeviceAttrTrackEnabled,
isScreenTrackEnabled,
isDebugModeEnabled,
bgDelayValue,
bgTasksValue,
initialiseCioPackage,
]);

const fetchConfigsOrSetDefault = async () => {
const keyStorageObj = new CioKeyValueStorage();
const bgDelayValue = await keyStorageObj.getBGQSecondsDelay();

Check warning on line 87 in Apps/APN/App.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/App.js#L87

[no-shadow] 'bgDelayValue' is already declared in the upper scope on line 33 column 10.
const bgTasksValue = await keyStorageObj.getBGQMinTasksInQueue();

Check warning on line 88 in Apps/APN/App.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/App.js#L88

[no-shadow] 'bgTasksValue' is already declared in the upper scope on line 34 column 10.
const screenTrackValue = await keyStorageObj.getScreenTrack();
const deviceAttrValue = await keyStorageObj.getDeviceAttributesTrack();
const debugModeValue = await keyStorageObj.getDebugModeConfig();
const trackUrl = await keyStorageObj.getTrackingUrl();

// Setting values here to show default values on Settings screens
if (screenTrackValue === null) {
await keyStorageObj.saveScreenTrack(DefaultConstants.SCREEN_TRACK_STATUS)
await keyStorageObj.saveScreenTrack(DefaultConstants.SCREEN_TRACK_STATUS);
}
if (bgDelayValue === null) {
await keyStorageObj.saveBGQSecondsDelay(`${DefaultConstants.BGQ_SECONDS_DELAY}`)
await keyStorageObj.saveBGQSecondsDelay(
`${DefaultConstants.BGQ_SECONDS_DELAY}`
);
}
if (bgTasksValue === null) {
await keyStorageObj.saveBGQMinTasksInQueue(`${DefaultConstants.BGQ_MIN_TASKS_IN_QUEUE}`)
await keyStorageObj.saveBGQMinTasksInQueue(
`${DefaultConstants.BGQ_MIN_TASKS_IN_QUEUE}`
);
}
if (deviceAttrValue === null) {
await keyStorageObj.saveDeviceAttributesTrack(`${DefaultConstants.TRACK_DEVICE_ATTRIBUTES_STATUS}`)
await keyStorageObj.saveDeviceAttributesTrack(
`${DefaultConstants.TRACK_DEVICE_ATTRIBUTES_STATUS}`
);
}
if (debugModeValue === null) {
await keyStorageObj.saveDebugModeConfig(`${DefaultConstants.DEBUG_MODE_STATUS}`)
await keyStorageObj.saveDebugModeConfig(
`${DefaultConstants.DEBUG_MODE_STATUS}`
);
}
setIsDeviceAttrTrackEnabled(deviceAttrValue === null ? true : JSON.parse(deviceAttrValue))
setIsScreenTrackEnabled(screenTrackValue === null ? true : JSON.parse(screenTrackValue))
setIsDebugModeEnabled(debugModeValue === null ? true : JSON.parse(debugModeValue))
setBgDelayValue(bgDelayValue === null ? DefaultConstants.BGQ_SECONDS_DELAY : parseInt(bgDelayValue))
setBgTasksValue(bgTasksValue === null ? DefaultConstants.BGQ_MIN_TASKS_IN_QUEUE : parseInt(bgTasksValue))
setTrackingUrl(trackUrl)
}

const initialiseCioPackage = () => {
setIsDeviceAttrTrackEnabled(
deviceAttrValue === null ? true : JSON.parse(deviceAttrValue)
);
setIsScreenTrackEnabled(
screenTrackValue === null ? true : JSON.parse(screenTrackValue)
);
setIsDebugModeEnabled(
debugModeValue === null ? true : JSON.parse(debugModeValue)
);
setBgDelayValue(
bgDelayValue === null
? DefaultConstants.BGQ_SECONDS_DELAY
: parseInt(bgDelayValue)

Check warning on line 130 in Apps/APN/App.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/App.js#L130

[radix] Missing radix parameter.
);
setBgTasksValue(
bgTasksValue === null
? DefaultConstants.BGQ_MIN_TASKS_IN_QUEUE
: parseInt(bgTasksValue)

Check warning on line 135 in Apps/APN/App.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/App.js#L135

[radix] Missing radix parameter.
);
setTrackingUrl(trackUrl);
};

const configuration = new CustomerioConfig()
configuration.logLevel = isDebugModeEnabled === null ? CioLogLevel.debug : isDebugModeEnabled
configuration.autoTrackDeviceAttributes = isDeviceAttrTrackEnabled === null ? true : isDeviceAttrTrackEnabled
configuration.backgroundQueueMinNumberOfTasks = bgTasksValue
configuration.backgroundQueueSecondsDelay = bgDelayValue
if(trackingUrl != null) {
configuration.trackingApiUrl = trackingUrl
const initialiseCioPackage = useCallback(() => {
const configuration = new CustomerioConfig();
configuration.logLevel =
isDebugModeEnabled === null ? CioLogLevel.debug : isDebugModeEnabled;
configuration.autoTrackDeviceAttributes =
isDeviceAttrTrackEnabled === null ? true : isDeviceAttrTrackEnabled;
configuration.backgroundQueueMinNumberOfTasks = bgTasksValue;
configuration.backgroundQueueSecondsDelay = bgDelayValue;
if (trackingUrl != null) {
configuration.trackingApiUrl = trackingUrl;
}

const env = new CustomerIOEnv()
env.siteId = Env.siteId
env.apiKey = Env.apiKey

const cioManager = new CioManager()
cioManager.initializeCio(env, configuration)
}
const env = new CustomerIOEnv();
env.siteId = Env.siteId;
env.apiKey = Env.apiKey;

const cioManager = new CioManager();
cioManager.initializeCio(env, configuration);
}, [
isDebugModeEnabled,
isDeviceAttrTrackEnabled,
bgTasksValue,
bgDelayValue,
trackingUrl,
]);

useEffect(() => {
const getUrlAsync = async () => {
Expand All @@ -129,13 +178,10 @@ const [trackingUrl, setTrackingUrl] = useState(null)
getUrlAsync();
}, []);

if (loading == true ) {
return (
<ActivityIndicator/>
)
if (loading == true) {

Check warning on line 181 in Apps/APN/App.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/App.js#L181

[eqeqeq] Expected '===' and instead saw '=='.
return <ActivityIndicator />;
} else {
return (

return (
// MARK:- AUTO SCREEN TRACKING
// Start
<NavigationContainer
Expand All @@ -148,63 +194,70 @@ const [trackingUrl, setTrackingUrl] = useState(null)
if (isScreenTrackEnabled) {
const previousRouteName = routeNameRef.current;
const currentRouteName = navigationRef.getCurrentRoute().name;

if (previousRouteName !== currentRouteName) {
CustomerIO.screen(currentRouteName)
CustomerIO.screen(currentRouteName);
}
routeNameRef.current = currentRouteName;
}
}}
// End
>

<Stack.Navigator initialRouteName={firstScreen}>
<Stack.Screen name="Login"
component={Login}
options={{
headerShown : false,
gestureEnabled: false,
gestureDirection: 'vertical',
}}/>
<Stack.Screen name="Dashboard" component={Dashboard}
options={{
headerShown : false,
gestureEnabled: false,

}}
/>
<Stack.Screen name="CustomDataScreen" component={CustomDataScreen}
options={{
title:"",
headerStyle: {
backgroundColor: '#ffffff'},
}}
/>
<Stack.Screen name="Deeplinks" component={Deeplinks}
options={{
title:"",
}}
/>
<Stack.Screen name="SettingsScreen" component={SettingsScreen}
options={{
title:"",
headerStyle: {
// backgroundColor: '#ffffff'
},
}}
/>
</Stack.Navigator>

</NavigationContainer>
>
<Stack.Navigator initialRouteName={firstScreen}>
<Stack.Screen
name="Login"
component={Login}
options={{
headerShown: false,
gestureEnabled: false,
gestureDirection: 'vertical',
}}
/>
<Stack.Screen
name="Dashboard"
component={Dashboard}
options={{
headerShown: false,
gestureEnabled: false,
}}
/>
<Stack.Screen
name="CustomDataScreen"
component={CustomDataScreen}
options={{
title: '',
headerStyle: {
backgroundColor: '#ffffff',
},
}}
/>
<Stack.Screen
name="Deeplinks"
component={Deeplinks}
options={{
title: '',
}}
/>
<Stack.Screen
name="SettingsScreen"
component={SettingsScreen}
options={{
title: '',
headerStyle: {
// backgroundColor: '#ffffff'
},
}}
/>
</Stack.Navigator>
</NavigationContainer>
);
}
}
}
const styles = StyleSheet.create({

Check warning on line 256 in Apps/APN/App.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/App.js#L256

[no-unused-vars] 'styles' is assigned a value but never used.
mainView: {
flex: 1,
flexDirection: 'row',
paddingTop : 50,
justifyContent:'center'
paddingTop: 50,
justifyContent: 'center',
},
});

4 changes: 2 additions & 2 deletions Apps/APN/babel.config.js
@@ -1,7 +1,7 @@
module.exports = function(api) {
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: ['react-native-reanimated/plugin']
plugins: ['react-native-reanimated/plugin'],
};
};

0 comments on commit e451443

Please sign in to comment.