generated from the-collab-lab/smart-shopping-list
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from the-collab-lab/am-create-landing-page
- Loading branch information
Showing
7 changed files
with
293 additions
and
218 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* The `env()` function used in this block of code | ||
* allows us to reference special variables that might be defined | ||
* by certain browsers. In this case, we are making sure that | ||
* the app stays within the 'safe' viewable area of a mobile phone, | ||
* and isn't covered up by the phone's UI. | ||
* | ||
* @see: https://developer.mozilla.org/en-US/docs/Web/CSS/env | ||
*/ | ||
.Home { | ||
display: flex; | ||
flex-direction: column; | ||
height: 100dvh; | ||
} | ||
|
||
.Home > * { | ||
padding-inline: min(5dvw, 3.2rem); | ||
} | ||
|
||
.Home-header { | ||
background-color: var(--color-bg); | ||
padding-bottom: 0.5rem; | ||
padding-top: max(env(safe-area-inset-top), 1rem); | ||
text-align: center; | ||
} | ||
|
||
.Home-header > h1 { | ||
margin: 0; | ||
} | ||
|
||
.checkbox { | ||
height: 200px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,40 @@ | ||
import './Home.css'; | ||
import { useState } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { SingleList } from '../components'; | ||
import { createList } from '../api/firebase'; | ||
|
||
export function Home({ data, setListPath, user }) { | ||
const [shoppingListName, setShoppingListName] = useState(''); | ||
const navigate = useNavigate(); // useNavigate doc suggests using redirect | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
try { | ||
const newListPath = await createList( | ||
user.uid, | ||
user.email, | ||
shoppingListName, | ||
); | ||
setListPath(newListPath); | ||
alert('You have created a new shopping list: ' + shoppingListName); | ||
navigate('/list'); | ||
} catch (error) { | ||
alert(`Your list was not created, please try again. Error: ${error}`); | ||
} | ||
}; | ||
import { useAuth, SignInButton, SignOutButton } from '../api/useAuth.jsx'; | ||
import { auth } from '../api/config.js'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
export function Home() { | ||
const { user } = useAuth(); | ||
return ( | ||
<div className="Home"> | ||
<p> | ||
Hello from the home (<code>/</code>) page! | ||
</p> | ||
<ul> | ||
{data && data.length > 0 ? ( | ||
data.map((list) => ( | ||
<SingleList | ||
key={list.name} | ||
name={list.name} | ||
setListPath={setListPath} | ||
path={list.path} | ||
/> | ||
)) | ||
) : ( | ||
<h1>You have no Lists!</h1> | ||
)} | ||
</ul> | ||
<form onSubmit={handleSubmit}> | ||
<label> | ||
Shopping List: | ||
<input | ||
type="text" | ||
value={shoppingListName} | ||
id="shopping-list" | ||
onChange={(e) => setShoppingListName(e.target.value)} | ||
></input> | ||
</label> | ||
<input type="submit" /> | ||
</form> | ||
</div> | ||
<> | ||
<div className="Home"> | ||
<header className="Home-header"> | ||
<h2>Welcome to Box Makers!</h2> | ||
<img | ||
className="checkbox" | ||
src="img/checkbox.png" | ||
alt="black checkbox with green check" | ||
/> | ||
<h3> | ||
New to the app? Click <Link to="/about">here</Link> to learn more! | ||
</h3> | ||
{!!user ? ( | ||
<div> | ||
<span>Welcome back {auth.currentUser.displayName}!</span> ( | ||
<SignOutButton />) | ||
<br /> | ||
<span> | ||
View your lists <Link to="/list">here</Link> | ||
</span> | ||
</div> | ||
) : ( | ||
<div> | ||
<span>Click 'Sign In' to register and get started: </span> | ||
<SignInButton /> | ||
</div> | ||
)} | ||
</header> | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.