-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from hendrixgotcodes/dev
migrated to typescript #3
- Loading branch information
Showing
158 changed files
with
6,527 additions
and
5,403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 4, | ||
"semi": true, | ||
"singleQuote": false, | ||
"endOfLine": "auto" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 /> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.