- using nanoevents as event emitter

- bug: createResumeModal opens twice
This commit is contained in:
Amruth Pillai
2020-07-06 14:47:05 +05:30
parent 6d3e5823fc
commit dbb005d26c
11 changed files with 1183 additions and 784 deletions

View File

@ -1,15 +1,23 @@
import React, { useState, useContext, Fragment } from "react";
import BaseModal from "./BaseModal";
import { navigate } from "gatsby";
import React, { Fragment, useContext, useEffect, useState } from "react";
import Button from "../components/shared/Button";
import ModalContext from "../contexts/ModalContext";
import UserContext from "../contexts/UserContext";
import { navigate } from "gatsby";
import BaseModal from "./BaseModal";
const AuthModal = () => {
const [open, setOpen] = useState(false);
const [isLoading, setLoading] = useState(false);
const { authModal } = useContext(ModalContext);
const { emitter, events } = useContext(ModalContext);
const { user, loginWithGoogle, logout } = useContext(UserContext);
useEffect(() => {
const unbind = emitter.on(events.AUTH_MODAL, () => setOpen(true));
return () => unbind();
}, [emitter, events]);
const handleSignInWithGoogle = async () => {
setLoading(true);
await loginWithGoogle();
@ -18,7 +26,7 @@ const AuthModal = () => {
const handleGotoApp = () => {
navigate("/app/dashboard");
authModal.setOpen(false);
setOpen(false);
};
const getTitle = () =>
@ -46,7 +54,7 @@ const AuthModal = () => {
return (
<BaseModal
state={authModal}
state={[open, setOpen]}
title={getTitle()}
action={user ? loggedInAction : loggedOutAction}
>