Compare commits
1 Commits
8a3d0fa49b
...
d05e0fb0e0
| Author | SHA1 | Date | |
|---|---|---|---|
|
d05e0fb0e0
|
@@ -7,26 +7,28 @@ const MyNavbar = () => {
|
|||||||
const { currentUser } = useContext(UserContext);
|
const { currentUser } = useContext(UserContext);
|
||||||
|
|
||||||
const MyLink = ({ children, ...rest }) => {
|
const MyLink = ({ children, ...rest }) => {
|
||||||
return <Nav.Link as={Link} {...rest}>{children}</Nav.Link>;
|
return (
|
||||||
|
<Nav.Link as={Link} {...rest}>
|
||||||
|
{children}
|
||||||
|
</Nav.Link>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<Navbar variant="dark" bg="dark" expand="lg">
|
||||||
<Navbar variant="dark" bg="dark" expand="lg">
|
<Container>
|
||||||
<Container>
|
<Navbar.Brand as={Link} href="/">LearningTree</Navbar.Brand>
|
||||||
<Navbar.Brand href="/">LearningTree</Navbar.Brand>
|
<Navbar.Toggle aria-controls="navbar-nav" />
|
||||||
<Navbar.Toggle aria-controls="navbar-nav" />
|
<Navbar.Collapse id="navbar-nav">
|
||||||
<Navbar.Collapse id="navbar-nav">
|
<Nav className="ms-auto">
|
||||||
<Nav className="ms-auto">
|
<MyLink href="/">Home</MyLink>
|
||||||
<MyLink href="/">Home</MyLink>
|
{(currentUser?.id && <MyLink href="/logout">Logout</MyLink>) || (
|
||||||
{(currentUser?.id && (
|
<MyLink href="/login">Login</MyLink>
|
||||||
<MyLink href="/logout">Logout</MyLink>
|
)}
|
||||||
)) || <MyLink href="/login">Login</MyLink>}
|
</Nav>
|
||||||
</Nav>
|
</Navbar.Collapse>
|
||||||
</Navbar.Collapse>
|
</Container>
|
||||||
</Container>
|
</Navbar>
|
||||||
</Navbar>
|
|
||||||
</React.Fragment>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useContext, useEffect } from "react";
|
import { useContext } from "react";
|
||||||
import { Container } from "react-bootstrap";
|
import { Container } from "react-bootstrap";
|
||||||
import MyNavbar from "../components/MyNavbar";
|
import MyNavbar from "../components/MyNavbar";
|
||||||
import UserContext from "../contexts/UserContext";
|
import UserContext from "../contexts/UserContext";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useContext, useEffect, useState } from "react";
|
import React, { useContext, useEffect, useState } from "react";
|
||||||
import { Button, Col, Container, Form, Row, Alert } from "react-bootstrap";
|
import { Button, Col, Container, Form, Row, Alert } from "react-bootstrap";
|
||||||
import { Link } from "wouter";
|
import { Link, useLocation } from "wouter";
|
||||||
import MyNavbar from "../components/MyNavbar";
|
import MyNavbar from "../components/MyNavbar";
|
||||||
import UserContext from "../contexts/UserContext";
|
import UserContext from "../contexts/UserContext";
|
||||||
import { makeRequest } from "../utils.ts";
|
import { makeRequest } from "../utils.ts";
|
||||||
@@ -11,6 +11,7 @@ const LoginPage = () => {
|
|||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
const { currentUser, setCurrentUser } = useContext(UserContext);
|
const { currentUser, setCurrentUser } = useContext(UserContext);
|
||||||
|
const [location, setLocation] = useLocation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentUser?.id) {
|
if (currentUser?.id) {
|
||||||
@@ -19,7 +20,7 @@ const LoginPage = () => {
|
|||||||
}, [currentUser]);
|
}, [currentUser]);
|
||||||
|
|
||||||
const gotoHome = () => {
|
const gotoHome = () => {
|
||||||
window.location.href = "/";
|
setLocation("/");
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendLoginRequest = async (e) => {
|
const sendLoginRequest = async (e) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { Button, Col, Container, Form, Row, Alert } from "react-bootstrap";
|
import { Button, Col, Container, Form, Row, Alert } from "react-bootstrap";
|
||||||
import { Link } from "wouter";
|
import { Link, useLocation } from "wouter";
|
||||||
import MyNavbar from "../components/MyNavbar";
|
import MyNavbar from "../components/MyNavbar";
|
||||||
import { makeRequest } from "../utils.ts";
|
import { makeRequest } from "../utils.ts";
|
||||||
|
|
||||||
@@ -12,6 +12,7 @@ const RegisterPage = () => {
|
|||||||
const [password2, setPassword2] = useState("");
|
const [password2, setPassword2] = useState("");
|
||||||
|
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
const [location, setLocation] = useLocation();
|
||||||
|
|
||||||
const sendRegisterRequest = (e) => {
|
const sendRegisterRequest = (e) => {
|
||||||
e?.preventDefault();
|
e?.preventDefault();
|
||||||
@@ -32,7 +33,7 @@ const RegisterPage = () => {
|
|||||||
setError(data);
|
setError(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window.location.href = "/login";
|
setLocation("/login");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user