From f99e0aba70efad0deb907d8e27f09fc9f527c8a4 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 17 Feb 2023 17:07:50 +0700 Subject: Refactor --- src/core/hooks/useActive.js | 19 +++++++++++++++++++ src/core/hooks/useAuth.js | 14 ++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/core/hooks/useActive.js create mode 100644 src/core/hooks/useAuth.js (limited to 'src/core/hooks') diff --git a/src/core/hooks/useActive.js b/src/core/hooks/useActive.js new file mode 100644 index 00000000..e3a371cb --- /dev/null +++ b/src/core/hooks/useActive.js @@ -0,0 +1,19 @@ +import { useState } from "react" + +const useActive = () => { + const [ active, setActive ] = useState(false) + + const activate = () => { + setActive(true) + } + + const deactivate = () => { + setActive(false) + } + + return { + activate, deactivate, active + } +} + +export default useActive \ No newline at end of file diff --git a/src/core/hooks/useAuth.js b/src/core/hooks/useAuth.js new file mode 100644 index 00000000..488562f6 --- /dev/null +++ b/src/core/hooks/useAuth.js @@ -0,0 +1,14 @@ +import { getAuth } from "../utils/auth" + +const useAuth = () => { + const [auth, setAuth] = useState(null) + + useEffect(() => { + const handleIsAuthenticated = () => setAuth(getAuth()) + handleIsAuthenticated() + }, []) + + return [auth, setAuth] +} + +export default useAuth \ No newline at end of file -- cgit v1.2.3 From d0d2a927fa1b9ac0a0e571f6e6f1294445db66a4 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Sun, 19 Feb 2023 22:06:00 +0700 Subject: fix --- src/core/hooks/useSidebar.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/core/hooks/useSidebar.js (limited to 'src/core/hooks') diff --git a/src/core/hooks/useSidebar.js b/src/core/hooks/useSidebar.js new file mode 100644 index 00000000..9388734a --- /dev/null +++ b/src/core/hooks/useSidebar.js @@ -0,0 +1,22 @@ +import useActive from "./useActive" +import SidebarComponent from "../components/elements/Sidebar/Sidebar" +import { useEffect } from "react" + +const useSidebar = () => { + const { active, activate, deactivate } = useActive() + + useEffect(() => { + if (active) { + document.querySelector('html, body').classList.add('overflow-hidden') + } else { + document.querySelector('html, body').classList.remove('overflow-hidden') + } + }, [active]) + + return { + open: activate, + Sidebar: + } +} + +export default useSidebar \ No newline at end of file -- cgit v1.2.3 From ed950b23d50f9b3993cfd2ac2386a5b3a68d5e57 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 20 Feb 2023 17:03:28 +0700 Subject: fix --- src/core/hooks/useAuth.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/hooks') diff --git a/src/core/hooks/useAuth.js b/src/core/hooks/useAuth.js index 488562f6..13f04454 100644 --- a/src/core/hooks/useAuth.js +++ b/src/core/hooks/useAuth.js @@ -1,3 +1,4 @@ +import { useEffect, useState } from "react" import { getAuth } from "../utils/auth" const useAuth = () => { @@ -8,7 +9,7 @@ const useAuth = () => { handleIsAuthenticated() }, []) - return [auth, setAuth] + return auth } export default useAuth \ No newline at end of file -- cgit v1.2.3 From f66b12fd1d0b83af0d7230d7b1565fbe00afbe3c Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 11:03:34 +0700 Subject: prettier --- src/core/hooks/useActive.js | 10 ++++++---- src/core/hooks/useAuth.js | 6 +++--- src/core/hooks/useSidebar.js | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src/core/hooks') diff --git a/src/core/hooks/useActive.js b/src/core/hooks/useActive.js index e3a371cb..c39cbdca 100644 --- a/src/core/hooks/useActive.js +++ b/src/core/hooks/useActive.js @@ -1,7 +1,7 @@ -import { useState } from "react" +import { useState } from 'react' const useActive = () => { - const [ active, setActive ] = useState(false) + const [active, setActive] = useState(false) const activate = () => { setActive(true) @@ -12,8 +12,10 @@ const useActive = () => { } return { - activate, deactivate, active + activate, + deactivate, + active } } -export default useActive \ No newline at end of file +export default useActive diff --git a/src/core/hooks/useAuth.js b/src/core/hooks/useAuth.js index 13f04454..af62e45c 100644 --- a/src/core/hooks/useAuth.js +++ b/src/core/hooks/useAuth.js @@ -1,5 +1,5 @@ -import { useEffect, useState } from "react" -import { getAuth } from "../utils/auth" +import { useEffect, useState } from 'react' +import { getAuth } from '../utils/auth' const useAuth = () => { const [auth, setAuth] = useState(null) @@ -12,4 +12,4 @@ const useAuth = () => { return auth } -export default useAuth \ No newline at end of file +export default useAuth diff --git a/src/core/hooks/useSidebar.js b/src/core/hooks/useSidebar.js index 9388734a..c463fd81 100644 --- a/src/core/hooks/useSidebar.js +++ b/src/core/hooks/useSidebar.js @@ -1,6 +1,6 @@ -import useActive from "./useActive" -import SidebarComponent from "../components/elements/Sidebar/Sidebar" -import { useEffect } from "react" +import useActive from './useActive' +import SidebarComponent from '../components/elements/Sidebar/Sidebar' +import { useEffect } from 'react' const useSidebar = () => { const { active, activate, deactivate } = useActive() @@ -19,4 +19,4 @@ const useSidebar = () => { } } -export default useSidebar \ No newline at end of file +export default useSidebar -- cgit v1.2.3 From ac3fdf7be9982e65d8f83a20bc487f8dd62e3bfc Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 23:36:47 +0700 Subject: fix --- src/core/hooks/useSidebar.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/core/hooks') diff --git a/src/core/hooks/useSidebar.js b/src/core/hooks/useSidebar.js index c463fd81..4da61ac2 100644 --- a/src/core/hooks/useSidebar.js +++ b/src/core/hooks/useSidebar.js @@ -15,7 +15,12 @@ const useSidebar = () => { return { open: activate, - Sidebar: + Sidebar: ( + + ) } } -- cgit v1.2.3