Skip to content

Commit

Permalink
evening push
Browse files Browse the repository at this point in the history
  • Loading branch information
autumn-ragland committed Apr 23, 2019
1 parent 43c5ed1 commit 24c7bb1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 49 deletions.
17 changes: 10 additions & 7 deletions client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,37 @@

.profileImages{
display: grid;
grid-template-columns: 1fr 5fr;
grid-template-columns: 1fr 1fr;
margin: 0 10% 0 10%;
height: 5%;
}

.profile{
grid-column: 1;
height: 100%;
clip-path: circle(25% at center);
background: lightblue;
}

.background{
.background {
grid-column: 2;
width: 100%;
height: 100%;
}

.tweetGrid{
display: grid;
font-size: 25px;
grid-template-columns: 1fr 2fr;
grid-template-columns: 1fr 1fr;
margin: 1% 25% 1% 25%;
height: 5%;
width: 50%;
border: 1px solid blue;
background: rgba(211, 211, 211, 0.5);
border: 2px solid lightgray;
}

.tweetMessage{
grid-column: 2;
grid-row: 1;
padding: 1%;
font-size: 15px;
}

.tweetImage{
Expand Down
2 changes: 1 addition & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +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/>} />
<Route path={'/edit/:tweetID'} component={()=> <EditTweet/>} />
</Router>
);
}
Expand Down
16 changes: 6 additions & 10 deletions client/src/EditTweet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@ class EditTweet extends Component {
//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', {
fetch('/users/editTweet/:id', {
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,
tweetPublic:e.target.tweetPublic.checked,
})
})
.then(() => console.log('Tweet Added'))
.then(() => console.log('Tweet Updated'))
};

render() {
Expand All @@ -36,18 +32,18 @@ class EditTweet extends Component {
<form onSubmit={this.formSubmit}>
<div className={'formStyle'}>
<label htmlFor={'tweetMessage'}>Tweet Message: </label>
<input type="text" id={'tweetMessage'} name={'tweetMessage'}/>
<input type="text" id={'tweetMessage'} value={this.props.tweetMessage} name={'tweetMessage'}/>
</div>
<div className={'formStyle'}>
<label htmlFor={'tweetImage'}>Tweet Image URL: </label>
<input type="text" id={'tweetImage'} name={'tweetImage'}/>
<input type="text" id={'tweetImage'} value={this.props.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'}/>
<input type="submit" value={'edit tweet'}/>
</div>
</form>
</div>
Expand Down
4 changes: 2 additions & 2 deletions client/src/TwitterHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class TwitterHome extends Component {
return (
<div className="App">
<div>
<form>
<form className={'formStyle'}>
<label htmlFor={'searchBar'}>Search: </label>
<input type="text" name={'searchBar'} placeholder={'search all tweets'}/>
</form>
Expand All @@ -96,7 +96,7 @@ class TwitterHome extends Component {
return (
<div className="App">
<div>
<form>
<form className={'formStyle'}>
<label htmlFor={'searchBar'}>Search: </label>
<input type="text" name={'searchBar'} placeholder={'search all tweets'}/>
</form>
Expand Down
13 changes: 6 additions & 7 deletions client/src/TwitterProfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, {Component} from 'react';
import {BrowserRouter as Router, Link, Route} from 'react-router-dom';
import EditTweet from "./EditTweet";

class TwitterProfile extends Component {
constructor(props) {
super(props);
this.state = {
userData:'',
checkbox:false,
tweetArray:[]
tweetArray:[],
};
this.userFetch();
}
Expand Down Expand Up @@ -44,8 +44,10 @@ class TwitterProfile extends Component {
<div key={eachTweet._id} className={'tweetGrid'}>
<p className={'tweetMessage'}>{eachTweet.tweetMessage}</p>
<img className={'tweetImage'} src={eachTweet.tweetImage} alt=""/>
<Link to={'/edit'}>Edit</Link>
<Link to={'/edit/' + eachTweet._id}>Edit</Link>
</div>
<Route exact path={'/edit/' + eachTweet._id}
component={()=> <EditTweet tweetMessage={eachTweet.tweetMessage} tweetImage={eachTweet.tweetImage}/>}/>
</Router>
)
});
Expand All @@ -55,9 +57,6 @@ class TwitterProfile extends Component {

//add tweet form submission event handler
formSubmit = (e) => {
if (e.target.tweetPublic.value === 'on'){
this.setState({checkbox:true})
}
e.preventDefault();
fetch('/users/addTweet', {
method:'POST',
Expand All @@ -69,7 +68,7 @@ class TwitterProfile extends Component {
username:this.props.username,
tweetMessage:e.target.tweetMessage.value,
tweetImage:e.target.tweetImage.value,
tweetPublic:this.state.checkbox,
tweetPublic:e.target.tweetPublic.checked,
})
})
.then(()=>console.log('Tweet Added'))
Expand Down
44 changes: 27 additions & 17 deletions server/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,38 +116,48 @@ router.get('/loginFail', (req, res) => {
//add a tweet
router.post('/addTweet', (req, res) => {
TwitterUserCollection.findOneAndUpdate({username: req.body.username},
{$push: {tweets:req.body}}, (errors) => {
{$push: {tweets: req.body}}, (errors) => {
if (errors) res.send(errors);
else res.send("Tweet Added");
});
});

//edit a tweet by tweet ID
router.post('/editTweet/:id', (req, res) => {
TwitterUserCollection.findOneAndUpdate({tweets: {_id: req.params.id}}, req.body, (errors, results) => {
if (errors) res.send(errors);
else if (results) res.send('tweet found by id');
else res.send('tweet not found by id');
});
});

//get all tweets fixme
//results = user object array. Map array for each user THEN map each user for tweets
router.get('/grabTweets',(req,res)=> {
TwitterUserCollection.find({},(errors,results)=>{
if(errors) res.send(errors);
else{
res.send(results);
}
})
router.get('/grabTweets', (req, res) => {
TwitterUserCollection.find({}, (errors, results) => {
if (errors) res.send(errors);
else {
res.send(results);
}
})
});

//search tweets INCOMPLETE SEARCH BY USERNAME fixme
router.get('/searchTweets',(req,res)=> {
TwitterUserCollection.findOne({username:req.body.username},(errors,results)=>{
if(errors) res.send(errors);
else{
//INCOMPLETE SEARCH BY USERNAME fixme
//search tweets
router.get('/searchTweets', (req, res) => {
TwitterUserCollection.findOne({username: req.body.username}, (errors, results) => {
if (errors) res.send(errors);
else {
res.send(results)
}
})
});

//grab user
router.post('/searchUsers',(req,res)=> {
TwitterUserCollection.findOne({username:req.body.username},(errors,results)=>{
if(errors) res.send(errors);
else{
router.post('/searchUsers', (req, res) => {
TwitterUserCollection.findOne({username: req.body.username}, (errors, results) => {
if (errors) res.send(errors);
else {
res.send(results);
}
})
Expand Down
9 changes: 4 additions & 5 deletions wireframe.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# 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)
- edit tweets route
- look up mongoose queries to sort tweets by date:
UserCollection.find( ).sort( { field: value } )
- cookies?
- search tweets
- search tweets by tweet body
###Server:
- new user strategy and routes
- login strategy and routes
Expand Down

0 comments on commit 24c7bb1

Please sign in to comment.