Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part 5 #84

Open
wants to merge 23 commits into
base: PART_1_and_2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
prepare for part 4 youtube video
  • Loading branch information
adrianhajdin committed May 14, 2021
commit 988c855cc4dbb2f1714a85d9c4d8dabebe779379
26 changes: 26 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"dependencies": {
"@material-ui/core": "^4.9.10",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.58",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"jwt-decode": "^3.1.2",
"material-ui-chip-input": "^1.1.0",
"moment": "^2.27.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
Expand Down
2 changes: 2 additions & 0 deletions client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="icon" type="image/png" href="./memories.png">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Heebo:wght@300;400;700&display=swap" rel="stylesheet">
<title>Memories</title>
</head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React from 'react';
import { Container } from '@material-ui/core';
import { BrowserRouter, Switch, Route, Redirect } from 'react-router-dom';

import Home from './components/Home/Home';
import PostDetails from './components/PostDetails/PostDetails';
import Navbar from './components/Navbar/Navbar';
import Home from './components/Home/Home';
import Auth from './components/Auth/Auth';
import PostDetails from './components/PostDetails/PostDetails';

const App = () => {
const user = JSON.parse(localStorage.getItem('profile'));
Expand Down
3 changes: 1 addition & 2 deletions client/src/actions/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const getPost = (id) => async (dispatch) => {
const { data } = await api.fetchPost(id);

dispatch({ type: FETCH_POST, payload: { post: data } });
// dispatch({ type: END_LOADING });
} catch (error) {
console.log(error);
}
Expand Down Expand Up @@ -44,8 +43,8 @@ export const createPost = (post, history) => async (dispatch) => {
const { data } = await api.createPost(post);

dispatch({ type: CREATE, payload: data });

history.push(`/posts/${data._id}`);
// dispatch({ type: END_LOADING });
} catch (error) {
console.log(error);
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Auth/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const SignUp = () => {

return (
<Container component="main" maxWidth="xs">
<Paper className={classes.paper} elevation={3}>
<Paper className={classes.paper} elevation={6}>
<Avatar className={classes.avatar}>
<LockOutlinedIcon />
</Avatar>
Expand Down
5 changes: 2 additions & 3 deletions client/src/components/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Form = ({ currentId, setCurrentId }) => {

if (!user?.result?.name) {
return (
<Paper className={classes.paper}>
<Paper className={classes.paper} elevation={6}>
<Typography variant="h6" align="center">
Please Sign In to create your own memories and like other's memories.
</Typography>
Expand All @@ -49,7 +49,6 @@ const Form = ({ currentId, setCurrentId }) => {
}

const handleAddChip = (tag) => {
console.log(tag, postData.tags);
setPostData({ ...postData, tags: [...postData.tags, tag] });
};

Expand All @@ -58,7 +57,7 @@ const Form = ({ currentId, setCurrentId }) => {
};

return (
<Paper className={classes.paper}>
<Paper className={classes.paper} elevation={6}>
<form autoComplete="off" noValidate className={`${classes.root} ${classes.form}`} onSubmit={handleSubmit}>
<Typography variant="h6">{currentId ? `Editing "${post?.title}"` : 'Creating a Memory'}</Typography>
<TextField name="title" variant="outlined" label="Title" fullWidth value={postData.title} onChange={(e) => setPostData({ ...postData, title: e.target.value })} />
Expand Down
29 changes: 6 additions & 23 deletions client/src/components/Home/Home.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState, useEffect } from 'react';
import { Container, Grow, Grid, AppBar, TextField, Button, Paper, Chip } from '@material-ui/core';
import React, { useState } from 'react';
import { Container, Grow, Grid, AppBar, TextField, Button, Paper } from '@material-ui/core';
import { useDispatch } from 'react-redux';
import { useHistory, useLocation } from 'react-router-dom';
import ChipInput from 'material-ui-chip-input';

import { getPosts, getPostsBySearch } from '../../actions/posts';
import { getPostsBySearch } from '../../actions/posts';
import Posts from '../Posts/Posts';
import Form from '../Form/Form';
import Pagination from '../Pagination';
Expand All @@ -18,7 +18,6 @@ const Home = () => {
const query = useQuery();
const page = query.get('page') || 1;
const searchQuery = query.get('searchQuery');
const searchTags = query.get('tags');

const [currentId, setCurrentId] = useState(0);
const dispatch = useDispatch();
Expand All @@ -27,12 +26,6 @@ const Home = () => {
const [tags, setTags] = useState([]);
const history = useHistory();

// useEffect(() => {
// if (query.get('page')) {
// dispatch(getPosts(page));
// }
// }, [currentId, dispatch, page]);

const searchPost = () => {
if (search.trim() || tags) {
dispatch(getPostsBySearch({ search, tags: tags.join(',') }));
Expand All @@ -42,25 +35,15 @@ const Home = () => {
}
};

// useEffect(() => {
// if (searchQuery || searchTags) {
// dispatch(getPostsBySearch({ search: searchQuery, tags: searchTags }));
// }
// }, [searchQuery, searchTags]);

const handleKeyPress = (e) => {
if (e.keyCode === 13) {
searchPost();
}
};

const handleAddChip = (tag) => {
setTags([...tags, tag]);
};
const handleAddChip = (tag) => setTags([...tags, tag]);

const handleDeleteChip = (chipToDelete) => {
setTags(tags.filter((tag) => tag !== chipToDelete));
};
const handleDeleteChip = (chipToDelete) => setTags(tags.filter((tag) => tag !== chipToDelete));

return (
<Grow in>
Expand All @@ -84,7 +67,7 @@ const Home = () => {
</AppBar>
<Form currentId={currentId} setCurrentId={setCurrentId} />
{(!searchQuery && !tags.length) && (
<Paper className={classes.pagination}>
<Paper className={classes.pagination} elevation={6}>
<Pagination page={page} />
</Paper>
)}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Navbar/Navbar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
import { AppBar, Typography, Toolbar, Avatar, Button, TextField } from '@material-ui/core';
import { AppBar, Typography, Toolbar, Avatar, Button } from '@material-ui/core';
import { Link, useHistory, useLocation } from 'react-router-dom';
import { useDispatch } from 'react-redux';
import decode from 'jwt-decode';
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Navbar/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export default makeStyles((theme) => ({
},
},
heading: {
color: 'rgba(0,183,255, 1)',
color: theme.palette.primary.main,
textDecoration: 'none',
fontSize: '2em',
fontWeight: 300,
},
image: {
marginLeft: '15px',
Expand All @@ -28,7 +29,6 @@ export default makeStyles((theme) => ({
width: '400px',
[theme.breakpoints.down('sm')]: {
width: 'auto',

},
},
profile: {
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Pagination.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react/jsx-props-no-spreading */
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Pagination, PaginationItem } from '@material-ui/lab';
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/PostDetails/PostDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Post = () => {

if (isLoading) {
return (
<Paper style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', padding: '20px', borderRadius: '15px', height: '39vh' }}>
<Paper elevation={6} style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', padding: '20px', borderRadius: '15px', height: '39vh' }}>
<CircularProgress size="7em" />
</Paper>
);
Expand All @@ -39,7 +39,7 @@ const Post = () => {
const recommendedPosts = posts.filter(({ _id }) => _id !== post._id);

return (
<Paper style={{ padding: '20px', borderRadius: '15px' }}>
<Paper style={{ padding: '20px', borderRadius: '15px' }} elevation={6}>
<div className={classes.card}>
<div className={classes.section}>
<Typography variant="h3" component="h2">{post.title}</Typography>
Expand All @@ -61,7 +61,7 @@ const Post = () => {
<div className={classes.section}>
<Typography gutterBottom variant="h5">You might also like:</Typography>
<Divider />
<div style={{ display: 'flex' }}>
<div className={classes.recommendedPosts}>
{recommendedPosts.map(({ title, name, message, likes, selectedFile, _id }) => (
<div style={{ margin: '20px', cursor: 'pointer' }} onClick={() => openPost(_id)} key={_id}>
<Typography gutterBottom variant="h6">{title}</Typography>
Expand Down
6 changes: 6 additions & 0 deletions client/src/components/PostDetails/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ export default makeStyles((theme) => ({
marginLeft: 0,
},
},
recommendedPosts: {
display: 'flex',
[theme.breakpoints.down('sm')]: {
flexDirection: 'column',
},
},
}));
2 changes: 1 addition & 1 deletion client/src/components/Posts/Post/Post.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Post = ({ post, setCurrentId }) => {
};

return (
<Card className={classes.card}>
<Card className={classes.card} raised elevation={6}>
<ButtonBase
component="span"
name="test"
Expand Down
9 changes: 7 additions & 2 deletions client/src/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

body {
background-color: rgba(0,183,255, 1) !important;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='540' height='450' viewBox='0 0 1080 900'%3E%3Cg fill-opacity='.1'%3E%3Cpolygon fill='%23444' points='90 150 0 300 180 300'/%3E%3Cpolygon points='90 150 180 0 0 0'/%3E%3Cpolygon fill='%23AAA' points='270 150 360 0 180 0'/%3E%3Cpolygon fill='%23DDD' points='450 150 360 300 540 300'/%3E%3Cpolygon fill='%23999' points='450 150 540 0 360 0'/%3E%3Cpolygon points='630 150 540 300 720 300'/%3E%3Cpolygon fill='%23DDD' points='630 150 720 0 540 0'/%3E%3Cpolygon fill='%23444' points='810 150 720 300 900 300'/%3E%3Cpolygon fill='%23FFF' points='810 150 900 0 720 0'/%3E%3Cpolygon fill='%23DDD' points='990 150 900 300 1080 300'/%3E%3Cpolygon fill='%23444' points='990 150 1080 0 900 0'/%3E%3Cpolygon fill='%23DDD' points='90 450 0 600 180 600'/%3E%3Cpolygon points='90 450 180 300 0 300'/%3E%3Cpolygon fill='%23666' points='270 450 180 600 360 600'/%3E%3Cpolygon fill='%23AAA' points='270 450 360 300 180 300'/%3E%3Cpolygon fill='%23DDD' points='450 450 360 600 540 600'/%3E%3Cpolygon fill='%23999' points='450 450 540 300 360 300'/%3E%3Cpolygon fill='%23999' points='630 450 540 600 720 600'/%3E%3Cpolygon fill='%23FFF' points='630 450 720 300 540 300'/%3E%3Cpolygon points='810 450 720 600 900 600'/%3E%3Cpolygon fill='%23DDD' points='810 450 900 300 720 300'/%3E%3Cpolygon fill='%23AAA' points='990 450 900 600 1080 600'/%3E%3Cpolygon fill='%23444' points='990 450 1080 300 900 300'/%3E%3Cpolygon fill='%23222' points='90 750 0 900 180 900'/%3E%3Cpolygon points='270 750 180 900 360 900'/%3E%3Cpolygon fill='%23DDD' points='270 750 360 600 180 600'/%3E%3Cpolygon points='450 750 540 600 360 600'/%3E%3Cpolygon points='630 750 540 900 720 900'/%3E%3Cpolygon fill='%23444' points='630 750 720 600 540 600'/%3E%3Cpolygon fill='%23AAA' points='810 750 720 900 900 900'/%3E%3Cpolygon fill='%23666' points='810 750 900 600 720 600'/%3E%3Cpolygon fill='%23999' points='990 750 900 900 1080 900'/%3E%3Cpolygon fill='%23999' points='180 0 90 150 270 150'/%3E%3Cpolygon fill='%23444' points='360 0 270 150 450 150'/%3E%3Cpolygon fill='%23FFF' points='540 0 450 150 630 150'/%3E%3Cpolygon points='900 0 810 150 990 150'/%3E%3Cpolygon fill='%23222' points='0 300 -90 450 90 450'/%3E%3Cpolygon fill='%23FFF' points='0 300 90 150 -90 150'/%3E%3Cpolygon fill='%23FFF' points='180 300 90 450 270 450'/%3E%3Cpolygon fill='%23666' points='180 300 270 150 90 150'/%3E%3Cpolygon fill='%23222' points='360 300 270 450 450 450'/%3E%3Cpolygon fill='%23FFF' points='360 300 450 150 270 150'/%3E%3Cpolygon fill='%23444' points='540 300 450 450 630 450'/%3E%3Cpolygon fill='%23222' points='540 300 630 150 450 150'/%3E%3Cpolygon fill='%23AAA' points='720 300 630 450 810 450'/%3E%3Cpolygon fill='%23666' points='720 300 810 150 630 150'/%3E%3Cpolygon fill='%23FFF' points='900 300 810 450 990 450'/%3E%3Cpolygon fill='%23999' points='900 300 990 150 810 150'/%3E%3Cpolygon points='0 600 -90 750 90 750'/%3E%3Cpolygon fill='%23666' points='0 600 90 450 -90 450'/%3E%3Cpolygon fill='%23AAA' points='180 600 90 750 270 750'/%3E%3Cpolygon fill='%23444' points='180 600 270 450 90 450'/%3E%3Cpolygon fill='%23444' points='360 600 270 750 450 750'/%3E%3Cpolygon fill='%23999' points='360 600 450 450 270 450'/%3E%3Cpolygon fill='%23666' points='540 600 630 450 450 450'/%3E%3Cpolygon fill='%23222' points='720 600 630 750 810 750'/%3E%3Cpolygon fill='%23FFF' points='900 600 810 750 990 750'/%3E%3Cpolygon fill='%23222' points='900 600 990 450 810 450'/%3E%3Cpolygon fill='%23DDD' points='0 900 90 750 -90 750'/%3E%3Cpolygon fill='%23444' points='180 900 270 750 90 750'/%3E%3Cpolygon fill='%23FFF' points='360 900 450 750 270 750'/%3E%3Cpolygon fill='%23AAA' points='540 900 630 750 450 750'/%3E%3Cpolygon fill='%23FFF' points='720 900 810 750 630 750'/%3E%3Cpolygon fill='%23222' points='900 900 990 750 810 750'/%3E%3Cpolygon fill='%23222' points='1080 300 990 450 1170 450'/%3E%3Cpolygon fill='%23FFF' points='1080 300 1170 150 990 150'/%3E%3Cpolygon points='1080 600 990 750 1170 750'/%3E%3Cpolygon fill='%23666' points='1080 600 1170 450 990 450'/%3E%3Cpolygon fill='%23DDD' points='1080 900 1170 750 990 750'/%3E%3C/g%3E%3C/svg%3E");
background-color: #f7f8fc;
}

* {
/* font-family: 'Noto Sans JP' !important; */
font-family: 'Heebo', sans-serif !important;
}
2 changes: 1 addition & 1 deletion server/controllers/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getPosts = async (req, res) => {
const startIndex = (Number(page) - 1) * LIMIT; // get the starting index of every page

const total = await PostMessage.countDocuments({});
const posts = await PostMessage.find().limit(LIMIT).skip(startIndex);
const posts = await PostMessage.find().sort({ _id: -1 }).limit(LIMIT).skip(startIndex);

res.json({ data: posts, currentPage: Number(page), numberOfPages: Math.ceil(total / LIMIT)});
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"type": "module",
"scripts": {
"start": "nodemon index.js"
"start": "node index.js"
},
"author": "",
"license": "ISC",
Expand Down