Skip to content

Commit

Permalink
Migrating to firebase, still need tokens + chat
Browse files Browse the repository at this point in the history
  • Loading branch information
conorpo committed Dec 25, 2023
1 parent 4779aeb commit 34089c3
Show file tree
Hide file tree
Showing 15 changed files with 1,483 additions and 332 deletions.
7 changes: 5 additions & 2 deletions frontend/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React ,{ useEffect, useContext } from 'react';
import React from 'react';
import { StyleSheet, Image } from 'react-native';
import { DefaultTheme, NavigationContainer} from '@react-navigation/native';
import { createNativeStackNavigator} from '@react-navigation/native-stack';

//Initialize Firebase
import _ from './config/firebaseConfig';

//Screens
import ChatScreen from './screens/Chat.js';
Expand All @@ -19,12 +21,13 @@ const DarkTheme = {
dark: true,
colors: {
...DefaultTheme.colors,
primary: '#ffc904', //UCF Golf
primary: '#ffc904', //UCF Gold
background: '#222222',
text: '#ffffff',
border: '#1a1a1a',
},
}

const App = () => {
return (
<MainProvider>
Expand Down
9 changes: 6 additions & 3 deletions frontend/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ module.exports = function(api) {
return {
presets: ['babel-preset-expo',
'@babel/preset-env',
// '@babel/preset-react'
'@babel/preset-react'
],

plugins: ['@babel/plugin-syntax-jsx']
plugins: [
["@babel/plugin-proposal-private-property-in-object", { "loose": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }],
["@babel/plugin-proposal-private-methods", { "loose": true }]
]
};
};
3 changes: 3 additions & 0 deletions frontend/config/config.js
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',
}
20 changes: 20 additions & 0 deletions frontend/config/firebaseConfig.js
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);
40 changes: 14 additions & 26 deletions frontend/contexts/Main.js
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);
6 changes: 6 additions & 0 deletions frontend/metro.config.js
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;
Loading

0 comments on commit 34089c3

Please sign in to comment.