Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed compatibility issues with newer versions of dependencies #47

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import React, { useRef, useState } from 'react';
import './App.css';

import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
import 'firebase/analytics';
import { initializeApp } from 'firebase/app';
import { getAuth, GoogleAuthProvider, signInWithPopup, signOut, onAuthStateChanged } from 'firebase/auth';
import { getFirestore, collection, query, orderBy, limit, addDoc, serverTimestamp } from 'firebase/firestore';
import { getAnalytics } from 'firebase/analytics';

import { useAuthState } from 'react-firebase-hooks/auth';
import { useCollectionData } from 'react-firebase-hooks/firestore';

firebase.initializeApp({
// Initialize Firebase
const firebaseApp = initializeApp({
// your config
})

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

const auth = getAuth(firebaseApp);
const firestore = getFirestore(firebaseApp);
const analytics = getAnalytics(firebaseApp);

function App() {

const [user] = useAuthState(auth);

return (
@@ -38,10 +37,9 @@ function App() {
}

function SignIn() {

const signInWithGoogle = () => {
const provider = new firebase.auth.GoogleAuthProvider();
auth.signInWithPopup(provider);
const provider = new GoogleAuthProvider();
signInWithPopup(auth, provider);
}

return (
@@ -50,34 +48,31 @@ function SignIn() {
<p>Do not violate the community guidelines or you will be banned for life!</p>
</>
)

}

function SignOut() {
return auth.currentUser && (
<button className="sign-out" onClick={() => auth.signOut()}>Sign Out</button>
<button className="sign-out" onClick={() => signOut(auth)}>Sign Out</button>
)
}


function ChatRoom() {
const dummy = useRef();
const messagesRef = firestore.collection('messages');
const query = messagesRef.orderBy('createdAt').limit(25);
const messagesRef = collection(firestore, 'messages');
const q = query(messagesRef, orderBy('createdAt'), limit(25));

const [messages] = useCollectionData(query, { idField: 'id' });
const [messages] = useCollectionData(q, { idField: 'id' });

const [formValue, setFormValue] = useState('');


const sendMessage = async (e) => {
e.preventDefault();

const { uid, photoURL } = auth.currentUser;

await messagesRef.add({
await addDoc(messagesRef, {
text: formValue,
createdAt: firebase.firestore.FieldValue.serverTimestamp(),
createdAt: serverTimestamp(),
uid,
photoURL
})
@@ -119,5 +114,4 @@ function ChatMessage(props) {
</>)
}


export default App;