Skip to content

Commit

Permalink
Dynamically Render Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
tupkung committed Sep 2, 2017
1 parent 37e23f9 commit 7f43eba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
18 changes: 17 additions & 1 deletion contacts/src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, {Component} from 'react'
import ListContacts from './ListContacts'
import * as ContactsAPI from './utils/ContactsAPI'
import CreateContact from './CreateContact'

class App extends Component {
state = {
screen: 'list', // list, create
contacts: []
}
removeContact = (contact) => {
Expand All @@ -23,7 +25,21 @@ class App extends Component {
render() {
return (
<div>
<ListContacts onDeleteContact={this.removeContact} contacts={this.state.contacts}/>
{this.state.screen === 'list' && (
<ListContacts
onDeleteContact={this.removeContact}
contacts={this.state.contacts}
onNavigate={()=>{
this.setState({ screen: 'create'})
}}
/>
)}

{this.state.screen === 'create' && (
<CreateContact />
)}


</div>
)
}
Expand Down
12 changes: 12 additions & 0 deletions contacts/src/CreateContact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React, { Component } from 'react'

class CreateContact extends Component {
render() {
return (
<div>Create Contact!</div>
)
}
}


export default CreateContact
8 changes: 7 additions & 1 deletion contacts/src/ListContacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ListContacts extends Component {
}

render() {
const {contacts, onDeleteContact} = this.props
const {contacts, onDeleteContact, onNavigate} = this.props
const {query} = this.state

let showingContacts
Expand All @@ -45,6 +45,12 @@ class ListContacts extends Component {
value={this.state.query}
onChange={(event) => this.updateQuery(event.target.value)}
/>

<a
href="#create"
onClick={onNavigate}
className="add-contact"
>Add Contact</a>
</div>
{showingContacts.length !== contacts.length && (
<div className='showing-contacts'>
Expand Down

0 comments on commit 7f43eba

Please sign in to comment.