Skip to content

Commit

Permalink
A way for an new user to understand how the app functions (#41)
Browse files Browse the repository at this point in the history
* feat: adding sample list route & page

* mod: change SampleList to about

* mod: a text version/skeleton of the about page of the application

* feat: added an unauthenticated home context with way to navigate to about page with button

* feat: added unauthenticated nav bar for another option on getting to about page

* feat: added links for app creators

* fix: fixed a few typos and add name to the place holder

* feat: created Authenticated/Unauthenticated home components

* feat: update vite config to utilize the svgr plugin for the svg logo used on about

* feat: making it so the sign in button can change the value in the label based on if needs to sign  up or in

* feat: added links to mentors and added link to the collab lab

* fix: removed bullet point from the create list form label

* fix: fixing some buttons and styling issues weird messed up in resolving merge conflicts

* fix: fixing the new UnauthenticatedNavBar to use the correct bootstrap comp since didn't get them in conflict resolve

* fix: if signing up or out from about page properly redirects to home page since it is not a protected route it was just staying on about

* mod: added name to layout

* fix: scroll bars on bottom of all pages because the page wasn't extend to the view fully and they were always showing
  • Loading branch information
bbland1 authored Sep 30, 2024
1 parent fceec4b commit a97e76b
Show file tree
Hide file tree
Showing 17 changed files with 360 additions and 69 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
crossorigin="anonymous"
/>
<meta name="color-scheme" content="dark light" />
<title>Smart Shopping List</title>
<title>GrocerEase</title>
<script type="module" src="/src/index.tsx" async></script>
</head>
<body>
Expand Down
6 changes: 5 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/// <reference types="vite-plugin-svgr/client" />

import React from "react";

import { Routes, Route } from "react-router-dom";

import { Home, Layout, List, ManageList, PageNotFound } from "./views";
import { Home, Layout, List, ManageList, PageNotFound, About } from "./views";

import { useFindUser, useShoppingListData, useShoppingLists } from "./api";

Expand Down Expand Up @@ -74,6 +76,8 @@ export function App() {
/>
</Route>

<Route path="/about" element={<About />}></Route>

{/* a catch all route for if someone tries to manually navigate to something not created yet */}
<Route path="*" element={<PageNotFound />} />
</Route>
Expand Down
62 changes: 50 additions & 12 deletions src/api/useAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,72 @@ import { GoogleAuthProvider, signInWithPopup } from "firebase/auth";
import { addUserToDatabase, User } from "./firebase";
import toast from "react-hot-toast";
import Button from "react-bootstrap/Button";
import { useLocation, useNavigate } from "react-router-dom";

/**
* A button that signs the user in using Google OAuth. When clicked,
* the button redirects the user to the Google OAuth sign-in page.
* After the user signs in, they are redirected back to the app.
*/
export const SignInButton = () => (
<Button
type="button"
onClick={() => signInWithPopup(auth, new GoogleAuthProvider())}
>
Sign In
</Button>
);

type SignInButtonProps = {
isSignIn?: boolean;
};

export const SignInButton = ({ isSignIn = true }: SignInButtonProps) => {
const location = useLocation();
const navigate = useNavigate();

return (
<Button
type="button"
onClick={() => {
signInWithPopup(auth, new GoogleAuthProvider())
.then(() => {
if (location.pathname === "/about") {
navigate("/");
}
})
.catch((error) => {
console.error(error);
toast.error(
"An error occurred while signing in. Please try again.",
);
});
}}
className="m-2"
>
{isSignIn ? "Sign In" : "Sign Up"}
</Button>
);
};

/**
* A button that signs the user out of the app using Firebase Auth.
*/
export const SignOutButton = () => {
const location = useLocation();
const navigate = useNavigate();

return (
<Button
type="button"
onClick={() => {
auth.signOut().catch((error) => {
console.error(error);
toast.error("An error occurred while signing out. Please try again.");
});
auth
.signOut()
.then(() => {
if (location.pathname === "/about") {
navigate("/");
}
})
.catch((error) => {
console.error(error);
toast.error(
"An error occurred while signing out. Please try again.",
);
});
}}
className="m-2"
>
Sign Out
</Button>
Expand Down
38 changes: 20 additions & 18 deletions src/components/CreateList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,25 @@ export function CreateList({ user, setListPath }: Props) {
};

return (
<Form onSubmit={handleSubmit}>
<h3>Create New Shopping List</h3>
<Form.Label htmlFor="newListName">Name Your List</Form.Label>
<InputGroup>
<br />
<Form.Control
type="text"
value={inputValue}
onChange={handleChange}
name="newListName"
id="newListName"
aria-label="Shopping List Name"
aria-required="true" // Indicates that this field is required
/>
<br />
<Button aria-label="Create new shopping list">Create List</Button>
</InputGroup>
</Form>
<>
<Form onSubmit={handleSubmit}>
<h3>Create New Shopping List</h3>
<Form.Label htmlFor="newListName">Name Your List</Form.Label>
<InputGroup>
<br />
<Form.Control
type="text"
value={inputValue}
onChange={handleChange}
name="newListName"
id="newListName"
aria-label="Shopping List Name"
aria-required="true" // Indicates that this field is required
/>
<br />
<Button aria-label="Create new shopping list">Create List</Button>
</InputGroup>
</Form>
</>
);
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import { NavLink } from "react-router-dom";
import { SignOutButton } from "../api";
import { SignOutButton } from "../../api";
import Navbar from "react-bootstrap/Navbar";
import Container from "react-bootstrap/Container";
import Nav from "react-bootstrap/Nav";

import "./AuthenticatedNavBar.css";
import "../NavBar.css";

export function AuthenticatedNavBar() {
return (
Expand Down
3 changes: 2 additions & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export * from "./ListItem";
export * from "./SingleList";
export * from "./CreateList";
export * from "./ProtectedRoute";
export * from "./AuthenticatedNavBar";
export * from "./authenticated/AuthenticatedNavBar";
export * from "./forms/ShareListForm";
export * from "./unauthenticated/UnauthenticatedNavBar";
27 changes: 27 additions & 0 deletions src/components/unauthenticated/UnauthenticatedNavBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import { NavLink } from "react-router-dom";
import Navbar from "react-bootstrap/Navbar";
import Container from "react-bootstrap/Container";
import Nav from "react-bootstrap/Nav";

import "../NavBar.css";

export function UnauthenticatedNavBar() {
return (
<Navbar expand="lg" fixed="bottom" className="Nav">
<Container className="d-flex justify-content-around Nav-container">
<Nav.Link as={NavLink} to="/" className="Nav-link" aria-label="Home">
Home
</Nav.Link>
<Nav.Link
as={NavLink}
to="/about"
className="Nav-link"
aria-label="About"
>
About
</Nav.Link>
</Container>
</Navbar>
);
}
10 changes: 10 additions & 0 deletions src/icons/GithubLogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/icons/LinkedInLogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 7 additions & 20 deletions src/views/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import "./Home.css";
import { SingleList, CreateList } from "../components";
import { List, User } from "../api/firebase";
import { List, User } from "../api";
import { AuthenticatedHome, UnauthenticatedHome } from "../views";

interface Props {
data: List[];
Expand All @@ -12,24 +12,11 @@ interface Props {
export function Home({ data, setListPath, user }: Props) {
return (
<>
<div className="Home">
<p>
Hello from the home (<code>/</code>) page!
</p>
{user && (
<ul>
{data.map((list, index) => (
<SingleList
key={index}
name={list.name}
path={list.path}
setListPath={setListPath}
/>
))}
<CreateList user={user} setListPath={setListPath} />
</ul>
)}
</div>
{user ? (
<AuthenticatedHome data={data} setListPath={setListPath} user={user} />
) : (
<UnauthenticatedHome />
)}
</>
);
}
38 changes: 25 additions & 13 deletions src/views/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react";
import { Outlet } from "react-router-dom";
import { SignInButton, User } from "../api";
import { AuthenticatedNavBar } from "../components";
import { Outlet, useNavigate } from "react-router-dom";
import { User } from "../api";
import { AuthenticatedNavBar, UnauthenticatedNavBar } from "../components";
import Button from "react-bootstrap/Button";

import "./Layout.css";

Expand All @@ -10,16 +11,27 @@ interface Props {
}

export function Layout({ user }: Props) {
const navigate = useNavigate();
return (
<div className="Layout vh-100">
<header className="Layout-header">
<h1>Smart shopping list</h1>
</header>
<main className="Layout-main overflow-scroll">
<Outlet />
{!user && <SignInButton />}
</main>
{user && <AuthenticatedNavBar />}
</div>
<>
<div className="Layout vh-100">
<header className="Layout-header">
<h1>GrocerEase</h1>
</header>
<main className="Layout-main overflow-auto">
{user && (
<Button
onClick={() => navigate("/about")}
aria-label="Navigate to the about application page."
className="m-2"
>
about
</Button>
)}
<Outlet />
</main>
{user ? <AuthenticatedNavBar /> : <UnauthenticatedNavBar />}
</div>
</>
);
}
34 changes: 34 additions & 0 deletions src/views/authenticated/AuthenticatedHome.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";
import { SingleList, CreateList } from "../../components";
import { List, User } from "../../api";

interface Props {
data: List[];
setListPath: (path: string) => void;
user: User | null;
}

export function AuthenticatedHome({ data, setListPath, user }: Props) {
return (
<>
<p>
Hello from the home (<code>/</code>) page!
</p>
{user && (
<>
<ul>
{data.map((list, index) => (
<SingleList
key={index}
name={list.name}
path={list.path}
setListPath={setListPath}
/>
))}
</ul>
<CreateList user={user} setListPath={setListPath} />
</>
)}
</>
);
}
3 changes: 3 additions & 0 deletions src/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ export * from "./Home";
export * from "./Layout";
export * from "./authenticated/List";
export * from "./unauthenticated/PageNotFound";
export * from "./unauthenticated/About";
export * from "./unauthenticated/UnauthenticatedHome";
export * from "./authenticated/AuthenticatedHome";
Loading

0 comments on commit a97e76b

Please sign in to comment.