-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrating to firebase, still need tokens + chat
- Loading branch information
Showing
15 changed files
with
1,483 additions
and
332 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
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
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,3 @@ | ||
export const config = { | ||
URI : (__DEV__ == true) ? 'http://localhost:3000' : 'https://pt-gpt.com', | ||
} |
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,20 @@ | ||
// Import the functions you need from the SDKs you need | ||
import { initializeApp } from "firebase/app"; | ||
import { getAuth } from "firebase/auth"; | ||
import { getFirestore } from "firebase/firestore"; | ||
|
||
// For Firebase JS SDK v7.20.0 and later, measurementId is optional | ||
const firebaseConfig = { | ||
apiKey: "AIzaSyAm6LpGIvC6SKd6lGtzAjgLxLjeov1doDQ", | ||
authDomain: "pt-gpt.firebaseapp.com", | ||
projectId: "pt-gpt", | ||
storageBucket: "pt-gpt.appspot.com", | ||
messagingSenderId: "160696689322", | ||
appId: "1:160696689322:web:ef178a5c05057bc7dc26d3", | ||
measurementId: "G-LR20VKVT4L" | ||
}; | ||
|
||
// Initialize Firebase | ||
const app = initializeApp(firebaseConfig); | ||
const auth = getAuth(app); | ||
const db = getFirestore(app); |
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,38 +1,26 @@ | ||
import {createContext, useEffect, useState} from 'react'; | ||
import {v4 as messageIdGenerator} from 'uuid'; | ||
import {createContext, useState, useContext, useEffect} from 'react'; | ||
import {app} from '../config/firebaseConfig'; | ||
|
||
const MainContext = createContext(); | ||
|
||
const MainProvider = ({children}) => { | ||
const [user, setUser] = useState(null); | ||
export const MainProvider = ({children}) => { | ||
const [authUser, setAuthUser] = useState(null); // Firebase Auth User | ||
const [profile, setProfile] = useState(null); // Firestore User Profile | ||
const [messages, setMessages] = useState([]); | ||
const [token, setToken] = useState(null); | ||
const [token, setToken] = useState(null); | ||
|
||
const config = { | ||
URI : (__DEV__ == true) ? 'http://localhost:3000' : 'https://pt-gpt.com', | ||
} | ||
|
||
const helpers = { | ||
messageIdGenerator, | ||
convertMessage: function(message) { | ||
console.log(this); | ||
return { | ||
_id: messageIdGenerator(), | ||
text: message.content, | ||
createdAt: message.createdAt, | ||
user: { | ||
_id: message.role, | ||
name: (message.role == 'user') ? this.name : this.personality, | ||
avatar: `${config.URI}/imgs/personalities/${this.personality}.png` | ||
} | ||
}; | ||
useEffect(() => { | ||
if(!authUser) { | ||
setProfile(null); | ||
setMessages([]); | ||
} | ||
} | ||
}, [authUser]); | ||
|
||
return ( | ||
<MainContext.Provider value={{token, setToken, user, setUser, messages, setMessages, config, helpers}}> | ||
<MainContext.Provider value={{authUser, setAuthUser, profile, setProfile, messages, setMessages, token, setToken}}> | ||
{children} | ||
</MainContext.Provider> | ||
) | ||
}; | ||
|
||
export {MainContext, MainProvider}; | ||
export const useMainContext = () => useContext(MainContext); |
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,6 @@ | ||
const { getDefaultConfig } = require('@expo/metro-config'); | ||
|
||
const defaultConfig = getDefaultConfig(__dirname); | ||
defaultConfig.resolver.sourceExts.push('cjs'); | ||
|
||
module.exports = defaultConfig; |
Oops, something went wrong.