Skip to content

Commit

Permalink
feat: Added section for editing a blog.
Browse files Browse the repository at this point in the history
Signed-off-by: vishal-codes <itsvishal2417@gmail.com>
  • Loading branch information
vishal-codes committed Feb 4, 2023
1 parent 27cc6c1 commit a2ce4fc
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 115 deletions.
20 changes: 10 additions & 10 deletions client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<style>
@import url('https://fonts.googleapis.com/css2?family=Work+Sans:wght@300;400;500;600;700&display=swap&family=Poppins:wght@300;400;500;600;700');
body {
margin: 0;
font-family: Segoe UI, Helvetica Neue, Helvetica, Lucida Grande,
Arial, Ubuntu, Cantarell, Fira Sans, sans-serif !important;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
</style>
@import url('https://fonts.googleapis.com/css2?family=Work+Sans:wght@300;400;500;600;700&display=swap&family=Poppins:wght@300;400;500;600;700');
body {
margin: 0;
font-family: Segoe UI, Helvetica Neue, Helvetica, Lucida Grande,
Arial, Ubuntu, Cantarell, Fira Sans, sans-serif !important;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
</style>
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand All @@ -34,7 +34,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Comfort Space</title>
<script
src="https://accounts.google.com/gsi/client"
async
Expand Down
9 changes: 6 additions & 3 deletions client/src/components/CreateBlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function CreateBlog({ mode }) {
process.env.REACT_APP_APPWRITE_BUCKET_ID,
id
);
setUploadStatus('Uploaded successfully');
setUploadStatus('Uploaded successfully');
setCoverUrl(result.href);
}
};
Expand All @@ -82,7 +82,10 @@ function CreateBlog({ mode }) {
alert('Please fill all the text fields');
return;
}

if (summary.length > 55) {
alert('Summary should be less than 55 characters');
return;
}
const config = {
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -235,7 +238,7 @@ function CreateBlog({ mode }) {
variant='body1'
sx={{
textAlign: 'center',
mb: 3,
ml: 1,
}}
>
{uploadStatus}
Expand Down
215 changes: 215 additions & 0 deletions client/src/components/EditBlog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import React, { useState } from 'react';

import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import ReactQuill from 'react-quill';
import 'react-quill/dist/quill.snow.css';
import axios from 'axios';

import {
bluegrey,
richBlack,
light,
medium,
deepDark,
superLight,
} from './colors';
import { useLocation } from 'react-router';

import { Button, Typography } from '@mui/material';
import TextField from '@mui/material/TextField';
import { useNavigate } from 'react-router';
import { useSelector } from 'react-redux';
import DriveFileRenameOutlineIcon from '@mui/icons-material/DriveFileRenameOutline';

import { customGlobalScrollBars, smoothScrolling } from './CustomGlobalCSS';

function EditBlog({ mode }) {
const location = useLocation();
const navigate = useNavigate();

const author = useSelector((state) => state.auth);
const blog = location.state.blog;

const oldTitle = blog.title;
const oldContent = blog.content;
const oldSummary = blog.summary;
const [title, setTitle] = useState(blog.title);
const [content, setContent] = useState(blog.content);
const [summary, setSummary] = useState(blog.summary);

const modules = {
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline', 'strike', 'blockquote'],
[
{ list: 'ordered' },
{ list: 'bullet' },
{ indent: '-1' },
{ indent: '+1' },
],
['link', 'image'],
['clean'],
],
};

const editPost = async (e) => {
e.preventDefault();
if (!title || !content || !summary) {
alert('Please fill all the text fields');
return;
}
if (
title === oldTitle &&
content === oldContent &&
summary === oldSummary
) {
alert('No changes made');
return;
}
const config = {
headers: {
'Content-Type': 'application/json',
},
title,
content,
summary,
authorId: author.uid,
};
await axios.patch(
`${process.env.REACT_APP_SERVER_URL}/api/blog/edit/${blog._id}`,
config
);
navigate(`/blog/${blog._id}`);
};

return (
<Box
sx={{
minHeight: '100vh',
backgroundColor: mode === 'light' ? light : bluegrey,
color: 'text.primary',
p: '5rem',
}}
>
{customGlobalScrollBars(mode)}
{smoothScrolling()}
<Paper
sx={{
p: 2,
mt: 2,
backgroundColor: mode === 'light' ? superLight : richBlack,
boxShadow: '0 0 10px 0 rgba(0, 0, 0, 0.3)',
border: mode === 'light' ? 'none' : `1px solid ${light}`,
borderRadius: '15px',
}}
>
<Typography
variant='h3'
sx={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
my: 2,
mb: 4,
color: mode === 'light' ? deepDark : light,
padding: '0',
fontFamily: 'Poppins',
fontWeight: '600',
fontSize: '2.5rem',
}}
>
<DriveFileRenameOutlineIcon
sx={{ fontSize: '2.5rem', mr: 1 }}
/>
Create a Blog
</Typography>
<form onSubmit={editPost}>
<TextField
fullWidth
required
id='outlined-required'
label='Title'
value={title}
color='success'
onChange={(e) => setTitle(e.target.value)}
sx={{
fontFamily: 'Poppins, Work Sans',
backgroundColor:
mode === 'light' ? 'whitesmoke' : richBlack,
borderRadius: '6px',
mb: 3,
'& .MuiInputBase-input': {
p: 1,
},
'& .MuiInputLabel-root': {
top: -5,
fontSize: '0.9rem',
},
}}
/>
<TextField
fullWidth
required
id='outlined-required'
label='Summary (max 55 characters)'
value={summary}
color='success'
onChange={(e) => setSummary(e.target.value)}
sx={{
backgroundColor:
mode === 'light' ? 'whitesmoke' : richBlack,
borderRadius: '6px',
mb: 3,
'& .MuiInputBase-input': {
p: 1,
},
'& .MuiInputLabel-root': {
top: -5,
fontSize: '0.9rem',
},
}}
/>
<ReactQuill
theme='snow'
modules={modules}
value={content}
onChange={(newValue) => setContent(newValue)}
sx={{
backgroundColor:
mode === 'light' ? 'whitesmoke' : richBlack,
borderRadius: '6px',
mb: 3,
'& .ql-editor': {
p: 1,
},
'& .ql-container': {
p: 1,
},
}}
/>

<Button
color='success'
sx={{
mt: 3,
backgroundColor: mode === 'light' ? medium : light,
color: bluegrey,
font: '500 0.9rem Poppins, sans-serif',
':hover': {
backgroundColor: medium,
color: 'black',
},
}}
variant='contained'
type='submit'
>
Save Changes
</Button>
</form>
</Paper>
</Box>
);
}

