Pulled and merged the latest code from master

This commit is contained in:
Aaron Sun
2019-10-29 14:02:56 -04:00
22 changed files with 441 additions and 119 deletions

View File

@@ -61,6 +61,14 @@
}
}
},
"@material-ui/icons": {
"version": "4.5.1",
"resolved": "https://registry.npmjs.org/@material-ui/icons/-/icons-4.5.1.tgz",
"integrity": "sha512-YZ/BgJbXX4a0gOuKWb30mBaHaoXRqPanlePam83JQPZ/y4kl+3aW0Wv9tlR70hB5EGAkEJGW5m4ktJwMgxQAeA==",
"requires": {
"@babel/runtime": "^7.4.4"
}
},
"@material-ui/styles": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/@material-ui/styles/-/styles-4.5.0.tgz",
@@ -9717,6 +9725,11 @@
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
},
"typeface-roboto": {
"version": "0.0.75",
"resolved": "https://registry.npmjs.org/typeface-roboto/-/typeface-roboto-0.0.75.tgz",
"integrity": "sha512-VrR/IiH00Z1tFP4vDGfwZ1esNqTiDMchBEXYY9kilT6wRGgFoCAlgkEUMHb1E3mB0FsfZhv756IF0+R+SFPfdg=="
},
"uglify-js": {
"version": "3.4.10",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.10.tgz",

View File

@@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"@material-ui/core": "^4.4.3",
"@material-ui/icons": "^4.5.1",
"@material-ui/styles": "^4.5.0",
"@material-ui/system": "^4.5.0",
"axios": "^0.19.0",
@@ -18,7 +19,8 @@
"react-router-dom": "^5.1.0",
"react-scripts": "0.9.5",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0"
"redux-thunk": "^2.3.0",
"typeface-roboto": "0.0.75"
},
"devDependencies": {},
"scripts": {

View File

@@ -19,6 +19,8 @@ import { logoutUser, getUserData } from './redux/actions/userActions';
// Components
import AuthRoute from "./util/AuthRoute";
// axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api';
// Pages
import home from './pages/Home';
import signup from './pages/Signup';
@@ -34,14 +36,20 @@ const theme = createMuiTheme(themeObject);
const token = localStorage.FBIdToken;
if (token) {
const decodedToken = jwtDecode(token);
if (decodedToken.exp * 1000 < Date.now()) {
store.dispatch(logoutUser);
try {
const decodedToken = jwtDecode(token);
if (decodedToken.exp * 1000 < Date.now()) {
store.dispatch(logoutUser());
window.location.href = "/login";
} else {
store.dispatch({ type: SET_AUTHENTICATED });
axios.defaults.headers.common['Authorization'] = token;
store.dispatch(getUserData());
}
} catch (invalidTokenError) {
store.dispatch(logoutUser());
window.location.href = "/login";
} else {
store.dispatch({ type: SET_AUTHENTICATED });
axios.defaults.headers.common['Authorization'] = token;
store.dispatch(getUserData());
}
}

View File

@@ -35,8 +35,7 @@ class Writing_Microblogs extends Component {
handleSubmit(event) {
const postData = {
body: this.state.value,
body: this.state.value,
userImage: "bing-url",
microBlogTitle: this.state.title,
microBlogTopics: this.state.topics.split(', ')
@@ -46,7 +45,7 @@ class Writing_Microblogs extends Component {
}
axios
.post('/putPost', postData, headers)
.post("/putPost", postData, headers)
.then((res) =>{
alert('Post was shared successfully!')
console.log(res.data);

View File

@@ -10,6 +10,7 @@ import Button from '@material-ui/core/Button';
import withStyles from "@material-ui/core/styles/withStyles";
// Redux stuff
// import { logoutUser } from '../../redux/actions/userActions';
import { connect } from 'react-redux';
const styles = {
@@ -29,7 +30,7 @@ const styles = {
progress: {
position: "absolute"
}
};
};
export class Navbar extends Component {
render() {
@@ -62,6 +63,8 @@ const mapStateToProps = (state) => ({
user: state.user
})
// const mapActionsToProps = { logoutUser };
Navbar.propTypes = {
user: PropTypes.object.isRequired,
classes: PropTypes.object.isRequired

View File

@@ -0,0 +1,48 @@
import React, { Component, Fragment } from "react";
import PropTypes from "prop-types";
import axios from "axios";
import { connect } from 'react-redux';
//MUI
import withStyles from "@material-ui/core/styles/withStyles";
import Card from "@material-ui/core/CardMedia";
import Typography from "@material-ui/core/Typography";
import Button from "@material-ui/core/Button";
import { Paper } from "@material-ui/core";
const styles = theme => ({
...theme
});
class Profile extends Component {
state = {
profile: null
};
componentDidMount() {
axios
.get("/user")
.then(res => {
console.log(res.data.userData.credentials.handle);
this.setState({
profile: res.data.userData.credentials.handle
});
})
.catch(err => console.log(err));
}
render() {
let profileMarkup = this.state.profile ? (
<p>
<Typography variant='h5'>{this.state.profile}</Typography>
</p>) : <p>loading profile...</p>
return profileMarkup;
}
}
const mapStateToProps = state => ({
user: state.user,
classes: PropTypes.object.isRequired
});
export default connect(mapStateToProps)(withStyles(styles)(Profile));

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

@@ -88,6 +88,14 @@ export class edit extends Component {
handle: this.state.handle,
bio: this.state.bio
};
// Removes all keys from newProfileData that are empty, undefined, or null
Object.keys(newProfileData).forEach(key => {
if (newProfileData[key] === "" || newProfileData[key] === undefined || newProfileData[key] === null) {
delete newProfileData[key];
}
})
axios
.post("/updateProfileInfo", newProfileData)
.then((res) => {

View File

@@ -1,49 +1,124 @@
/* eslint-disable */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import axios from 'axios';
//import '../App.css';
import { makeStyles, styled } from '@material-ui/core/styles';
import Grid from '@material-ui/core/Grid';
import Card from '@material-ui/core/Card';
import CardMedia from '@material-ui/core/CardMedia';
import CardContent from '@material-ui/core/CardContent';
import Chip from '@material-ui/core/Chip';
import Paper from '@material-ui/core/Paper';
import Typography from "@material-ui/core/Typography";
import AddCircle from '@material-ui/icons/AddCircle';
import TextField from '@material-ui/core/TextField';
// component
import Userline from '../Userline';
import noImage from '../images/no-img.png';
const PostCard = styled(Card)({
background: 'linear-gradient(45deg, #1da1f2 90%)',
border: 3,
borderRadius: 3,
height:325,
width: 345,
padding: '0 30px',
const MyChip = styled(Chip)({
margin: 2,
color: 'primary'
});
class user extends Component {
componentDidMount(){
//TODO: get user details
//TODO: get posts
class user extends Component {
state = {
profile: null,
imageUrl: null,
topics: null,
newTopic: null
};
handleDelete = (topic) => {
alert(`Delete topic: ${topic}!`);
}
handleAddCircle = () => {
axios.post('/putTopic', {
topic: this.state.newTopic
})
.then(function () {
location.reload();
})
.catch(function (err) {
console.log(err);
});
}
handleChange(event) {
this.setState({
newTopic: event.target.value
})
}
componentDidMount() {
axios
.get("/user")
.then(res => {
this.setState({
profile: res.data.credentials.handle,
imageUrl: res.data.credentials.imageUrl
});
})
.catch(err => console.log(err));
axios
.get("/getAllTopics")
.then(res => {
this.setState({
topics: res.data
})
})
.catch(err => console.log(err));
}
render() {
const classes = this.props;
let profileMarkup = this.state.profile ? (
<p>
<Typography variant='h5'>{this.state.profile}</Typography>
</p>) : (<p>loading username...</p>);
let topicsMarkup = this.state.topics ? (
this.state.topics.map(topic => <MyChip
label={{topic}.topic.topic}
key={{topic}.topic.topicId}
onDelete={ (topic) => this.handleDelete(topic)}/>)
) : (<p> loading topics...</p>);
let imageMarkup = this.state.imageUrl ? (
<img
src={this.state.imageUrl}
height="250"
width="250"
/>
) : (<img src={noImage}/>);
return (
<Grid container spacing={16}>
<Grid item sm={8} xs={12}>
<p>Post</p>
</Grid>
<Grid item sm={4} xs={12}>
<PostCard>
<CardMedia image="./no-img-png" />
<CardContent>Username</CardContent>
</PostCard>
{imageMarkup}
{profileMarkup}
{topicsMarkup}
<TextField
id="newTopic"
label="new topic"
defaultValue=""
margin="normal"
variant="outlined"
value={this.state.newTopic}
onChange={ (event) => this.handleChange(event)}
/>
<AddCircle
color="primary"
clickable
onClick={this.handleAddCircle}
/>
</Grid>
</Grid>
);
}
}
export default user;

View File

@@ -50,7 +50,13 @@ export default {
marginBottom: 20
},
paper: {
padding: 20
padding: 10,
display: 'flex',
justifyContent: 'center',
flexWrap: 'wrap'
},
chip: {
margin: 0.5,
},
profile: {
'& .image-wrapper': {