Skip to content

Commit

Permalink
Merge pull request #60 from agiledev-students-spring2024/homeBranch
Browse files Browse the repository at this point in the history
- Added components folder where we add components
  • Loading branch information
ellispinsky authored Mar 6, 2024
2 parents 16a3731 + 2c68b72 commit 33dc9e5
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 18 deletions.
3 changes: 2 additions & 1 deletion front-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"react-router-dom": "^6.22.2",
"react-scripts": "^5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
Binary file removed front-end/public/logo192.png
Binary file not shown.
63 changes: 63 additions & 0 deletions front-end/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,66 @@
transform: rotate(360deg);
}
}
.mainContainer {
flex-direction: column;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}

.titleContainer {
display: flex;
flex-direction: column;
font-size: 64px;
font-weight: bolder;
align-items: center;
justify-content: center;
}

.resultContainer,
.historyItem {
flex-direction: row;
display: flex;
width: 400px;
align-items: center;
justify-content: space-between;
}

.historyContainer {
flex-direction: column;
display: flex;
height: 200px;
align-items: center;
flex-grow: 5;
justify-content: flex-start;
}

.buttonContainer {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 260px;
}

.inputContainer {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
}

.inputContainer > .errorLabel {
color: red;
font-size: 12px;
}

.inputBox {
height: 48px;
width: 400px;
font-size: large;
border-radius: 8px;
border: 1px solid grey;
padding-left: 8px;
}
43 changes: 26 additions & 17 deletions front-end/src/App.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import logo from './logo.svg';
import './App.css';

import "./App.css";
import Home from "./components/home";
import Login from "./components/login";
import { useState } from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
function App() {
const [loggedIn, setLoggedIn] = useState(false);
const [email, setEmail] = useState("");

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<BrowserRouter>
<Routes>
<Route
path="/"
element={
<Home
email={email}
loggedIn={loggedIn}
setLoggedIn={setLoggedIn}
/>
}
/>
<Route
path="/login"
element={<Login setLoggedIn={setLoggedIn} setEmail={setEmail} />}
/>
</Routes>
</BrowserRouter>
</div>
);
}
Expand Down
31 changes: 31 additions & 0 deletions front-end/src/components/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react'
import { useNavigate } from 'react-router-dom'

const Home = (props) => {
const { loggedIn, email } = props
const navigate = useNavigate()

const onButtonClick = () => {
// You'll update this function later
}

return (
<div className="mainContainer">
<div className={'titleContainer'}>
<div>Welcome!</div>
</div>
<div>This is the home page.</div>
<div className={'buttonContainer'}>
<input
className={'inputButton'}
type="button"
onClick={onButtonClick}
value={loggedIn ? 'Log out' : 'Log in'}
/>
{loggedIn ? <div>Your email address is {email}</div> : <div />}
</div>
</div>
)
}

export default Home
74 changes: 74 additions & 0 deletions front-end/src/components/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React, { useState } from 'react'
import { useNavigate } from 'react-router-dom'

const Login = (props) => {
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [emailError, setEmailError] = useState('')
const [passwordError, setPasswordError] = useState('')

const navigate = useNavigate()

const onButtonClick = () => {
// Set initial error values to empty
setEmailError('')
setPasswordError('')

// Check if the user has entered both fields correctly
if ('' === email) {
setEmailError('Please enter your email')
return
}

if (!/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(email)) {
setEmailError('Please enter a valid email')
return
}

if ('' === password) {
setPasswordError('Please enter a password')
return
}

if (password.length < 7) {
setPasswordError('The password must be 8 characters or longer')
return
}

// Authentication calls will be made here...
}

return (
<div className={'mainContainer'}>
<div className={'titleContainer'}>
<div>Login</div>
</div>
<br />
<div className={'inputContainer'}>
<input
value={email}
placeholder="Enter your email here"
onChange={(ev) => setEmail(ev.target.value)}
className={'inputBox'}
/>
<label className="errorLabel">{emailError}</label>
</div>
<br />
<div className={'inputContainer'}>
<input
value={password}
placeholder="Enter your password here"
onChange={(ev) => setPassword(ev.target.value)}
className={'inputBox'}
/>
<label className="errorLabel">{passwordError}</label>
</div>
<br />
<div className={'inputContainer'}>
<input className={'inputButton'} type="button" onClick={onButtonClick} value={'Log in'} />
</div>
</div>
)
}

export default Login
54 changes: 54 additions & 0 deletions front-end/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,57 @@ code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

html,
body {
padding: 0;
margin: 0;
font-family:
-apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
}

* {
box-sizing: border-box;
}

main {
padding: 5rem 0;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

code {
background: #fafafa;
border-radius: 5px;
padding: 0.75rem;
font-family:
Menlo,
Monaco,
Lucida Console,
Courier New,
monospace;
}

input[type='button'] {
border: none;
background: cornflowerblue;
color: white;
padding: 12px 24px;
margin: 8px;
font-size: 24px;
border-radius: 8px;
cursor: pointer;
}

0 comments on commit 33dc9e5

Please sign in to comment.