Skip to content

Commit

Permalink
Merge branch 'feat/fusion-mobile'
Browse files Browse the repository at this point in the history
  • Loading branch information
oreHGA committed Jul 9, 2023
2 parents a2a9553 + 2ac43e4 commit 7e863c1
Show file tree
Hide file tree
Showing 100 changed files with 18,892 additions and 16,009 deletions.
5 changes: 4 additions & 1 deletion fusionMobile/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ module.exports = {
extends: [
"universe/native",
"universe/shared/typescript-analysis",
"plugin:@tanstack/eslint-plugin-query/recommended",
"prettier",
],
plugins: ["@typescript-eslint", "unused-imports"],
plugins: ["@typescript-eslint", "unused-imports", "@tanstack/query"],
ignorePatterns: ["ios", "android"],
overrides: [
{
Expand All @@ -15,6 +16,8 @@ module.exports = {
rules: {
"prettier/prettier": "off",
"unused-imports/no-unused-imports": "error",
"@tanstack/query/exhaustive-deps": "error",
"@tanstack/query/prefer-query-object-syntax": "error",
"import/order": [
1,
{
Expand Down
57 changes: 43 additions & 14 deletions fusionMobile/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { PortalProvider } from "@gorhom/portal";
import { useNavigation } from "@react-navigation/native";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import dayjs from "dayjs";
import { Logs } from "expo";
import Constants from "expo-constants";
import * as Notifications from "expo-notifications";
import * as SplashScreen from "expo-splash-screen";
import React from "react";
import { Alert, Platform, StatusBar } from "react-native";
import { Alert, Linking, Platform, StatusBar } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import Toast from "react-native-toast-message";

import { FontLoader } from "./FontLoader";
import { CustomNavigation } from "./src/navigation";
import { maskPromptId, appInsights } from "./src/utils";

import { QUERY_OPTIONS_DEFAULT } from "~/config";
import { PromptContextProvider } from "~/contexts";
import { notificationService, promptService } from "~/services";
import { toastConfig } from "~/theme";

Logs.enableExpoCliLogging();

Expand All @@ -23,11 +26,21 @@ const registerForPushNotificationsAsync = async () => {
const { status: existingStatus } = await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
if (existingStatus !== "granted") {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
Alert.alert(
"Notification Permission",
"We need your permission to send you notifications based on your prompt settings.",
[
{
text: "OK",
onPress: async () => {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
},
},
]
);
}
if (finalStatus !== "granted") {
Alert.alert("Error", "Failed to get push token for push notification!");
return false;
}

Expand All @@ -44,7 +57,7 @@ const registerForPushNotificationsAsync = async () => {
};

Notifications.setNotificationHandler({
handleNotification: async (notification) => {
handleNotification: async () => {
return {
shouldShowAlert: true,
shouldPlaySound: false,
Expand All @@ -53,7 +66,12 @@ Notifications.setNotificationHandler({
},
});

SplashScreen.preventAutoHideAsync();
// SplashScreen.preventAutoHideAsync(); - temp remove since asking for notification permission on first load causes hiding splash screen to fail

// Create a client
const queryClient = new QueryClient({
defaultOptions: QUERY_OPTIONS_DEFAULT,
});

function App() {
const responseListener = React.useRef<
Expand All @@ -67,8 +85,16 @@ function App() {
const permissionStatus = await registerForPushNotificationsAsync();
if (!permissionStatus) {
Alert.alert(
"Error",
"Failed to register for push notifications, please quit, turn on notifications for fusion & restart the app"
"Enable notifications",
"We only notify you based on your prompt settings. Please enable notifications in your settings to continue.",
[
{
text: "OK",
onPress: async () => {
Linking.openURL("app-settings:Fusion");
},
},
]
);
return;
}
Expand Down Expand Up @@ -232,12 +258,15 @@ function App() {
<GestureHandlerRootView className="flex flex-1 flex-grow-1">
<FontLoader>
<StatusBar barStyle="light-content" />
<PromptContextProvider>
<PortalProvider>
<CustomNavigation />
</PortalProvider>
</PromptContextProvider>
<QueryClientProvider client={queryClient}>
<PromptContextProvider>
<PortalProvider>
<CustomNavigation />
</PortalProvider>
</PromptContextProvider>
</QueryClientProvider>
</FontLoader>
<Toast config={toastConfig} position="bottom" />
</GestureHandlerRootView>
);
}
Expand Down
8 changes: 3 additions & 5 deletions fusionMobile/FontLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ interface Props extends PropsWithChildren {
onFontsLoaded?: () => void; // callback for displaying the splash screen once background view has loaded
}

SplashScreen.preventAutoHideAsync();

export const FontLoader = ({ onFontsLoaded, children }: Props) => {
const insets = useSafeAreaInsets();
const [fontsLoaded] = useFonts({
Expand All @@ -23,9 +21,9 @@ export const FontLoader = ({ onFontsLoaded, children }: Props) => {
});

const onLayoutRootView = useCallback(async () => {
if (fontsLoaded) {
await SplashScreen.hideAsync(); //hide the splashscreen
}
// if (fontsLoaded) {
// await SplashScreen.hideAsync(); //hide the splashscreen
// }
}, [fontsLoaded, onFontsLoaded]);

if (!fontsLoaded) {
Expand Down
17 changes: 15 additions & 2 deletions fusionMobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,35 @@ Data is currently stored using AsyncStorage (SQLite)
uuid
promptText
responseType - "number", "yesno", "text", "customOptions"
additionalMeta - json.stringify of dictionary for customOption maps
additionalMeta - {category, isNotificationActive, customOptionsText}
notificationConfig_days - json.stringify of "{"monday": true, "tuesday": false ....., "sunday": true}"
notificationConfig_startTime
notificationConfig_endTime
notificationConfig_countPerDay
}
```

customOptionText will look like - 'optionA;optionB;optionC'

After a prompt is created, a notification is generated.

Response to prompts are saved in format

```json
{
triggerTimestamp
endTimestamp
responseTimestamp
value
promptUuid
additionalMeta {
note: string
}
}
```

when responseType == customOption,
value can contain "valA;valB"

They can eventually exported in fusion Event schema [doc](../README.md)

Mapping Fusion event schema to prompt_response
Expand Down Expand Up @@ -259,3 +267,8 @@ Prompt response view

- Share screen should eventually allow users select what prompts
& who they want to share the results to in Fusion :)

# Setting environment variables

Expo handles environment variables a little different than regular web app. We set them in the app.config.ts file.
and then use constants. See appInsights.js for an example. More docs - https://docs.expo.dev/build-reference/variables/
2 changes: 1 addition & 1 deletion fusionMobile/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ android {
applicationId 'com.neurofusion.fusion'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 10
versionCode 27
versionName "1.0.0"
}

Expand Down
2 changes: 1 addition & 1 deletion fusionMobile/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://exp.host/@oreogundipe/fusion"/>
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustPan" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Binary file modified fusionMobile/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fusionMobile/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions fusionMobile/android/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>
<color name="splashscreen_background">#ffffff</color>
<color name="iconBackground">#FFFFFF</color>
<color name="splashscreen_background">#0B0816</color>
<color name="iconBackground">#0B0816</color>
<color name="colorPrimary">#023c69</color>
<color name="colorPrimaryDark">#ffffff</color>
<color name="colorPrimaryDark">#0B0816</color>
<color name="activityBackground">#0B0816</color>
</resources>
1 change: 1 addition & 0 deletions fusionMobile/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowBackground">@color/activityBackground</item>
</style>
<style name="ResetEditText" parent="@android:style/Widget.EditText">
<item name="android:padding">0dp</item>
Expand Down
9 changes: 6 additions & 3 deletions fusionMobile/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
version: "1.0.0",
orientation: "portrait",
icon: "./assets/icon.png",
userInterfaceStyle: "light",
backgroundColor: "#0B0816",
splash: {
image: "./assets/splash.png",
Expand All @@ -21,7 +20,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
ios: {
supportsTablet: true,
bundleIdentifier: "com.neurofusion.fusion",
buildNumber: "14",
buildNumber: "37",
backgroundColor: "#0B0816",
},
android: {
Expand All @@ -30,7 +29,8 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
backgroundColor: "#0B0816",
},
package: "com.neurofusion.fusion",
versionCode: 7,
versionCode: 27,
softwareKeyboardLayoutMode: "pan",
},
web: {
favicon: "./assets/favicon.png",
Expand All @@ -41,6 +41,9 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
projectId: "f79cfe2d-2f56-413a-89f8-b9fde538ac75",
},
storybookEnabled: process.env.STORYBOOK_ENABLED,
appInsightsConnectionString:
process.env.APP_INSIGHTS_CONNECTION_STRING ??
"InstrumentationKey=5a52ca8a-bd71-4c4c-84f6-d51429acbe03;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/",
},
plugins: ["expo-notifications"],
owner: "oreogundipe",
Expand Down
43 changes: 0 additions & 43 deletions fusionMobile/app.json

This file was deleted.

Binary file added fusionMobile/assets/delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fusionMobile/assets/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fusionMobile/assets/pie-chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions fusionMobile/eas.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@
"ios": {
"resourceClass": "m-medium"
},
"env": {}
"env": {
"APP_INSIGHTS_CONNECTION_STRING": "InstrumentationKey=5a52ca8a-bd71-4c4c-84f6-d51429acbe03;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/"
}
},
"preview": {
"distribution": "internal",
"ios": {
"resourceClass": "m-medium"
},
"env": {}
"env": {
"APP_INSIGHTS_CONNECTION_STRING": "InstrumentationKey=5a52ca8a-bd71-4c4c-84f6-d51429acbe03;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/"
}
},
"production": {
"ios": {
"resourceClass": "m-medium"
},
"env": {}
"env": {
"APP_INSIGHTS_CONNECTION_STRING": "InstrumentationKey=e9a047e3-efc6-4339-acef-1ef135fd15ea;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/"
}
}
},
"submit": {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion fusionMobile/ios/Fusion/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>19</string>
<string>37</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand All @@ -60,6 +60,13 @@
<string>Share recorded data on Fusion with Apple.</string>
<key>NSMotionUsageDescription</key>
<string>For fetching data on your steps</string>
<key>RCTRootViewBackgroundColor</key>
<integer>4278913046</integer>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
<string>fetch</string>
</array>
<key>UILaunchStoryboardName</key>
<string>SplashScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
Loading

1 comment on commit 7e863c1

@vercel
Copy link

@vercel vercel bot commented on 7e863c1 Jul 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

fusion – ./neurofusion/next-client

fusion-neurofusion-research-inc.vercel.app
www.usefusion.app
usefusion.app
fusion-git-master-neurofusion-research-inc.vercel.app

Please sign in to comment.