Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
80 changes: 56 additions & 24 deletions src/components/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { useNavigate } from "react-router-dom";
import Dialog from "@mui/material/Dialog";
import CloseIcon from "@mui/icons-material/Close";
import "../styles/HomePage.css";
import { useAuth } from "../context/AuthContext";
import logo from "../assets/logo2.jpg";
import { useState } from "react";
import {
GoogleLogin,
type CredentialResponse,
} from "@react-oauth/google";
import { GoogleLogin, type CredentialResponse } from "@react-oauth/google";

const HomePage = () => {
const { user, signInWithGoogle } = useAuth();
const navigate = useNavigate();
const [loginOpen, setLoginOpen] = useState(false);
const [loginError, setLoginError] = useState("");

const closeLogin = () => {
setLoginOpen(false);
setLoginError("");
};

const handleGoogleSuccess = async (response: CredentialResponse) => {
if (!response.credential) {
setLoginError("Google did not return a login credential.");
Expand All @@ -22,6 +27,7 @@ const HomePage = () => {
try {
setLoginError("");
await signInWithGoogle(response.credential);
closeLogin();
navigate("/map");
} catch (error) {
console.error("Google sign-in failed:", error);
Expand All @@ -38,19 +44,13 @@ const HomePage = () => {
</div>

{!user && (
<div className="nav-google-login">
<GoogleLogin
onSuccess={handleGoogleSuccess}
onError={() =>
setLoginError("Google sign-in was cancelled or failed.")
}
shape="pill"
size="large"
text="signin_with"
theme="outline"
width="210"
/>
</div>
<button
className="nav-signin-button"
type="button"
onClick={() => setLoginOpen(true)}
>
Sign in
</button>
)}
</nav>

Expand Down Expand Up @@ -87,15 +87,47 @@ const HomePage = () => {
</button>
)}
</div>

{loginError && (
<p className="login-error" role="alert">
{loginError}
</p>
)}
</div>

</section>

<Dialog
open={loginOpen && !user}
onClose={closeLogin}
aria-labelledby="login-dialog-title"
aria-describedby="login-dialog-description"
slotProps={{ paper: { className: "login-dialog" } }}
>
<button
className="login-dialog-close"
type="button"
aria-label="Close sign in dialog"
onClick={closeLogin}
>
<CloseIcon fontSize="small" />
</button>
<h2 id="login-dialog-title">Sign in to GeoGallery</h2>
<p id="login-dialog-description">
Welcome back! Please sign in to continue.
</p>
<div className="login-dialog-provider">
<GoogleLogin
onSuccess={handleGoogleSuccess}
onError={() =>
setLoginError("Google sign-in failed. Please try again.")
}
shape="pill"
size="large"
text="continue_with"
theme="outline"
width="260"
/>
</div>
{loginError && (
<p className="login-error" role="alert">
{loginError}
</p>
)}
</Dialog>
</main>
);
};
Expand Down
82 changes: 70 additions & 12 deletions src/styles/HomePage.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,8 @@
margin-top: 34px;
}

.nav-google-login {
display: flex;
align-items: center;
justify-content: flex-end;
}

.login-error {
margin: 14px 0 0;
color: #ffb4b4;
font-size: 14px;
}

.explore-button,
.nav-signin-button,
.guest-link {
font-family: var(--calistoga);
cursor: pointer;
Expand All @@ -156,6 +145,75 @@
box-shadow: 0 18px 34px rgba(76, 202, 237, 0.26);
}

.nav-signin-button {
padding: 11px 20px;
border: 1px solid rgba(246, 251, 255, 0.3);
border-radius: 8px;
background: rgba(255, 255, 255, 0.08);
color: #f6fbff;
font-size: 14px;
}

.nav-signin-button:hover {
background: rgba(255, 255, 255, 0.16);
transform: translateY(-2px);
}

.login-dialog {
position: relative;
width: min(380px, calc(100vw - 32px));
margin: 16px;
padding: 36px 28px 32px;
border-radius: 18px !important;
background: #f9fcfd !important;
color: #17252d;
text-align: center;
}

.login-dialog-close {
position: absolute;
top: 12px;
right: 12px;
width: 34px;
height: 34px;
display: grid;
place-items: center;
border: 0;
border-radius: 8px;
background: transparent;
color: #64757c;
cursor: pointer;
}

.login-dialog-close:hover {
background: #edf3f5;
color: #17252d;
}

.login-dialog h2 {
margin: 0;
font-family: var(--calistoga);
font-size: 26px;
font-weight: 400;
}

.login-dialog > p {
margin: 10px 0 0;
color: #63767f;
font-size: 14px;
line-height: 1.5;
}

.login-dialog-provider {
display: flex;
justify-content: center;
margin-top: 28px;
}

.login-dialog .login-error {
color: #a33f3f;
}

.guest-link {
border: 1px solid rgba(246, 251, 255, 0.2);
background: rgba(255, 255, 255, 0.08);
Expand Down
Loading