Skip to content

Commit

Permalink
Merge branch 'main' into feature/button-hover
Browse files Browse the repository at this point in the history
  • Loading branch information
aberger3647 committed Apr 5, 2024
2 parents 06488a4 + 0cfdd5a commit cf96138
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export function App() {
<Home
data={listsData}
areListsLoading={areListsLoading}
setListPath={setListPath}
listPath={listPath}
setListPath={setListPath}
listName={listName}
exact
/>
Expand Down
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
25 changes: 11 additions & 14 deletions src/components/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ export default function Button({
color,
fn,
testId,
buttonWidth,
}) {
return (
<div class="buttonContainer">
<span className="buttonBack"></span>

<button
className={className}
value={value}
type={type}
onClick={fn}
style={{ backgroundColor: color }}
data-testid={testId}
>
{text}
</button>
</div>
<button
className={className}
value={value}
type={type}
onClick={fn}
style={{ backgroundColor: color, width: buttonWidth }}
data-testid={testId}
>
{text}
</button>
);
}
7 changes: 4 additions & 3 deletions src/components/SelectListForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import Button from './Button';

export default function SelectListForm({
data,
listPath,
areListsLoading,
setListPath,
listName,
}) {
const [selectedList, setSelectedList] = useState('');
const initialListState = listName ? listName : 'Select a list';
const [selectedList, setSelectedList] = useState(initialListState);
const navigate = useNavigate();
const handleSelectChange = (e) => {
const input = e.target.value;
Expand All @@ -21,12 +22,12 @@ export default function SelectListForm({
<div>Loading lists...</div>
) : (
<div>
<label htmlFor="listSelector">Select List</label>
<select
id="listSelector"
value={selectedList}
onChange={handleSelectChange}
>
<option>{selectedList}</option>
{data.map((data) => {
return (
<option key={data.path} value={data.path}>
Expand Down
5 changes: 5 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ input:focus {
outline: var(--black);
}

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

@media screen and (min-width: 780px) {
h1 {
font-size: 70px;
Expand Down
2 changes: 1 addition & 1 deletion src/views/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export function Home({

<SelectListForm
data={data}
listPath={listPath}
areListsLoading={areListsLoading}
setListPath={setListPath}
listName={listName}
/>
</div>
);
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 cf96138

Please sign in to comment.