Skip to content

Commit

Permalink
afternoon update
Browse files Browse the repository at this point in the history
  • Loading branch information
autumn-ragland committed Apr 22, 2019
1 parent a6c73cf commit 43c5ed1
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 22 deletions.
16 changes: 13 additions & 3 deletions client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,28 @@

.tweetGrid{
display: grid;
grid-template-columns: 1fr 1fr;
margin: 0 10% 0 10%;
font-size: 25px;
grid-template-columns: 1fr 2fr;
margin: 1% 25% 1% 25%;
height: 5%;
border: 1px solid black;
width: 50%;
border: 1px solid blue;
}

.tweetMessage{
grid-column: 2;
grid-row: 1;
}

.tweetImage{
grid-column: 1;
grid-row: 1;
width: 25%;
padding: 5%;
}
.editButton{
grid-column: 2;
grid-row: 2;
width: 25%;
margin: 5%;
}
2 changes: 2 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import TwitterHome from "./TwitterHome";
import TwitterRegistration from "./TwitterRegistration";
import TwitterProfile from "./TwitterProfile";
import TwitterLogout from "./TwitterLogout";
import EditTweet from "./EditTweet";

class App extends Component {

Expand Down Expand Up @@ -39,6 +40,7 @@ class App extends Component {
<Route path={'/register'} component={() => <TwitterRegistration userInfo={this.userInfo} />} />
<Route path={'/profile'} component={() => <TwitterProfile username={this.state.username} isLoggedIn={this.state.isLoggedIn}/>} />
<Route path={'/logout'} component={()=> <TwitterLogout/>} />
<Route path={'/edit'} component={()=> <EditTweet/>} />
</Router>
);
}
Expand Down
57 changes: 57 additions & 0 deletions client/src/EditTweet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, {Component} from 'react';

class EditTweet extends Component {
constructor(props) {
super(props);
this.state = {}
}

//fixme INCOMPLETE
//edit tweet form submission event handler
formSubmit = (e) => {
if (e.target.tweetPublic.value === 'on') {
this.setState({checkbox: true})
}
e.preventDefault();
fetch('/users/addTweet', {
method: 'POST',
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
username: this.props.username,
tweetMessage: e.target.tweetMessage.value,
tweetImage: e.target.tweetImage.value,
tweetPublic: this.state.checkbox,
})
})
.then(() => console.log('Tweet Added'))
};

render() {
return (
<div>
<h2>Edit Tweet</h2>
<form onSubmit={this.formSubmit}>
<div className={'formStyle'}>
<label htmlFor={'tweetMessage'}>Tweet Message: </label>
<input type="text" id={'tweetMessage'} name={'tweetMessage'}/>
</div>
<div className={'formStyle'}>
<label htmlFor={'tweetImage'}>Tweet Image URL: </label>
<input type="text" id={'tweetImage'} name={'tweetImage'}/>
</div>
<div className={'formStyle'}>
<label htmlFor={'tweetPublic'}>Public Tweet: </label>
<input type="checkbox" name={'tweetPublic'}/>
</div>
<div className={'formStyle'}>
<input type="submit" value={'add tweet'}/>
</div>
</form>
</div>
);
}
}
export default EditTweet
79 changes: 69 additions & 10 deletions client/src/TwitterHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import React, {Component} from 'react';

