diff --git a/mini-sns/components/AppConatiner.js b/mini-sns/components/AppConatiner.js index bdd3ef7..68537df 100644 --- a/mini-sns/components/AppConatiner.js +++ b/mini-sns/components/AppConatiner.js @@ -12,13 +12,16 @@ class AppContainer extends React.Component { } componentDidMount() { - firebaseApp.auth().getRedirectResult().then(function(result) { + firebaseApp.auth().getRedirectResult().then((result) => { if (result.credential) { // This gives you a Google Access Token. var token = result.credential.accessToken; } var user = result.user; console.log( 'getRedirectResult', user ); + this.props.context.update( { + user, + } ); }); firebaseApp.auth().onAuthStateChanged((user) => { if (user) { @@ -28,11 +31,14 @@ class AppContainer extends React.Component { // ... if( user.providerData.length ) { console.log( 'user', user ); + this.props.context.update( { + user, + } ); } else { console.log( 'anonymous user', user ); this.props.context.update( { - user, + anonymous: user, } ); } } else { diff --git a/mini-sns/components/FeedForm.js b/mini-sns/components/FeedForm.js index 7397524..c6aef59 100644 --- a/mini-sns/components/FeedForm.js +++ b/mini-sns/components/FeedForm.js @@ -1,10 +1,13 @@ import React from 'react'; import axios from 'axios'; +import { withAppContext } from '../contexts/AppContext'; -export default () => { +let FeedForm = props => { const [ content, setContent ] = React.useState(''); const submit = () => { axios.post('/api/feeds', { + displayName: props.context.user.displayName, + avatar: props.context.user.photoURL, content, } ) .then( () => { @@ -31,4 +34,8 @@ export default () => { ) -} \ No newline at end of file +} + +FeedForm = withAppContext(FeedForm); + +export default FeedForm; \ No newline at end of file diff --git a/mini-sns/components/nav.js b/mini-sns/components/nav.js index 60569fe..1e0a01f 100644 --- a/mini-sns/components/nav.js +++ b/mini-sns/components/nav.js @@ -1,56 +1,70 @@ import React from 'react' import Link from 'next/link' +import firebase from 'firebase'; +import firebaseApp from '../firebase/firebaseApp'; +import { withAppContext } from '../contexts/AppContext'; -const links = [ - { href: 'https://zeit.co/now', label: 'ZEIT' }, - { href: 'https://github.com/zeit/next.js', label: 'GitHub' } -].map(link => { - link.key = `nav-link-${link.href}-${link.label}` - return link -}) - -const Nav = () => ( - + ) +} - - -) +Nav = withAppContext( Nav ); export default Nav diff --git a/mini-sns/contexts/AppContext.js b/mini-sns/contexts/AppContext.js index 209f6c9..6a46aef 100644 --- a/mini-sns/contexts/AppContext.js +++ b/mini-sns/contexts/AppContext.js @@ -11,6 +11,7 @@ class AppProvider extends Component { // 글로벌 데이터 key: 'value', user: null, + anonymous: null, // update update: (state, callback) => { this.setState(state, callback); diff --git a/mini-sns/pages/_app.js b/mini-sns/pages/_app.js index 205f6fe..770a28c 100644 --- a/mini-sns/pages/_app.js +++ b/mini-sns/pages/_app.js @@ -27,13 +27,6 @@ class MyApp extends App { return
-
-
- - 피드 목록 - -
-
diff --git a/mini-sns/pages/feed.js b/mini-sns/pages/feed.js index d55fb98..270798f 100644 --- a/mini-sns/pages/feed.js +++ b/mini-sns/pages/feed.js @@ -2,6 +2,8 @@ import React from 'react'; import { useRouter } from 'next/router'; import firebaseApp from '../firebase/firebaseApp'; import { withAppContext } from '../contexts/AppContext'; +import Nav from '../components/nav'; +import Head from 'next/head'; const db = firebaseApp.firestore(); @@ -10,7 +12,27 @@ let Feed = ( props ) => { const id = router.query.id; return ( <> - { props.data.content } + + { props.data.displayName }님의 피드 + + + + + + + +