Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
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
24,140 changes: 1,045 additions & 23,095 deletions client/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"formik": "^2.2.6",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-hook-form": "^7.19.0",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.0",
"socket.io-client": "^4.0.1",
Expand Down
19 changes: 19 additions & 0 deletions client/src/helpers/APICalls/uploadImage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { AuthApiData } from '../../interface/AuthApiData';

const uploadImage = async (Image: File): Promise<AuthApiData> => {
const data = new FormData();
data.append('uploads', Image);

const fetchOptions = {
method: 'POST',
body: data,
};

return await fetch(`/imageUpload`, fetchOptions)
.then((res) => res.json())
.catch((err) => {
console.log('UPLOADIMAGE-ERROR: ', err);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use console.error for this log

});
};

export default uploadImage;
2 changes: 1 addition & 1 deletion client/src/mocks/mockUseAuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ const MockUseAuthProvider: FunctionComponent = ({ children }) => {
{children}
</AuthContext.Provider>
);
};
};

export default MockUseAuthProvider;
60 changes: 55 additions & 5 deletions client/src/pages/ProfilePicture/ProfilePicture.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';
import { ChangeEvent, FormEvent, useState } from 'react';
import useStyles from './useStyles';
import AuthMenu from '../../components/AuthMenu/AuthMenu';
import Grid from '@material-ui/core/Grid';
Expand All @@ -8,9 +10,37 @@ import Button from '@material-ui/core/Button';
import IconButton from '@material-ui/core/IconButton';
import Box from '@material-ui/core/Box';
import DeleteIcon from '@material-ui/icons/Delete';
import uploadImage from '../../helpers/APICalls/uploadImage';

export default function ProfilePicture(): JSX.Element {
const classes = useStyles();
const [fileInput, setFileInput] = useState<File>();
const [previewImage, setPreviewImage] = useState('');
const componentRef = React.useRef<HTMLFormElement>(null);

const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
if (!fileInput) return;
uploadImage(fileInput);
};

const handleChange = async (event: ChangeEvent<HTMLInputElement>) => {
const target = event.target as HTMLInputElement;
const image: File = (target.files as FileList)[0];
profileImage(image);
await setFileInput(image);
componentRef.current?.requestSubmit();
};

const profileImage = (image: File) => {
const reader = new FileReader();
reader.readAsDataURL(image);
reader.onloadend = () => {
const result = reader.result as string;
setPreviewImage(result);
};
};

return (
<Box className={classes.outsideContainer}>
<AuthMenu />
Expand All @@ -34,8 +64,8 @@ export default function ProfilePicture(): JSX.Element {
Profile Picture
</Typography>
</Grid>
<Grid item container className={classes.profileImageContainer}>
<img src="" className={classes.profileImage}></img>
<Grid item container className={classes.previewImageContainer}>
{previewImage && <img src={previewImage} className={classes.previewImage}></img>}
</Grid>
<Grid item container className={classes.tipContainer}>
<Typography variant="h6" className={classes.tip}>
Expand All @@ -44,11 +74,31 @@ export default function ProfilePicture(): JSX.Element {
</Typography>
</Grid>
<Grid item container className={classes.uploadButtonContainer}>
<Button variant="text" className={classes.uploadButton}>
Upload a file from your device
</Button>
<form
method="POST"
action="/imageUpload"
id="upload-Image-Form"
ref={componentRef}
onSubmit={handleSubmit}
encType="multipart/form-data"
>
<input
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use MUI TextField for this one

className={classes.uploadInput}
id="fileInput"
name="uploads"
type="file"
onChange={handleChange}
/>
<label htmlFor="fileInput" className={classes.label}>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use MUI InputLabel for this

<Button variant="contained" component="span" className={classes.uploadButton}>
Upload a file from your device
</Button>
</label>
<button type="submit" className={classes.submitButton}></button>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use MUI Button component for this one

</form>
</Grid>
<Grid item container className={classes.deleteButtonContainer}>
{/*this is going to remove from the cloud*/}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment please

<IconButton className={classes.deleteButton}>
<DeleteIcon className={classes.deleteButtonIcon} />
Delete photo
Expand Down
21 changes: 14 additions & 7 deletions client/src/pages/ProfilePicture/useStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const useStyles = makeStyles(() => ({
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: -1,
// zIndex: -1,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused code line

overflow: 'hidden',
},
innerContentContainer: {
Expand All @@ -37,7 +37,7 @@ const useStyles = makeStyles(() => ({
color: 'black',
margin: '2rem',
},
profileImageContainer: {
previewImageContainer: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
Expand All @@ -46,11 +46,11 @@ const useStyles = makeStyles(() => ({
paddingBottom: '2rem',
border: 'none',
},
profileImage: {
previewImage: {
position: 'relative',
display: 'flex',
height: '10rem',
width: '10rem',
height: '15rem',
width: '15rem',
border: '0.15rem solid',
borderRadius: '50%',
},
Expand All @@ -75,20 +75,27 @@ const useStyles = makeStyles(() => ({
},
uploadButton: {
border: '0.15rem solid',
borderRadius: '0.3rem',
borderColor: 'red',
color: 'red',
fontWeight: 700,
fontSize: '1rem',
fontFamily: 'sans-serif',
height: '4rem',
width: '30%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'transparent',
'&:hover': {
backgroundColor: 'transparent',
},
},
label: {},
submitButton: {
display: 'none',
},
uploadInput: {
display: 'none',
},
deleteButtonContainer: {
display: 'flex',
alignItems: 'center',
Expand Down
Loading