export default EditBlog;
5 changes: 3 additions & 2 deletions client/src/components/GoogleOneTapLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
stopLoadingAction,
} from '../actions/actions';

import { bluegrey, light, medium, dark, deepDark } from '../components/colors';
import { light, deepDark } from '../components/colors';

const GoogleOneTapLogin = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -66,7 +66,8 @@ const GoogleOneTapLogin = () => {
username
)
);
navigate('/home');
window.localStorage.setItem('healthAppLastPage', 'groups');
navigate('/groups');
})
.catch((err) => {
console.log(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default function Home({ themeChange, mode }) {
);
if (response.data.success) {
setModalVisible(false);
window.open(`${process.env.REACT_APP_BASE_URL}/home`, '_self');
window.open(`${process.env.REACT_APP_BASE_URL}/groups`, '_self');
} else {
alert('Something went wrong, please try again');
}
Expand Down Expand Up @@ -428,6 +428,7 @@ export default function Home({ themeChange, mode }) {
}}
>
<TextField
color='success'
fullWidth
required
id='outlined-required'
Expand All @@ -446,6 +447,7 @@ export default function Home({ themeChange, mode }) {
}}
/>
<TextField
color='success'
fullWidth
required
id='outlined-required'
Expand Down
25 changes: 1 addition & 24 deletions client/src/components/LandingPage.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
import React, { useEffect } from 'react';
import React from 'react';
import Box from '@mui/material/Box';
import GoogleOneTapLogin from './GoogleOneTapLogin';
import Typography from '@mui/material/Typography';
import { useDispatch } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import jwtDecode from 'jwt-decode';

import { signInAction } from '../actions/actions';
function LandingPage() {
const dispatch = useDispatch();
const navigate = useNavigate();

useEffect(() => {
const auth = window.localStorage.getItem('healthApp');
if (auth) {
const { dnd } = JSON.parse(auth);
const {
sub: uid,
email,
name,
picture: photoURL,
iat: signInTime,
} = jwtDecode(dnd);
dispatch(signInAction(uid, email, name, photoURL, dnd, signInTime));
navigate('/home');
}
});

return (
<Box
sx={{
Expand Down
Loading

0 comments on commit a2ce4fc

Please sign in to comment.