class TwitterHome extends Component {

constructor(props) {
super(props);
this.state = {
userObject: [],
tweetArray:[],
anotherMap:[],
theFinalMap:[],
};
this.tweetFetch()
}

//form submission event handler
formSubmit = (e) => {
e.preventDefault();
Expand All @@ -20,30 +31,77 @@ class TwitterHome extends Component {
.then((data) => {
if (data) {
this.props.userInfo(data, true)
}
else{
this.props.userInfo(null,false)
} else {
this.props.userInfo(null, false);
}
})
};

//grab user objects
tweetFetch = () => {
fetch('/users/grabTweets')
.then(data => data.json())
.then(returnedData => this.setState({userObject: returnedData}))
.then(() => this.mapAllTweets())

};

//map tweets from user object
mapAllTweets = () => {
let mappedUsers = this.state.userObject.map((eachUser) => {
return (
eachUser.tweets
)
});
for(let i=0; i<mappedUsers.length; i++){
let mappedTweets = mappedUsers[i].map((eachTweet)=>{
return(this.state.anotherMap.push(eachTweet))
});
this.setState({tweetArray:mappedTweets})
}
this.mapTweetsAgain()
};

mapTweetsAgain = () => {
let finalMap = this.state.anotherMap.map((eachTweet)=>{
return(
<div key={eachTweet._id} className={'tweetGrid'}>
<p className={'tweetMessage'}>{eachTweet.tweetMessage}</p>
<img className={'tweetImage'} src={eachTweet.tweetImage} alt=""/>
</div>
)
});
this.setState({theFinalMap:finalMap})
};

render() {
//logged in user display
if (this.props.isLoggedIn === true) {
console.log('Client Check: Logged in');
return (
<div className="App">
<h1>Mock Twitter</h1>
<h3>Five Latest Tweets</h3>
<div>
<form>
<label htmlFor={'searchBar'}>Search: </label>
<input type="text" name={'searchBar'} placeholder={'search all tweets'}/>
</form>
</div>
<h3>Tweets: </h3>
<hr/>
{this.state.theFinalMap}
</div>
);
}
//not logged in user display
else {
console.log('Client Check: Not logged in');
return (
<div className="App">
<h1>Mock Twitter Sign In</h1>
<div>
<form>
<label htmlFor={'searchBar'}>Search: </label>
<input type="text" name={'searchBar'} placeholder={'search all tweets'}/>
</form>
</div>
<h3>Sign In</h3>
<form onSubmit={this.formSubmit}>
<div className={'formStyle'}>
<label htmlFor={'username'}>Username: </label>
Expand All @@ -57,11 +115,12 @@ class TwitterHome extends Component {
<input type="submit" value={'sign in'}/>
</div>
</form>
<h3>Tweets: </h3>
<hr/>
{this.state.theFinalMap}
</div>
);
}


}
}

Expand Down
17 changes: 10 additions & 7 deletions client/src/TwitterProfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {Component} from 'react';
import {BrowserRouter as Router, Link, Route} from 'react-router-dom';

class TwitterProfile extends Component {
constructor(props) {
Expand Down Expand Up @@ -33,15 +34,19 @@ class TwitterProfile extends Component {
}
};

// fixme INCOMPLETE
//list tweets
mapTweets = () => {
if (this.state.userData.tweets) {
console.log(this.state.userData.tweets);
let tweetMap = this.state.userData.tweets.map((eachTweet) => {
return (
<div key={eachTweet._id} className={'tweetGrid'}>
<p className={'tweetMessage'}>{eachTweet.tweetMessage}</p>
<img className={'tweetImage'} src={eachTweet.tweetImage} alt=""/>
</div>
<Router>
<div key={eachTweet._id} className={'tweetGrid'}>
<p className={'tweetMessage'}>{eachTweet.tweetMessage}</p>
<img className={'tweetImage'} src={eachTweet.tweetImage} alt=""/>
<Link to={'/edit'}>Edit</Link>
</div>
</Router>
)
});
this.setState({tweetArray:tweetMap})
Expand Down Expand Up @@ -70,8 +75,6 @@ class TwitterProfile extends Component {
.then(()=>console.log('Tweet Added'))
};



render() {
//logged in user
if (this.props.isLoggedIn === true) {
Expand Down
2 changes: 1 addition & 1 deletion server/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ router.get('/grabTweets',(req,res)=> {
TwitterUserCollection.find({},(errors,results)=>{
if(errors) res.send(errors);
else{
res.send(results)
res.send(results);
}
})
});
Expand Down
8 changes: 7 additions & 1 deletion wireframe.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# project3-mern Wireframe

###TODO:
- edit tweets
- look up mongoose queries to sort tweets by date
- add CSS to profile pages
- display all tweets on homepage (50% complete)
- cookies?
- search tweets
###Server:
- new user strategy and routes
- login strategy and routes
Expand Down

0 comments on commit 43c5ed1

Please sign in to comment.