diff --git a/components/cart/CartSidebarView/CartSidebarView.tsx b/components/cart/CartSidebarView/CartSidebarView.tsx index 11d24d234..f392a0890 100644 --- a/components/cart/CartSidebarView/CartSidebarView.tsx +++ b/components/cart/CartSidebarView/CartSidebarView.tsx @@ -1,11 +1,11 @@ import React, { FunctionComponent } from "react"; // import s from "./CartSidebarView.module.css"; import { Button } from "@components/ui"; -import { Trash } from "@components/icon"; +import { Trash, Cross } from "@components/icon"; +import { useUI } from "@components/ui/context"; -interface Props {} - -const CartSidebarView: FunctionComponent = () => { +const CartSidebarView: FunctionComponent = () => { + const { dispatch } = useUI(); return ( <>
@@ -17,22 +17,11 @@ const CartSidebarView: FunctionComponent = () => {
diff --git a/components/core/Layout/Layout.tsx b/components/core/Layout/Layout.tsx index 0ea64d4bf..aa22d3d52 100644 --- a/components/core/Layout/Layout.tsx +++ b/components/core/Layout/Layout.tsx @@ -13,7 +13,7 @@ interface Props { const Layout: FunctionComponent = ({ className, children }) => { const rootClassName = cn(s.root, className); - // const { displaySidebar } = useUI(); + const { displaySidebar } = useUI(); return ( = ({ className, children }) => { />
{children}
- {/* {displaySidebar && ( + {displaySidebar && ( - )} */} + )}
); }; diff --git a/components/core/Navbar/Navbar.tsx b/components/core/Navbar/Navbar.tsx index e849205d3..5ac0c93bd 100644 --- a/components/core/Navbar/Navbar.tsx +++ b/components/core/Navbar/Navbar.tsx @@ -4,6 +4,7 @@ import s from "./Navbar.module.css"; import { Logo, Container } from "@components/ui"; import { Avatar, Searchbar } from "@components/core"; import { Heart, Bag } from "@components/icon"; +import { useUI } from "@components/ui/context"; interface Props { className?: string; children?: any; @@ -11,6 +12,10 @@ interface Props { const Navbar: FunctionComponent = ({ className }) => { const rootClassName = cn(s.root, className); + const { dispatch } = useUI(); + + const handleCartClick = () => dispatch("OPEN_SIDEBAR"); + return ( @@ -23,7 +28,7 @@ const Navbar: FunctionComponent = ({ className }) => { diff --git a/components/icon/Cross.tsx b/components/icon/Cross.tsx new file mode 100644 index 000000000..cff53612d --- /dev/null +++ b/components/icon/Cross.tsx @@ -0,0 +1,16 @@ +import React from "react"; + +const Cross = ({ ...props }) => { + return ( + + + + ); +}; + +export default Cross; diff --git a/components/icon/index.ts b/components/icon/index.ts index e354c1755..2dc7ced7c 100644 --- a/components/icon/index.ts +++ b/components/icon/index.ts @@ -1,3 +1,4 @@ export { default as Bag } from "./Bag"; export { default as Heart } from "./Heart"; export { default as Trash } from "./Trash"; +export { default as Cross } from "./Cross"; diff --git a/components/ui/context.tsx b/components/ui/context.tsx index 0ac416e4d..9b1a1ede4 100644 --- a/components/ui/context.tsx +++ b/components/ui/context.tsx @@ -1,15 +1,16 @@ import React, { Context, FunctionComponent } from "react"; -export interface ContextType { - displaySidebar: boolean; -} - const initialState = { displaySidebar: false, + dispatch: null, }; +export interface UIState { + displaySidebar: boolean; + dispatch: (string) => void; +} function uiReducer(state, action) { - switch (action.type) { + switch (action) { case "OPEN_SIDEBAR": { return { ...state, @@ -19,13 +20,13 @@ function uiReducer(state, action) { case "CLOSE_SIDEBAR": { return { ...state, - displaySidebar: true, + displaySidebar: false, }; } } } -export const UIContext = React.createContext(initialState); +export const UIContext = React.createContext(initialState); UIContext.displayName = "UIContext"; export const UIProvider: FunctionComponent = (props) => {