Skip to content

Commit

Permalink
Merge branch 'FrontEnd-Integration' into 32-question-view-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lauratbg authored Mar 4, 2024
2 parents 3cc31fa + 1ae245b commit 2060fdb
Show file tree
Hide file tree
Showing 16 changed files with 1,174 additions and 154 deletions.
507 changes: 506 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"dependencies": {
"asciidoctor-emoji": "^0.5.0"
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"asciidoctor-emoji": "^0.5.0",
"react-router-dom": "^6.22.1"
}
}
50 changes: 49 additions & 1 deletion webapp/package-lock.json

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

4 changes: 3 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"axios": "^1.6.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"react-icons": "^5.0.1",
"react-router-dom": "^6.22.2",
"react-scripts": "^5.0.1",
"web-vitals": "^3.5.1"
},
"scripts": {
Expand Down
Binary file added webapp/public/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added webapp/public/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 21 additions & 32 deletions webapp/src/App.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
import React, { useState } from 'react';
import AddUser from './components/AddUser';
import Login from './components/Login';
import CssBaseline from '@mui/material/CssBaseline';
import React from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import Container from '@mui/material/Container';
import Typography from '@mui/material/Typography';
import Link from '@mui/material/Link';
import QuestionView from './components/questionView/QuestionView';
import Navbar from './components/fragments/NavBar';
import Home from './components/home/Home';
import Login from './components/Login';
import AddUser from './components/AddUser';
import Instructions from './components/Instructions';

function App() {
const [showLogin, setShowLogin] = useState(true);

const handleToggleView = () => {
setShowLogin(!showLogin);
};

function App() {
return (
<QuestionView />
/*
<Container component="main" maxWidth="xs">
<CssBaseline />
<Typography component="h1" variant="h5" align="center" sx={{ marginTop: 2 }}>
Welcome to the 2024 edition of the Software Architecture course
</Typography>
{showLogin ? <Login /> : <AddUser />}
<Typography component="div" align="center" sx={{ marginTop: 2 }}>
{showLogin ? (
<Link name="gotoregister" component="button" variant="body2" onClick={handleToggleView}>
Don't have an account? Register here.
</Link>
) : (
<Link component="button" variant="body2" onClick={handleToggleView}>
Already have an account? Login here.
</Link>
)}
</Typography>
</Container>*/
<Router>
<Container component="main" maxWidth="xl">
<Navbar />
<Routes>
<Route path="/" element={<Navigate to="/home" />} />
<Route path="/home" element={<Home />} />
<Route path="/login" element={<Login />} />
<Route path="/instructions" element={<Instructions />} />
<Route path="/addUser" element={<AddUser />} />

</Routes>
</Container>
</Router>
);
}

Expand Down
137 changes: 85 additions & 52 deletions webapp/src/components/AddUser.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,93 @@
// src/components/AddUser.js
import React, { useState } from 'react';
import axios from 'axios';
import { Container, Typography, TextField, Button, Snackbar } from '@mui/material';

const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';
import React, { useState } from "react";
import { FaUser, FaLock } from "react-icons/fa";
import "./Login.css";
import { Link } from "react-router-dom";

const AddUser = () => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const [openSnackbar, setOpenSnackbar] = useState(false);

const addUser = async () => {
try {
await axios.post(`${apiEndpoint}/adduser`, { username, password });
setOpenSnackbar(true);
} catch (error) {
setError(error.response.data.error);
}
};

const handleCloseSnackbar = () => {
setOpenSnackbar(false);
};

return (
<Container component="main" maxWidth="xs" sx={{ marginTop: 4 }}>
<Typography component="h1" variant="h5">
Add User
</Typography>
<TextField
name="username"
margin="normal"
fullWidth
label="Username"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
<TextField
name="password"
margin="normal"
fullWidth
label="Password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<Button variant="contained" color="primary" onClick={addUser}>
Add User
</Button>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="User added successfully" />
{error && (
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
)}
</Container>
<div className="wrapper">
<form action="">
<div className="wrapper2">
<h1> Register </h1>
<div className="input-box">
<input type="text" placeholder="Username" required />
<FaUser className="icon" />
</div>
<div className="input-box">
<input type="password" placeholder="Password" required />
<FaLock className="icon" />
</div>
<div className="input-box">
<input type="password" placeholder="Repeat password" required />
<FaLock className="icon" />
</div>

<button type="submit">Register</button>

<LinkLogin />
</div>
</form>
</div>
);
};

function LinkLogin() {
return (
<Link to="/login" className="button-login" variant="body2" >
Do you have an account? Login here.
</Link>
);
}
// const [username, setUsername] = useState('');
// const [password, setPassword] = useState('');
// const [error, setError] = useState('');
// const [openSnackbar, setOpenSnackbar] = useState(false);

// const addUser = async () => {
// try {
// await axios.post(`${apiEndpoint}/adduser`, { username, password });
// setOpenSnackbar(true);
// } catch (error) {
// setError(error.response.data.error);
// }
// };

// const handleCloseSnackbar = () => {
// setOpenSnackbar(false);
// };

// return (
// <Container component="main" maxWidth="xs" sx={{ marginTop: 4 }}>
// <Typography component="h1" variant="h5">
// Add User
// </Typography>
// <TextField
// name="username"
// margin="normal"
// fullWidth
// label="Username"
// value={username}
// onChange={(e) => setUsername(e.target.value)}
// />
// <TextField
// name="password"
// margin="normal"
// fullWidth
// label="Password"
// type="password"
// value={password}
// onChange={(e) => setPassword(e.target.value)}
// />
// <Button variant="contained" color="primary" onClick={addUser}>
// Add User
// </Button>
// <Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="User added successfully" />
// {error && (
// <Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
// )}
// </Container>
// );
// };

export default AddUser;
37 changes: 37 additions & 0 deletions webapp/src/components/Home/Home.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}

.wrapper button{
width: 100%;
height: 45px;
background: darkblue;
border: none;
outline: none;
border-radius: 40px;
box-shadow: 0 0 10px black;
cursor:pointer;
font-size: 16px;
color: white;
font-weight: 700;
}

.wrapper link{
font-size: 14.5px;
text-align: center;
margin: 20px 0 15px;
}










Loading

0 comments on commit 2060fdb

Please sign in to comment.