Skip to content

Commit

Permalink
Add: remaining Logging w/ error handling & alerting
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldanielecki committed Jul 14, 2022
1 parent 5d36840 commit 3ad5b4b
Show file tree
Hide file tree
Showing 13 changed files with 567 additions and 265 deletions.
20 changes: 15 additions & 5 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
import "react-native-gesture-handler";
import analytics from "@react-native-firebase/analytics";
import crashlytics from "@react-native-firebase/crashlytics";
import eventsReducer from "./store/reducers/events";
import useCachedResources from "./hooks/useCachedResources";
import useColorScheme from "./hooks/useColorScheme";
import React from "react";
import Navigation from "./navigation";
import ReduxThunk from "redux-thunk";
import { applyMiddleware, createStore, combineReducers } from "redux";
import { init } from "./helpers/db";
import { init } from "./helpers/sqlite_db";
import { StatusBar } from "expo-status-bar";
import { Provider as PaperProvider } from "react-native-paper";
import { Provider as StoreProvider } from "react-redux";

init()
.then(() => {
console.log("Initialized database was successful.");
analytics().logEvent("custom_log", {
description: "--- Analytics: App -> init -> then",
});
})
.catch((error) => {
.catch((error: unknown) => {
if (error instanceof Error) {
console.log("Initializing database has failed.");
console.error(error);
analytics().logEvent("custom_log", {
description: "--- Analytics: App -> init -> catch, error: " + error,
});
crashlytics().recordError(error);
}
}).finally(() => {
analytics().logEvent("custom_log", {
description: "--- Analytics: App -> init -> finally",
});
});

const rootReducer = combineReducers({
Expand Down
4 changes: 4 additions & 0 deletions common/isInternetConnectionAvailable.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import analytics from "@react-native-firebase/analytics";
import NetInfo, { NetInfoState } from "@react-native-community/netinfo";

let stateIsConnected: boolean | null = null;
export const isInternetConnectionAvailable: () => Promise<boolean | null> = async () => {
NetInfo.addEventListener((state: NetInfoState) => {
stateIsConnected = state.isConnected;
});
analytics().logEvent("custom_log", {
description: "--- Analytics: common -> isInternetConnectionAvailable -> stateIsConnected: " + stateIsConnected,
});
return stateIsConnected;
}

Expand Down
22 changes: 20 additions & 2 deletions common/writeItemToStorage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import analytics from "@react-native-firebase/analytics";
import crashlytics from "@react-native-firebase/crashlytics";
import AsyncStorage from '@react-native-async-storage/async-storage';
import { Alert } from "react-native";
import { Event } from "../interfaces/event";
Expand All @@ -7,16 +9,32 @@ export const writeItemToStorage: (eventsToAsyncStorage: Event[]) => Promise<void

try {
await AsyncStorage.setItem("EVENTS_ASYNC_STORAGE", eventsInJSONString);

analytics().logEvent("custom_log", {
description: "--- Analytics: common -> writeItemToStorage -> try, eventsInJSONString: " + eventsInJSONString,
});
} catch (error: unknown) {
if (error instanceof Error) {
console.error('useAsyncStorage getItem error:', error);
Alert.alert(
"Error ❌",
"Problem with saving events on a local device to avoid a big load during next application launch.",
[{ text: "Okay" }]
);

analytics().logEvent("custom_log", {
description: "--- Analytics: common -> writeItemToStorage -> catch, error: " + error,
});
crashlytics().recordError(error);
}
} finally {
Alert.alert(
"Events loaded ✅",
"Events locally saved ✅",
"Once a week, TamoTam will make such a big load of external events.",
[{ text: "Okay" }]
);
analytics().logEvent("custom_log", {
description: "--- Analytics: common -> writeItemToStorage -> finally",
});
}
};

Expand Down
11 changes: 11 additions & 0 deletions components/SelectImage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ImagePicker from "expo-image-picker";
import analytics from "@react-native-firebase/analytics";
import useColorScheme from "../hooks/useColorScheme";
import Colors from "../constants/Colors";
import React, { useEffect, useState } from "react";
Expand All @@ -18,6 +19,13 @@ const SelectImage = (props: {
if (Platform.OS !== "web") {
const { status } =
await ImagePicker.requestMediaLibraryPermissionsAsync();

analytics().logEvent("custom_log", {
description: "--- Analytics: components -> SelectImage -> useEffect[], status: " + status,
});
analytics().logEvent("custom_log", {
description: "--- Analytics: components -> SelectImage -> useEffect[], Platform.OS: " + Platform.OS,
});
if (status !== "granted") {
Alert.alert(
"⚠️ Insufficient permissions! ⚠️",
Expand All @@ -44,6 +52,9 @@ const SelectImage = (props: {
setPickedImage(image.uri);
props.onImageTaken(image.uri);
}
analytics().logEvent("custom_log", {
description: "--- Analytics: components -> SelectImage -> selectImageHandler, image: " + image,
});
};

return (
Expand Down
16 changes: 13 additions & 3 deletions components/Themed.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import analytics from "@react-native-firebase/analytics";
import useColorScheme from "../hooks/useColorScheme";
import Colors from "../constants/Colors";
import React from "react";
Expand All @@ -7,9 +8,12 @@ export function useThemeColor(
props: { light?: string; dark?: string },
colorName: keyof typeof Colors.light & keyof typeof Colors.dark
) {
const theme = useColorScheme();
const theme: "light" | "dark" = useColorScheme();
const colorFromProps: string | undefined = props[theme];

analytics().logEvent("custom_log", {
description: "--- Analytics: components -> Themed -> useThemeColor, theme: " + theme,
});
if (colorFromProps) {
return colorFromProps;
} else {
Expand All @@ -28,17 +32,23 @@ export type ViewProps = ThemeProps & DefaultView["props"];
// TODO: For now it's not being used, check out how text could be changed not manually, but instead using this function.
export function Text(props: TextProps) {
const { darkColor, lightColor, style, ...otherProps } = props;
const color = useThemeColor({ dark: darkColor, light: lightColor }, "text");
const color: string = useThemeColor({ dark: darkColor, light: lightColor }, "text");

analytics().logEvent("custom_log", {
description: "--- Analytics: components -> Themed -> Text, color: " + color,
});
return <DefaultText style={[{ color }, style]} {...otherProps} />;
}

export function View(props: ViewProps) {
const { darkColor, lightColor, style, ...otherProps } = props;
const backgroundColor = useThemeColor(
const backgroundColor: string = useThemeColor(
{ dark: darkColor, light: lightColor },
"background"
);

analytics().logEvent("custom_log", {
description: "--- Analytics: components -> Themed -> View, backgroundColor: " + backgroundColor,
});
return <DefaultView style={[{ backgroundColor }, style]} {...otherProps} />;
}
89 changes: 0 additions & 89 deletions helpers/db.js

This file was deleted.

0 comments on commit 3ad5b4b

Please sign in to comment.