This commit is contained in:
2023-03-19 16:41:52 -04:00
parent f6e2b445d7
commit 8a3d0fa49b
4 changed files with 26 additions and 22 deletions

View File

@@ -7,11 +7,14 @@ const MyNavbar = () => {
const { currentUser } = useContext(UserContext);
const MyLink = ({ children, ...rest }) => {
return <Nav.Link as={Link} {...rest}>{children}</Nav.Link>;
return (
<Nav.Link as={Link} {...rest}>
{children}
</Nav.Link>
);
};
return (
<React.Fragment>
<Navbar variant="dark" bg="dark" expand="lg">
<Container>
<Navbar.Brand href="/">LearningTree</Navbar.Brand>
@@ -19,14 +22,13 @@ const MyNavbar = () => {
<Navbar.Collapse id="navbar-nav">
<Nav className="ms-auto">
<MyLink href="/">Home</MyLink>
{(currentUser?.id && (
<MyLink href="/logout">Logout</MyLink>
)) || <MyLink href="/login">Login</MyLink>}
{(currentUser?.id && <MyLink href="/logout">Logout</MyLink>) || (
<MyLink href="/login">Login</MyLink>
)}
</Nav>
</Navbar.Collapse>
</Container>
</Navbar>
</React.Fragment>
);
};

View File

@@ -1,4 +1,4 @@
import { useContext, useEffect } from "react";
import { useContext } from "react";
import { Container } from "react-bootstrap";
import MyNavbar from "../components/MyNavbar";
import UserContext from "../contexts/UserContext";

View File

@@ -1,6 +1,6 @@
import React, { useContext, useEffect, useState } from "react";
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 UserContext from "../contexts/UserContext";
import { makeRequest } from "../utils.ts";
@@ -11,6 +11,7 @@ const LoginPage = () => {
const [error, setError] = useState(null);
const { currentUser, setCurrentUser } = useContext(UserContext);
const [location, setLocation] = useLocation();
useEffect(() => {
if (currentUser?.id) {
@@ -19,7 +20,7 @@ const LoginPage = () => {
}, [currentUser]);
const gotoHome = () => {
window.location.href = "/";
setLocation("/");
};
const sendLoginRequest = async (e) => {

View File

@@ -1,6 +1,6 @@
import React, { useState } from "react";
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 { makeRequest } from "../utils.ts";
@@ -12,6 +12,7 @@ const RegisterPage = () => {
const [password2, setPassword2] = useState("");
const [error, setError] = useState(null);
const [location, setLocation] = useLocation();
const sendRegisterRequest = (e) => {
e?.preventDefault();
@@ -32,7 +33,7 @@ const RegisterPage = () => {
setError(data);
return;
}
window.location.href = "/login";
setLocation("/login");
});
};