add: logout functionality in larger devices

- add logout functionality in devices with width > 1024px
This commit is contained in:
sushant dhimal 2023-03-16 14:25:52 +05:45
parent 07697f7ae1
commit 0d92da9446
3 changed files with 45 additions and 3 deletions

View File

@ -1,13 +1,28 @@
import React from "react";
import React, { useContext } from "react";
import { signOut } from "firebase/auth";
import { auth } from "../firebase.config";
import { AuthContext } from "../context/AuthContext";
const NavLinks = ({ svg, link, text, setChatLog }) => {
const handleClick = (text) => {
const { dispatch } = useContext(AuthContext);
const handleClick = async (text) => {
if (text === "Clear Conversations") setChatLog([]);
if (text === "Log out") {
try {
let logOut = await signOut(auth);
console.log("logOut", logOut);
dispatch({ type: "LOGOUT" });
} catch (error) {
console.log("error happen during sign out", error);
}
}
};
return (
<a
href={link}
target="_blank"
target={link && "_blank"}
rel="noreferrer"
style={{ textDecoration: "none" }}
onClick={() => handleClick(text)}

View File

@ -12,6 +12,11 @@ function AuthReducer(state, action) {
currentUser: action.payload,
};
}
case "LOGOUT": {
return {
currentUser: "",
};
}
default: {
return state;
}

View File

@ -91,6 +91,7 @@ const Home = () => {
</div>
<h1>TalkBot</h1>
</header>
{showMenu && (
<nav>
<div className="navItems">
@ -225,6 +226,27 @@ const Home = () => {
text="Updates & FAQ"
link="https://help.openai.com/en/collections/3742473-chatgpt"
/>
<NavLinks
svg={
<svg
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
width={25}
height={25}
>
<path
d="m16 17 5-5m0 0-5-5m5 5H9m0-9H7.8c-1.68 0-2.52 0-3.162.327a3 3 0 0 0-1.311 1.311C3 5.28 3 6.12 3 7.8v8.4c0 1.68 0 2.52.327 3.162a3 3 0 0 0 1.311 1.311C5.28 21 6.12 21 7.8 21H9"
stroke="#fff"
strokeWidth={2}
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
}
text="Log out"
link=""
/>
</aside>
<section className="chatBox">