Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way for an new user to understand how the app functions #41

Merged
merged 18 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7755b00
feat: adding sample list route & page
bbland1 Sep 24, 2024
5e48804
mod: change SampleList to about
bbland1 Sep 25, 2024
78c3716
mod: a text version/skeleton of the about page of the application
bbland1 Sep 25, 2024
df82471
feat: added an unauthenticated home context with way to navigate to a…
bbland1 Sep 25, 2024
a6baa08
feat: added unauthenticated nav bar for another option on getting to …
bbland1 Sep 25, 2024
0c86ba2
feat: added links for app creators
bbland1 Sep 25, 2024
d664c2f
fix: fixed a few typos and add name to the place holder
bbland1 Sep 29, 2024
439089b
feat: created Authenticated/Unauthenticated home components
bbland1 Sep 29, 2024
7b5fd84
feat: update vite config to utilize the svgr plugin for the svg logo …
bbland1 Sep 29, 2024
73b1caf
feat: making it so the sign in button can change the value in the lab…
bbland1 Sep 29, 2024
d9bad0e
feat: added links to mentors and added link to the collab lab
bbland1 Sep 29, 2024
6acdbf4
fix: removed bullet point from the create list form label
bbland1 Sep 29, 2024
0406e98
Merge branch 'main' into bb/app-func-new-user
bbland1 Sep 29, 2024
34ca5e1
fix: fixing some buttons and styling issues weird messed up in resolv…
bbland1 Sep 29, 2024
859926a
fix: fixing the new UnauthenticatedNavBar to use the correct bootstra…
bbland1 Sep 29, 2024
810abab
fix: if signing up or out from about page properly redirects to home …
bbland1 Sep 29, 2024
8dd46ea
mod: added name to layout
bbland1 Sep 29, 2024
33ffcf1
fix: scroll bars on bottom of all pages because the page wasn't exten…
bbland1 Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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