Skip to content

Commit

Permalink
basic styling
Browse files Browse the repository at this point in the history
  • Loading branch information
viviannnl committed Sep 17, 2023
1 parent a4493b7 commit 8abb8ed
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 29 deletions.
Binary file added frontend/public/co2_img.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed frontend/public/favicon.ico
Binary file not shown.
Binary file added frontend/public/logo.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 removed frontend/public/logo512.png
Binary file not shown.
11 changes: 11 additions & 0 deletions frontend/src/components/Spinner.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'

function Spinner() {
return (
<div className='loadingSpinnerContainer'>
<div className='loadingSpinner'></div>
</div>
)
}

export default Spinner
2 changes: 1 addition & 1 deletion frontend/src/features/auth/authService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const register = async (userData) => {
const response = await axios.post(API_URL, userData)

if(response.data) {
localStorage.setItem('user', JSON.stringify(response.data))
localStorage.setItem('user', response.data)
}

return response.data
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/features/goals/goalsSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const submitGoals = createAsyncThunk ('goals/submit', async (goalsData, t
try {

const user = thunkAPI.getState().auth.user
const token = JSON.parse(user).token
const token = user.token
//console.log(goalsData)

return await goalsService.submitGoals(goalsData, token)
Expand All @@ -32,8 +32,8 @@ export const getGoals = createAsyncThunk ('goals/get', async (_,thunkAPI) => {
try {

const user = thunkAPI.getState().auth.user
const token = JSON.parse(user).token
//console.log(token)
const token = user.token
console.log(token)

return await goalsService.getGoals(token)
} catch(error) {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/features/habits/habitsSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const initialState = {

// submit habits
export const submitHabits = createAsyncThunk ('habits/submit', async (habitsData, thunkAPI) => {

console.log(habitsData)
try {

const user = thunkAPI.getState().auth.user
const token = JSON.parse(user).token
const token = user.token

console.log(habitsData)

Expand All @@ -33,7 +33,7 @@ export const getHabits = createAsyncThunk ('habits/get', async (_, thunkAPI) =>

try {
const user = thunkAPI.getState().auth.user
const token = JSON.parse(user).token
const token = user.token
//console.log(token)

return await habitsService.getHabits(token)
Expand Down
129 changes: 129 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
background-color: #EFF2E5;
font-family: 'Inter', sans-serif;
color: #5F6739;
}

p {
line-height: 1.7;
}

.header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #DEE7C2;
padding: 20px;
margin-bottom: 30px;
}

.header ul {
display: flex;
align-items: center;
justify-content: space-between;
}

.header ul li {
margin-left: 20px;
list-style-type: none;
}

.header ul li a {
display: flex;
align-items: center;
}

.content {
padding: 40px;
}

.heading {
font-size: 2rem;
font-weight: 700;
margin-bottom: 50px;
}

.projection {
padding: 40px;
margin: 50px;
height: 400px;
width: 400px;
background-image: url('../public/co2_img.jpg');
background-position: center center;
background-size: cover;
}

.projection p, .projection h1 {
color: white;
}

.form-group {
margin-bottom: 10px;
}

.form-group input,
.form-group textarea,
.form-group select {
padding: 10px;
border: 1px solid #e6e6e6;
border-radius: 5px;
margin-bottom: 10px;
font-family: inherit;
}

button {
padding: 10px 20px;
border: 1px solid #5F6739;
border-radius: 5px;
background: #5F6739;
color: #fff;
font-size: 16px;
font-weight: 700;
cursor: pointer;
text-align: center;
appearance: button;
display: flex;
align-items: center;
justify-content: center;
}

button:hover {
transform: scale(0.98);
}

.loadingSpinnerContainer {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 5000;
display: flex;
justify-content: center;
align-items: center;
}

.loadingSpinner {
width: 64px;
height: 64px;
border: 8px solid;
border-color: #000 transparent #555 transparent;
border-radius: 50%;
animation: spin 1.2s linear infinite;
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
17 changes: 12 additions & 5 deletions frontend/src/pages/Goals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {useState, useEffect} from 'react'
import {useDispatch, useSelector} from 'react-redux'
import {submitGoals, getGoals} from '../features/goals/goalsSlice'
import {useNavigate} from 'react-router-dom'
import Spinner from '../components/Spinner'
//import sendData from '../features/ml/ml'

function Goals() {
Expand Down Expand Up @@ -45,20 +46,26 @@ function Goals() {
//console.log()
}

const {goals, isSuccess,} = useSelector((state) => (state.goals))
const {habits} = useSelector((state) => (state.habits))
const {goals, isSuccess, isLoading} = useSelector((state) => (state.goals))

const navigate = useNavigate()
useEffect(() => {
if (isSuccess) {
navigate('/')
//SendData(habits, goals)
}
}, [isSuccess, goals, habits, navigate])
}, [isSuccess, goals, navigate])

if (isLoading) {
<Spinner />
}


return (<>
return (<div className='content'>
<h1>Hi {name},</h1>
<h2>Please tell us how you want to change your habits</h2>
<p>Please type in your number of days going to work by car, carpooling, public transport and walking</p>


<section className="form">
<form onSubmit={onSubmit}>
Expand Down Expand Up @@ -117,7 +124,7 @@ function Goals() {
</div>
</form>
</section>
</>
</div>

)
}
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/pages/Habits.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {useSelector, useDispatch} from 'react-redux'
import {useState, useEffect} from 'react'
import { useNavigate } from "react-router-dom";
import {submitHabits, resetHabits} from '../features/habits/habitsSlice'
import Spinner from '../components/Spinner'

function Habits() {

Expand Down Expand Up @@ -48,7 +49,7 @@ function Habits() {
walk: walk_day
}

//console.log(habitsData)
console.log(habitsData)
dispatch(submitHabits(habitsData))

}
Expand All @@ -60,9 +61,14 @@ function Habits() {
}
}, [isSuccess, navigate])

return (<>
if (isLoading) {
<Spinner />
}

return (<div className='content'>
<h1>Hi {name},</h1>
<h2>Please tell us your transport habits</h2>
<p>Please type in your number of days going to work by car, carpooling, public transport and walking</p>

<section className="form">
<form onSubmit={onSubmit}>
Expand Down Expand Up @@ -123,7 +129,7 @@ function Habits() {
</section>


</>
</div>

)
}
Expand Down
24 changes: 14 additions & 10 deletions frontend/src/pages/Landing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,28 @@ function Landing() {

}

return (<>
return (<div className="content">

<h1>Welcome {name} to CarAIbou</h1>
<div>
<p>By 2028, if we do not take actions, the Green House Gas emissinos in Canada would be {ghg_before} million metric tons</p>
</div>
<h1 className='heading'>Welcome {name} to CarAIbou</h1>
<div className='projection'>
<p>By 2028, if we do not take actions, the Green House Gas emissinos in Canada would be</p>
<h1>{ghg_before}</h1>
<p>million metric tons</p>
</div>
{user ? (<div>{habits ? (<>

<div>
<p>By 2028, if everyone takes the same actions as you do, the Green House Gas emissinos in Canada would be {ghg_after} million metric tons</p>
<div className='projection'>
<p>By 2028, if everyone takes the same actions as you do, the Green House Gas emissinos in Canada would be</p>
<h1>{ghg_after}</h1>
<p>million metric tons</p>
</div>
</>) : (<div>
<h3>You have not tell us your transport habits and goals</h3>
<p>You have not tell us your transport habits and goals</p>
<button onClick={() => (navigate('/habits'))}>Set transport habits and goals</button>
</div>)}</div>) : (<h3>Please login or register first</h3>)}
</div>)}</div>) : (<p>Please login or register first</p>)}


</>
</div>

)
}
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {useSelector, useDispatch} from 'react-redux'
import { toast } from 'react-toastify'
import { useNavigate } from "react-router-dom";
import {login, resetAuth} from '../features/auth/authSlice'
import Spinner from '../components/Spinner'

function Login() {

Expand Down Expand Up @@ -58,8 +59,11 @@ function Login() {
}
}, [isSuccess, isRejected, message, navigate, dispatch])

if (isLoading) {
<Spinner />
}

return (<>
return (<div className='content'>
<section className='heading'>
<h1>
<FaSignInAlt /> Login
Expand Down Expand Up @@ -100,7 +104,7 @@ function Login() {
</div>
</form>
</section>
</>)
</div>)
}

export default Login
9 changes: 7 additions & 2 deletions frontend/src/pages/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {useSelector, useDispatch} from 'react-redux'
import { toast } from 'react-toastify'
import { useNavigate } from "react-router-dom";
import {register, reset} from '../features/auth/authSlice'
import Spinner from '../components/Spinner'


function Register() {
Expand Down Expand Up @@ -65,10 +66,14 @@ function Register() {

}
}, [isSuccess, isRejected, message, navigate, dispatch])

if (isLoading) {
<Spinner />
}



return (<>
return (<div className='content'>
<section className='heading'>
<h1>
<FaUser /> Register
Expand Down Expand Up @@ -142,7 +147,7 @@ function Register() {
</div>
</form>
</section>
</>)
</div>)
}

export default Register

0 comments on commit 8abb8ed

Please sign in to comment.