Skip to content

Commit

Permalink
Merge pull request #14 from hendrixgotcodes/dev
Browse files Browse the repository at this point in the history
migrated to typescript #3
  • Loading branch information
hendrixgotcodes committed Aug 12, 2022
2 parents 310ed72 + 8c87e45 commit cc96adf
Show file tree
Hide file tree
Showing 158 changed files with 6,527 additions and 5,403 deletions.
39 changes: 39 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"env": {
"browser": true,
"es2021": true,
"react-native/react-native": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint",
"react-native"
],
"rules": {
"react-native/no-unused-styles": 2,
"react-native/split-platform-components": 2,
"react-native/no-inline-styles": 2,
"react-native/no-color-literals": 2,
"react-native/no-raw-text": "off",
"react-native/no-single-element-style-arrays": 2,
"react/prop-types": "off",
"import/namespace": "off",
"import/extensions": "off",
"@typescript-eslint/no-explicit-any": "off"
},
"ignorePatterns":["/node_modules/*", "/.expo/*", "/.expo-shared/*", "/.vscode/*", "babel.config.js"]
}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": true,
"singleQuote": false,
"endOfLine": "auto"
}
102 changes: 49 additions & 53 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,52 @@
import React, {useState, useEffect} from 'react';
import {NavigationContainer} from '@react-navigation/native'
import NetInfo, {useNetInfo} from '@react-native-community/netinfo'
import AppLoading from 'expo-app-loading'

//Component
import AppNavigator from './app/components/navigators/AppNavigator'
import AuthNavigator from './app/components/navigators/AuthNavigator'
import NotificationBanner from './app/components/NotificationBanner'

//Assets
import AuthContext from './app/auth/context'
import authStorage from './app/auth/storage'
import myTheme from './app/components/navigators/navigationTheme'
import navigationRef from './app/components/navigators/rootNavigation'


import { useNetInfo } from "@react-native-community/netinfo";
import { NavigationContainer } from "@react-navigation/native";
import AppLoading from "expo-app-loading";
import React, { useState } from "react";

// Component

// Assets
import AuthContext from "./app/auth/context";
import authStorage from "./app/auth/storage";
import AppNavigator from "./app/components/navigators/AppNavigator";
import AuthNavigator from "./app/components/navigators/AuthNavigator";
import myTheme from "./app/components/navigators/navigationTheme";
import navigationRef from "./app/components/navigators/rootNavigation";
import NotificationBanner from "./app/components/NotificationBanner";

export default function App() {

const NetInfo = useNetInfo()
const [isAppReady, setIsAppReady] = useState(false)
const [user, setUser] = useState()



const restoreUser = async ()=>{

const user = await authStorage.getUser()

if(!user) return
setUser(user)

}

if(!isAppReady){
return (<AppLoading startAsync={restoreUser} onFinish={()=> setIsAppReady(true)} onError={(error)=>console.log(error)} />)
}

return (
<>
{
(NetInfo.isInternetReachable === false && NetInfo.type !== "unknown") && <NotificationBanner />
}
{/* <NotificationBanner /> */}
<AuthContext.Provider value={{user, setUser}}>
<NavigationContainer ref={navigationRef} theme={myTheme}>
{user ? <AppNavigator /> : <AuthNavigator />}
</NavigationContainer>
</AuthContext.Provider>
</>
// <ChatScreen />

)

const NetInfo = useNetInfo();
const [isAppReady, setIsAppReady] = useState(false);
const [user, setUser] = useState();

const restoreUser = async () => {
const user = await authStorage.getUser();

if (!user) return;
setUser(user);
};

if (!isAppReady) {
return (
<AppLoading
startAsync={restoreUser}
onFinish={() => setIsAppReady(true)}
onError={(error) => console.log(error)}
/>
);
}

return (
<>
{NetInfo.isInternetReachable === false &&
NetInfo.type !== "unknown" && <NotificationBanner />}
{/* <NotificationBanner /> */}
<AuthContext.Provider value={{ user, setUser }}>
<NavigationContainer ref={navigationRef} theme={myTheme}>
{user ? <AppNavigator /> : <AuthNavigator />}
</NavigationContainer>
</AuthContext.Provider>
</>
// <ChatScreen />
);
}
106 changes: 0 additions & 106 deletions app/api/auth.js

This file was deleted.

73 changes: 73 additions & 0 deletions app/api/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { User } from "../types";
import firebase from "./firebase";

const auth = firebase.auth();
const db = firebase.firestore();

const getCurrentUser = () => auth.currentUser;

async function login (email: string, password:string):Promise<User>{
try {
await auth.signInWithEmailAndPassword(email, password);
const response = await db
.collection("users")
.doc(auth.currentUser?.uid)
.get();

return {
...response.data() as User,
uid: auth.currentUser ? auth.currentUser?.uid : "",
};
} catch (error: any) {
switch (error.code) {
case "auth/invalid-password":
throw new Error("Invalid password");
case "auth/invalid-email":
throw new Error("Your email is invalid");
case "auth/wrong-password":
throw new Error("Incorrect password");
case "auth/user-not-found":
throw new Error(
"It appears you have no account with us. Please try sign up."
);
default:
throw new Error("An unknown error occurred");
}
}
};

const logOut = async () => {
await auth.signOut();
};

const register = async (email:string, password:string) => {
try {
const { user } = await auth.createUserWithEmailAndPassword(
email,
password
);
return user;
} catch (error:any) {
switch (error.code) {
case "auth/invalid-password":
throw new Error("Invalid password");
case "auth/email-already-in-use":
throw new Error("Email already existes");
case "auth/wrong-password":
throw new Error("Incorrect password");
case "auth/user-not-found":
throw new Error(
"It appears you have no account with us. Please try sign up."
);
default:
throw new Error("An unknown error occured");
}
}
};

export default {
getCurrentUser,
login,
logOut,
register,
};
54 changes: 0 additions & 54 deletions app/api/client.js

This file was deleted.

Loading

0 comments on commit cc96adf

Please sign in to comment.