Skip to content

Commit

Permalink
Merge pull request #120 from the-collab-lab/feature/mobile-footer-log…
Browse files Browse the repository at this point in the history
…-button-116

Feature/mobile footer log button 116
  • Loading branch information
flbarfield authored Apr 4, 2024
2 parents 49fdead + d0e0ff2 commit 0cfdd5a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/api/useAuth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import Button from '../components/Button.jsx';
* 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 = () => (
export const SignInButton = ({ className, value }) => (
<Button
className={className}
value={value}
text="Sign in"
type="button"
fn={() => signInWithPopup(auth, new GoogleAuthProvider())}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ export default function Button({
color,
fn,
testId,
buttonWidth,
}) {
return (
<button
className={className}
value={value}
type={type}
onClick={fn}
style={{ backgroundColor: color }}
style={{ backgroundColor: color, width: buttonWidth }}
data-testid={testId}
>
{text}
Expand Down
5 changes: 5 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ input:focus {
outline: var(--black);
}

.logIn,
.logOut {
font-size: 18px;
}

@media screen and (min-width: 780px) {
h1 {
font-size: 70px;
Expand Down
68 changes: 60 additions & 8 deletions src/views/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@ import { Outlet } from 'react-router-dom';

import './Layout.css';
import { auth } from '../api/config.js';
import { useAuth, SignInButton, SignOutButton } from '../api/useAuth.jsx';
import { useAuth } from '../api/useAuth.jsx';
import LoggedOut from '../components/LoggedOut.jsx';
import { useState } from 'react';
import Button from '../components/Button.jsx';
import { GoogleAuthProvider, signInWithPopup } from 'firebase/auth';

export function Layout() {
const initialWindowSize = window.innerWidth;

const { user } = useAuth();
const [isMobile, setIsMobile] = useState(
initialWindowSize < 780 ? true : false,
);

function windowSizeCheck() {
if (window.innerWidth < 780 && isMobile === false) {
setIsMobile(true);
}
if (window.innerWidth >= 780 && isMobile === true) {
setIsMobile(false);
}
}

window.addEventListener('resize', windowSizeCheck);

return (
<div className="Layout">
{!!user ? (
Expand All @@ -16,24 +36,56 @@ export function Layout() {
<h1>Smart shopping list</h1>
</a>

<div>
<span>Welcome, {auth.currentUser.displayName}</span>
</div>
<SignOutButton />
{!isMobile && (
<div>
<div>
<span>Welcome, {auth.currentUser.displayName}</span>
</div>
<Button
fn={() => auth.signOut()}
color={'yellow'}
className={'logOut'}
text={'Log Out'}
/>
</div>
)}
</header>
<main className="Layout-main">
<Outlet />
</main>
{isMobile && (
<Button
fn={() => auth.signOut()}
color={'yellow'}
className={'logOut'}
text={'Log Out'}
buttonWidth={'100%'}
/>
)}
</>
) : (
<>
<header className="Layout-header">
<h1>Smart shopping list</h1>
<div>
<SignInButton />
</div>
{!isMobile && (
<Button
fn={() => signInWithPopup(auth, new GoogleAuthProvider())}
color={'yellow'}
className={'logIn'}
text={'Log In'}
/>
)}
</header>
<LoggedOut />
{isMobile && (
<Button
fn={() => signInWithPopup(auth, new GoogleAuthProvider())}
color={'yellow'}
className={'logIn'}
text={'Log In'}
buttonWidth={'98%'}
/>
)}
</>
)}
</div>
Expand Down
1 change: 0 additions & 1 deletion src/views/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import './List.css';
import AddItemForm from '../components/AddItemForm';
import ShareForm from '../components/ShareForm';
import ListSearchItems from '../components/ListSearchItems';
import { SignOutButton } from '../api/useAuth';

export function List({ data, isShoppingListLoading, listPath, listName }) {
if (!listPath) {
Expand Down

0 comments on commit 0cfdd5a

Please sign in to comment.