forked from louisrli/recoded-facebook-students
-
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.
First working version of everything.
- Loading branch information
Showing
9 changed files
with
755 additions
and
80 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 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
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,38 @@ | ||
import React from 'react'; | ||
import db from './firebase'; | ||
|
||
// These props are destructured from the Firebase field names. | ||
const ProfileBox = ({city, imageUrl, name, profile, userId }) => { | ||
return ( | ||
<div> | ||
<div> | ||
{name} | ||
</div> | ||
<div> | ||
{city} | ||
</div> | ||
<div> | ||
{profile} | ||
</div> | ||
<img src={imageUrl} alt={name}/> | ||
</div> | ||
); | ||
}; | ||
|
||
const FacebookPage = () => { | ||
const [profiles, setProfiles] = React.useState([]); | ||
React.useEffect(async () => { | ||
const profiles = await db.collection("profiles") | ||
.get() | ||
.then(querySnapshot => { | ||
return querySnapshot.docs.map(doc => doc.data()); | ||
|
||
}); | ||
setProfiles(profiles); | ||
}, []); | ||
return (<div> | ||
{profiles.map(p => <ProfileBox {...p}/>)} | ||
</div>); | ||
}; | ||
|
||
export default FacebookPage; |
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,58 @@ | ||
import React from 'react'; | ||
import Button from 'react-bootstrap/Button'; | ||
import Form from 'react-bootstrap/Form'; | ||
import db from './firebase'; | ||
import firebase from 'firebase'; | ||
|
||
const SignUpPage = () => { | ||
// Check if user is logged in. | ||
// https://firebase.google.com/docs/auth/web/manage-users | ||
const [user, setUser] = React.useState(firebase.auth().currentUser); | ||
const [profile, setProfile] = React.useState(''); | ||
const [city, setCity] = React.useState(''); | ||
|
||
const handleGoogleAuthClick = () => { | ||
const provider = new firebase.auth.GoogleAuthProvider(); | ||
firebase.auth().signInWithPopup(provider).then(function(result) { | ||
const token = result.credential.accessToken; | ||
const user = result.user; | ||
setUser(user); | ||
}).catch(function(error) { | ||
if (error) { | ||
alert(JSON.stringify(error)); | ||
} | ||
}); | ||
} | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
await db.collection("profiles").doc(user.uid).set({ | ||
userId: user.uid, | ||
name: user.displayName, | ||
profile: profile, | ||
city: city, | ||
imageUrl: user.photoURL, | ||
}); | ||
|
||
alert('Submitted!'); | ||
}; | ||
|
||
return (<div> | ||
<Form> | ||
<Form.Group> | ||
{!user && (<div onClick={handleGoogleAuthClick} style={{cursor: 'pointer'}}> | ||
<img src={require('./google-signin.png')} /> | ||
</div> | ||
)} | ||
{user && (<div>You're logged in as {user.email}</div>)} | ||
<Form.Control placeholder="Profile" onChange={(e) => setProfile(e.target.value)}/> | ||
<Form.Control placeholder="City" onChange={(e) => setCity(e.target.value)}/> | ||
<Button variant="primary" type="submit" onClick={handleSubmit}> | ||
Submit | ||
</Button> | ||
</Form.Group> | ||
</Form> | ||
</div>); | ||
}; | ||
|
||
export default SignUpPage; |
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,18 @@ | ||
import firebase from 'firebase'; | ||
|
||
// Your web app's Firebase configuration | ||
var firebaseConfig = { | ||
apiKey: "AIzaSyDPFwcO5W4cSdCIBU4zYSWd2Hsi52CLNQs", | ||
authDomain: "recodedfacebook.firebaseapp.com", | ||
databaseURL: "https://recodedfacebook.firebaseio.com", | ||
projectId: "recodedfacebook", | ||
storageBucket: "recodedfacebook.appspot.com", | ||
messagingSenderId: "792119652578", | ||
appId: "1:792119652578:web:6f456d9c56b5bf6c876ebb" | ||
}; | ||
|
||
// Initialize Firebase | ||
const firebaseApp = firebase.initializeApp(firebaseConfig); | ||
const db = firebaseApp.firestore(); | ||
|
||
export default db; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.