diff --git a/client/src/components/SnippetDisplay/SnippetDisplay.jsx b/client/src/components/SnippetDisplay/SnippetDisplay.jsx index 85d5f40..c15fc78 100644 --- a/client/src/components/SnippetDisplay/SnippetDisplay.jsx +++ b/client/src/components/SnippetDisplay/SnippetDisplay.jsx @@ -12,6 +12,7 @@ import { langs } from '@uiw/codemirror-extensions-langs'; // importing utils import { Card, Button } from 'react-bootstrap'; +import { set } from 'mongoose'; const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { const defaultDisplayValues = { @@ -19,7 +20,7 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { language: '', comments: '', storedCode: '', - tags: [] + tags: [], }; const [copied, setCopied] = useState(false); @@ -30,9 +31,16 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { setCurrentDisplay(selectedSnippet); }, [selectedSnippet, getSnippet]); + const handleCopy = () => { + setCopied(true); + setTimeout(() => { + setCopied(false); + }, 2000); + }; + const deleteSnippet = (snippetId) => { fetch('/snippets?' + new URLSearchParams({ snippetId }), { - method: 'DELETE' + method: 'DELETE', }) .then((response) => { if (response.ok) { @@ -44,7 +52,7 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { return { log: `SnippetDisiplay.deleteSnippet: Error: ${err}`, status: err.status, - message: 'There was an error deleting snippet.' + message: 'There was an error deleting snippet.', }; }); }; @@ -53,7 +61,7 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { fetch(`/snippets?${new URLSearchParams({ snippetId })}`, { method: 'PUT', headers: { 'Content-type': 'application/json' }, - body: JSON.stringify(currentDisplay) + body: JSON.stringify(currentDisplay), }) .then((response) => { //Are we using this response anywhere? IF not, delete this. @@ -68,66 +76,63 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { return { log: `SnippetDisplay.editSnippet: Error: ${err}`, status: err.status, - message: 'There was an error editing code snippet.' + message: 'There was an error editing code snippet.', }; }); }; const displayContent = (
-
+
-
- Title: +
+ Title: { if (editButtonState) { setCurrentDisplay({ ...currentDisplay, - title: e.target.value + title: e.target.value, }); } - }} - > + }}>
-
- Language: +
+ Language: { if (editButtonState) { setCurrentDisplay({ ...currentDisplay, - language: e.target.value + language: e.target.value, }); } - }} - > + }}>
-
- Comments: +
+ Comments: { if (editButtonState) { setCurrentDisplay({ ...currentDisplay, - comments: e.target.value + comments: e.target.value, }); } - }} - > + }}>
{ if (editButtonState) { setCurrentDisplay({ ...currentDisplay, tags: e }); @@ -141,59 +146,56 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { {\n console.log(\'Hello World!)\n}'} onChange={(e) => { setCurrentDisplay({ ...currentDisplay, storedCode: e }); - }} - > - setCopied(true)} - > - + }}> + + + {copied && copied to clipboard!}
); return ( - + {displayContent}
@@ -204,6 +206,6 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { SnippetDisplay.propTypes = { selectedSnippet: PropTypes.object, - getSnippet: PropTypes.func + getSnippet: PropTypes.func, }; export default SnippetDisplay; diff --git a/client/src/components/userStart/Login.jsx b/client/src/components/userStart/Login.jsx index 19449f6..30d9b2e 100644 --- a/client/src/components/userStart/Login.jsx +++ b/client/src/components/userStart/Login.jsx @@ -1,29 +1,48 @@ -import React, {useState} from 'react'; - - +import React, { useState } from 'react'; +import styles from './Login.module.scss'; // eslint-disable-next-line react/prop-types -const Login = ({handleLogin, handleHaveAccount}) => { - - - +const Login = ({ handleLogin, handleHaveAccount, style, error }) => { return (

USER LOGIN

-
-
-     - + +
+     +
-
-     - +
+     +
- + + {error &&

wrong username or password!

}
- +
); }; diff --git a/client/src/components/userStart/Login.module.scss b/client/src/components/userStart/Login.module.scss new file mode 100644 index 0000000..796d61f --- /dev/null +++ b/client/src/components/userStart/Login.module.scss @@ -0,0 +1,8 @@ +.red { + border: 1.5px solid red; +} + +.p { + margin-top: 8px; + color: red; +} diff --git a/client/src/containers/MainContainer/MainContainer.jsx b/client/src/containers/MainContainer/MainContainer.jsx index 0029963..b8817d5 100644 --- a/client/src/containers/MainContainer/MainContainer.jsx +++ b/client/src/containers/MainContainer/MainContainer.jsx @@ -7,6 +7,7 @@ import Signup from '../../components/userStart/Signup.jsx'; const MainContainer = () => { const [login, setLogin] = useState(false); const [haveAccount, setHaveAccount] = useState(true); + const [error, setError] = useState(false); const handleLogin = (e) => { e.preventDefault(); @@ -18,21 +19,22 @@ const MainContainer = () => { fetch('http://localhost:3000/authentication/login', { method: 'POST', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', }, // include cookies from cross origin request credentials: 'include', body: JSON.stringify({ username: usernameInputValue, - password: passwordInputValue - }) + password: passwordInputValue, + }), }) .then((result) => result.json()) .then((result) => { console.log('result from login request: ', result); - setLogin(true); + setLogin(result.username); }) .catch((err) => { + setError(true); console.log(err); }); @@ -53,17 +55,18 @@ const MainContainer = () => { fetch('http://localhost:3000/authentication/signup', { method: 'POST', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', }, body: JSON.stringify({ username: nameValue, - password: passwordValue - }) + password: passwordValue, + }), }) .then((result) => result.json()) .then((result) => { console.log('result from signup request: ', result); setHaveAccount(true); + setLogin(result.username); }) .catch((err) => { console.log(err); @@ -72,11 +75,28 @@ const MainContainer = () => { return login ? (
+
+ +

+ welcome, {login} +

+
) : haveAccount ? (
- +
) : (
diff --git a/client/src/containers/MainContainer/MainContainer.module.scss b/client/src/containers/MainContainer/MainContainer.module.scss index 3028ec1..27f568c 100644 --- a/client/src/containers/MainContainer/MainContainer.module.scss +++ b/client/src/containers/MainContainer/MainContainer.module.scss @@ -4,3 +4,32 @@ display: flex; } + +.div { + position: absolute; + top: 1rem; + right: 3rem; +} + +.button { + margin-right: 1rem; + border: 1px solid transparent; + border-radius: 5px; +} + +.h2 { + display: inline-block; + background: -webkit-linear-gradient(#ffffff, #333); + -webkit-background-clip: text; + -webkit-text-fill-color: transparent; +} + +.span { + font-family: 'Courier New', Courier, monospace; + font-size: 48px; + text-transform: uppercase; + background: -webkit-linear-gradient(#ffffff, #e2b2b2); + -webkit-background-clip: text; + -webkit-text-fill-color: transparent; +} + diff --git a/client/src/containers/Sidebar/Sidebar.module.scss b/client/src/containers/Sidebar/Sidebar.module.scss index f29bab6..d0c1f22 100644 --- a/client/src/containers/Sidebar/Sidebar.module.scss +++ b/client/src/containers/Sidebar/Sidebar.module.scss @@ -38,7 +38,7 @@ width: 300px; height: inherit; position: absolute; - left: -300px; + left: -250px; top: 0; transition: 200ms ease-in; diff --git a/server/routes/authenticationRouter.js b/server/routes/authenticationRouter.js index be5249b..60ead2a 100644 --- a/server/routes/authenticationRouter.js +++ b/server/routes/authenticationRouter.js @@ -9,7 +9,7 @@ require('dotenv').config(); const secret = process.env.JWT_SECRET; router.post('/signup', authenticationController.signUp, (req, res) => { - return res.status(201).json(res.locals.newUser); + return res.status(201).json({ username: res.locals.newUser.username }); }); router.post( @@ -18,17 +18,17 @@ router.post( (req, res) => { console.log(req.user); const token = jwt.sign({ userId: req.user.id }, secret, { - expiresIn: '1d' + expiresIn: '1d', }); res.cookie('token', token, { expires: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // Expires in 30 days - httpOnly: true + httpOnly: true, }); res.cookie('userId', req.user.id, { expires: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // Expires in 30 days - httpOnly: true + httpOnly: true, }); - return res.status(202).json({ token }); + return res.status(202).json({ username: req.user.username }); } );