diff --git a/inspiredblog/package-lock.json b/inspiredblog/package-lock.json index dc8d56e..164d502 100644 --- a/inspiredblog/package-lock.json +++ b/inspiredblog/package-lock.json @@ -3998,14 +3998,14 @@ } }, "for-editor-herb": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/for-editor-herb/-/for-editor-herb-1.1.0.tgz", - "integrity": "sha512-38SG+zSxVKq8ZoUHwB0DPbtkUqRKa/3XTUJdao253Ys5aQToUbfqcG7km7pMt3IYLp+ljHGvBix7dO2my+TGgQ==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/for-editor-herb/-/for-editor-herb-1.5.0.tgz", + "integrity": "sha512-D8qhAYe87gyV+ktjdP3Z5zYkeQj+jvJZx00s1h2snhzb5vqVtWIfsAKgF5KZQywhMe0a9e36KFPgI0fOHujvnQ==", "requires": { "highlight.js": "^9.13.1", "katex": "^0.11.1", - "marked": "^0.6.2", - "mermaid": "^8.4.7" + "marked": "^0.8.2", + "mermaid": "^8.4.8" } }, "for-in": { @@ -5841,9 +5841,9 @@ "integrity": "sha512-8z4efJYk43E0upd0NbVXwgSTQs6cT3T06etieCMEg7dRbzCbxUCK/GHlX8mhHRDcp+OLlHkPKsvqQTCvsRl2cg==" }, "marked": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/marked/-/marked-0.6.3.tgz", - "integrity": "sha512-Fqa7eq+UaxfMriqzYLayfqAE40WN03jf+zHjT18/uXNuzjq3TY0XTbrAoPeqSJrAmPz11VuUA+kBPYOhHt9oOQ==" + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/marked/-/marked-0.8.2.tgz", + "integrity": "sha512-EGwzEeCcLniFX51DhTpmTom+dSA/MG/OBUDjnWtHbEnjAH180VzUeAw+oE4+Zv+CoYBWyRlYOTR0N8SO9R1PVw==" }, "md5.js": { "version": "1.3.5", diff --git a/inspiredblog/package.json b/inspiredblog/package.json index 9ba047a..4722459 100644 --- a/inspiredblog/package.json +++ b/inspiredblog/package.json @@ -40,7 +40,7 @@ "draft-js": "^0.11.4", "draft-js-image-plugin": "^2.0.7", "draft-js-plugins-editor": "^3.0.0", - "for-editor-herb": "^1.1.0", + "for-editor-herb": "^1.5.0", "react": "^16.12.0", "react-dom": "^16.12.0", "react-markdown": "^4.3.1", diff --git a/inspiredblog/src/pages/.DS_Store b/inspiredblog/src/pages/.DS_Store new file mode 100644 index 0000000..a64b05b Binary files /dev/null and b/inspiredblog/src/pages/.DS_Store differ diff --git a/inspiredblog/src/pages/index.html b/inspiredblog/src/pages/index.html index bf3fce5..e8e780f 100644 --- a/inspiredblog/src/pages/index.html +++ b/inspiredblog/src/pages/index.html @@ -7,6 +7,7 @@ + My Story diff --git a/inspiredblog/src/pages/index/.DS_Store b/inspiredblog/src/pages/index/.DS_Store new file mode 100644 index 0000000..773aa72 Binary files /dev/null and b/inspiredblog/src/pages/index/.DS_Store differ diff --git a/inspiredblog/src/pages/index/App.js b/inspiredblog/src/pages/index/App.js index e12d7ea..a32d8eb 100644 --- a/inspiredblog/src/pages/index/App.js +++ b/inspiredblog/src/pages/index/App.js @@ -29,6 +29,7 @@ import MailIcon from '@material-ui/icons/Mail'; import ClassIcon from '@material-ui/icons/Class'; import HomeIcon from '@material-ui/icons/Home'; import BookIcon from '@material-ui/icons/Book'; +import AccountBoxIcon from '@material-ui/icons/AccountBox'; import profile from './img/profile.png'; import DescriptionIcon from '@material-ui/icons/Description'; import Particles from 'react-particles-js'; @@ -185,6 +186,10 @@ const App = (props) => { + history.push(`/blogs/profile/${localStorage.getItem('userId')}`)}> + + + history.push('/blogs/login')} style={{display: checkAuthState()?'none':''}}> @@ -220,7 +225,7 @@ const App = (props) => { - + @@ -293,7 +298,7 @@ const App = (props) => { account_box - Your Profile + Your Profile
diff --git a/inspiredblog/src/pages/index/components/Profile.js b/inspiredblog/src/pages/index/components/Profile.js index 08862d9..b678346 100644 --- a/inspiredblog/src/pages/index/components/Profile.js +++ b/inspiredblog/src/pages/index/components/Profile.js @@ -1,38 +1,177 @@ import React, { Component , useEffect, useState } from 'react' import {Redirect, useHistory} from 'react-router-dom'; import {connect} from 'react-redux'; -import TextField from '@material-ui/core/TextField'; +// import TextField from '@material-ui/core/TextField'; import Button from '@material-ui/core/Button'; import { makeStyles } from '@material-ui/core/styles'; - +import profile from '../img/profile.png'; +import format from 'date-fns/format'; +// import DateRangeIcon from '@material-ui/icons/DateRange'; +// import calendarImg from '../img/calendar.jpg'; const useStyles = makeStyles(theme => ({ - + outerDiv:{ + display:'flex', + flexDirection:'column', + width: '100%', + alignItems:'center' + }, + header: { + width:'100%', + backgroundColor: 'rgb(197,208,216)', + height: '160px', + }, + secondBanner: { + position: 'relative', + width: '95%', + display: 'flex', + justifyContent: 'flex-end', + margin: '10px 0' + }, + edit:{ + width:'20%', + '@media(max-width:1100px)':{ + width:'23%' + }, + '@media(max-width:800px)':{ + width:'25%' + }, + '@media(max-width:600px)':{ + width:'28%' + }, + }, + outlinedPrimary: { + color: 'rgb(26,151,240)', + border: '1px solid rgb(26,151,240)', + '&:hover': { + backgroundColor: 'rgb(202,215,241)' + }, + }, + buttonRoot: { + borderRadius:'20px', + textTransform:'none', + }, + imgHref: { + display: 'block', + width: '130px', + height: '130px', + padding: '5px', + position: 'absolute', + top: '-75px', + left: '0px', + backgroundColor:'white', + padding: '5px', + borderRadius: '50%', + }, + photo: { + width: '120px', + borderRadius: '50%', + }, + thirdBanner: { + width:'95%', + display: 'flex', + flexDirection:'column', + alignItems:'flex-start', + marginTop: '20px', + }, + publicInfo: { + width:'95%', + textAlign: 'left', + margin:'5px 0', + }, + email: { + width: '95%', + color: 'rgb(101,119,134)', + margin:'5px 0', + }, + dateJoined: { + width: '95%', + color: 'rgb(101,119,134)', + margin:'5px 0', + }, + follow: { + margin:'5px 0', + width: '95%', + }, + switch: { + width:'100%', + display:'flex', + borderBottom:'1px solid lightgray' + }, + switchButton:{ + color: 'rgb(101,119,134)', + padding: '10px 0', + textAlign: 'center', + width:'50%', + transitionDuration: '0.5s', + '&:hover': { + borderBottom: '2px solid rgba(29,161,242,1.00)', + background: 'lightblue', + color: 'rgba(29,161,242,1.00)', + }, + }, + activeSwitchButton: { + padding: '10px 0', + textAlign: 'center', + width:'50%', + transitionDuration: '0.5s', + color: 'rgba(29,161,242,1.00)', + borderBottom: '2px solid rgba(29,161,242,1.00)', + '&:hover': { + background: 'lightblue', + }, + } })); const Profile = (props) => { const classes = useStyles(); let history = useHistory(); - const [username, setUsername] = useState(''); + // const [username, setUsername] = useState(''); useEffect(()=>{ - setUsername(localStorage.getItem('username')); - },[props.auth.username]) + props.getProfile(props.match.params.targetId); + },[]) return ( -
-
- Username: - setUsername(e.target.value)} - id="username" - // label="Username" - /> +
+
+ +
+
+ + profile + +
+ +
+
+
+
{props.profile.username}
+ {props.profile.email?
{props.profile.email}
:''} + {props.profile.publicInfo?
{props.profile.publicInfo}
:''} +
+ Joined {format(new Date(props.profile.dateJoined), 'MMMM yyyy')} +
+
+ {'193 following 0 followers'} +
+
+
+
props.switchShowing('posts')}>Posts
+
props.switchShowing('likes')}>Likes
- + {props.profile.showing=='posts'? +
+ {props.profile.myBlogs.map(b=> +
{b.blog_title} - published on {format(new Date(b.created_on), 'MM/dd/yyyy')}
)} +
:''} + {props.profile.showing=='likes'? +
+ +
:''}
) @@ -41,13 +180,14 @@ const Profile = (props) => { const mapStateToProps = (state)=>{ return { auth: state.auth, + profile: state.profile, } } const mapDispatchToProps = (dispatch)=>{ return { - onSignIn :(email,password)=> dispatch({type: 'SIGN_IN', data: {email, password}}), + getProfile: (targetId)=> dispatch({type: 'GET_PROFILE', value: targetId}), + switchShowing: (type)=> dispatch({type: 'switch_showing', value: type}), updateProfile: (username) => dispatch({type: 'UPDATE_PROFILE', payload: username}) - // onSignUp :()=> dispatch({type: 'SIGN_UP'}), } } export default connect(mapStateToProps,mapDispatchToProps)(Profile) \ No newline at end of file diff --git a/inspiredblog/src/pages/index/components/blogs/BlogDetail.js b/inspiredblog/src/pages/index/components/blogs/BlogDetail.js index 989d1fd..0ca30d4 100644 --- a/inspiredblog/src/pages/index/components/blogs/BlogDetail.js +++ b/inspiredblog/src/pages/index/components/blogs/BlogDetail.js @@ -217,7 +217,7 @@ const BlogDetail = (props) => { arrow_back_ios
-
+
Edit
{props.blog.blogDetail.blog_title}
diff --git a/inspiredblog/src/pages/index/components/blogs/Blogs.js b/inspiredblog/src/pages/index/components/blogs/Blogs.js index 77a1a56..950ff5e 100644 --- a/inspiredblog/src/pages/index/components/blogs/Blogs.js +++ b/inspiredblog/src/pages/index/components/blogs/Blogs.js @@ -71,7 +71,7 @@ const useStyles = makeStyles(theme => ({ '&:hover': { color:'white', backgroundColor:'black' - }, + }, } })); diff --git a/inspiredblog/src/pages/index/img/.DS_Store b/inspiredblog/src/pages/index/img/.DS_Store new file mode 100644 index 0000000..efdca02 Binary files /dev/null and b/inspiredblog/src/pages/index/img/.DS_Store differ diff --git a/inspiredblog/src/pages/index/img/calendar.jpg b/inspiredblog/src/pages/index/img/calendar.jpg new file mode 100644 index 0000000..a9001c3 Binary files /dev/null and b/inspiredblog/src/pages/index/img/calendar.jpg differ diff --git a/inspiredblog/src/pages/index/reducers/index.js b/inspiredblog/src/pages/index/reducers/index.js index 4433492..4751d6f 100644 --- a/inspiredblog/src/pages/index/reducers/index.js +++ b/inspiredblog/src/pages/index/reducers/index.js @@ -3,6 +3,7 @@ import aboutReducer from './aboutReducer'; import sitesReducer from './sitesReducer'; import authReducer from './authReducer'; import blogReducer from './blogReducer'; +import profileReducer from './profileReducer'; const rootReducer = combineReducers( { @@ -10,6 +11,7 @@ const rootReducer = combineReducers( sites: sitesReducer, auth: authReducer, blog: blogReducer, + profile: profileReducer, }); export default rootReducer; diff --git a/inspiredblog/src/pages/index/reducers/profileReducer.js b/inspiredblog/src/pages/index/reducers/profileReducer.js new file mode 100644 index 0000000..097647d --- /dev/null +++ b/inspiredblog/src/pages/index/reducers/profileReducer.js @@ -0,0 +1,38 @@ +const initialState = { + username: null, + email: null, + dateJoined: new Date(), + publicInfo: null, + following: 0, + follower: 0, + myBlogs: [], + isSelf: false, + showing: 'posts', // alternative: likes +} + +const profileReducer = (state=initialState, action) => { + + switch (action.type){ + case 'get_profile_success': + return { + ...state, + username: action.value.profileData.username, + email: action.value.profileData.email || null, + dateJoined: action.value.profileData.created_on, + publicInfo: action.value.profileData.public_info, + isSelf: action.value.isSelf, + myBlogs: action.value.blogsData, + // follower: action.data.follower, + // following: action.data.following, + } + case 'switch_showing': + return { + ...state, + showing: action.value, + } + default: + return state + } +} + +export default profileReducer; \ No newline at end of file diff --git a/inspiredblog/src/pages/index/sagas/auth.js b/inspiredblog/src/pages/index/sagas/auth.js index b3923de..b8f1daf 100644 --- a/inspiredblog/src/pages/index/sagas/auth.js +++ b/inspiredblog/src/pages/index/sagas/auth.js @@ -51,6 +51,7 @@ export function* signinSaga(action){ yield localStorage.setItem('email',res.data.email); yield localStorage.setItem('token',res.data.token); yield localStorage.setItem('isAdmin',res.data.isAdmin); + yield localStorage.setItem('userId',res.data.userId); yield localStorage.setItem('expirationTime', new Date(res.data.expirationTime)); yield put({ type: 'signin_success', diff --git a/inspiredblog/src/pages/index/sagas/index.js b/inspiredblog/src/pages/index/sagas/index.js index 370d97b..e7549b4 100644 --- a/inspiredblog/src/pages/index/sagas/index.js +++ b/inspiredblog/src/pages/index/sagas/index.js @@ -2,12 +2,14 @@ import { all, fork } from 'redux-saga/effects'; import { watchIncreaseCounter} from './aboutSaga'; import {watchAuth} from './auth'; import {watchBlogs} from './blog'; +import {watchProfile} from './profile'; export function* rootSaga(){ yield all([ // fork(watchIncreaseCounter), watchIncreaseCounter(), watchAuth(), watchBlogs(), + watchProfile(), ]) // yield all([ // helloSaga(), diff --git a/inspiredblog/src/pages/index/sagas/profile.js b/inspiredblog/src/pages/index/sagas/profile.js new file mode 100644 index 0000000..87c9c32 --- /dev/null +++ b/inspiredblog/src/pages/index/sagas/profile.js @@ -0,0 +1,27 @@ +import { takeLatest, call, put, select } from 'redux-saga/effects'; +import axios from 'axios'; + +const host = process.env.NODE_ENV === "production"?'':'http://localhost:5000'; + +function* getProfile(action){ + let header = { + headers: { + Authorization: 'Bearer ' + localStorage.getItem('token') + } + } + try { + const result = yield axios.get(host + `/api/profile/getProfile/${action.value}`, header); + yield put({ + type: 'get_profile_success', + value: result.data, + }) + } + catch(err){ + console.log(err.response); + alert(err.response.data.message); + } +} + +export function* watchProfile(){ + yield takeLatest('GET_PROFILE', getProfile); +} \ No newline at end of file