diff --git a/src/blog/Blog.tsx b/src/blog/Blog.tsx index 7bd502b..d3b3e9c 100644 --- a/src/blog/Blog.tsx +++ b/src/blog/Blog.tsx @@ -2,16 +2,22 @@ import * as React from 'react'; import CssBaseline from '@mui/material/CssBaseline'; import Container from '@mui/material/Container'; import Box from '@mui/material/Box'; +import Button from '@mui/material/Button'; import AppTheme from '../shared-theme/AppTheme'; import MainContent from './components/MainContent'; import Article from './components/Article'; import Latest from './components/Latest'; import Footer from './components/Footer'; +import Login from './components/Login'; import { useArticles } from './providers/Article'; +import { useAuth } from './providers/Author'; export default function Blog(props: { disableCustomTheme?: boolean }) { const { articles, loading, error } = useArticles(); + const { currentUser } = useAuth(); + const [selectedArticle, setSelectedArticle] = React.useState(null); + const [showLogin, setShowLogin] = React.useState(false); const handleSelectArticle = (index: number) => { setSelectedArticle(index); @@ -20,6 +26,13 @@ export default function Blog(props: { disableCustomTheme?: boolean }) { const handleBack = () => setSelectedArticle(null); + const handleShowLogin = () => { + setShowLogin(true); + window.scrollTo({ top: 0, behavior: 'smooth' }); + }; + + const handleHideLogin = () => setShowLogin(false); + if (loading) { return ( @@ -64,13 +77,7 @@ export default function Blog(props: { disableCustomTheme?: boolean }) { - + - {selectedArticle === null ? ( + {showLogin ? ( + + ) : selectedArticle === null ? ( <> - + {!currentUser && ( + + + + )} + + { - // Optional pagination call - }} + onLoadMore={async () => {}} /> ) : ( @@ -102,7 +114,7 @@ export default function Blog(props: { disableCustomTheme?: boolean }) { )} - {selectedArticle === null && ( + {selectedArticle === null && !showLogin && ( void; +} + +export default function Login({ onBack }: LoginProps) { + const { login, loading, error, currentUser } = useAuth(); + const [username, setUsername] = React.useState(''); + const [password, setPassword] = React.useState(''); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + await login(username, password); + }; + + if (currentUser) { + // ✅ if logged in, auto-return to the article list + onBack(); + return null; + } + + return ( + + + + + + + Sign In + + + + Please log in to continue + + +
+ setUsername(e.target.value)} + required + /> + setPassword(e.target.value)} + required + /> + + {error && ( + + {error} + + )} + + + +
+ ); +}