From 8d923c4135f5dd22886e97a65635c1d0523b4b87 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Fri, 31 Mar 2023 20:55:01 +0600 Subject: [PATCH] chore: preact to astro comp --- src/components/Login/AccountDropdown.astro | 51 ++++++++++++++++++ src/components/Login/AccountNavigation.astro | 40 ++++++++++++++ src/components/Login/account-dropdown.tsx | 56 -------------------- src/components/Login/account-nav.tsx | 55 ------------------- src/components/Login/google-login.tsx | 25 ++++++++- src/components/Navigation.astro | 6 +-- src/components/Spinner.astro | 23 ++++++++ src/icons/google.svg | 6 +++ 8 files changed, 146 insertions(+), 116 deletions(-) create mode 100644 src/components/Login/AccountDropdown.astro create mode 100644 src/components/Login/AccountNavigation.astro delete mode 100644 src/components/Login/account-dropdown.tsx delete mode 100644 src/components/Login/account-nav.tsx create mode 100644 src/components/Spinner.astro create mode 100644 src/icons/google.svg diff --git a/src/components/Login/AccountDropdown.astro b/src/components/Login/AccountDropdown.astro new file mode 100644 index 000000000..8643c523a --- /dev/null +++ b/src/components/Login/AccountDropdown.astro @@ -0,0 +1,51 @@ + + + diff --git a/src/components/Login/AccountNavigation.astro b/src/components/Login/AccountNavigation.astro new file mode 100644 index 000000000..e07d01522 --- /dev/null +++ b/src/components/Login/AccountNavigation.astro @@ -0,0 +1,40 @@ +--- +import Spinner from '../Spinner.astro'; +import AccountDropdown from './AccountDropdown.astro'; +--- + +
+ + + + + +
+ + diff --git a/src/components/Login/account-dropdown.tsx b/src/components/Login/account-dropdown.tsx deleted file mode 100644 index 16fb057c7..000000000 --- a/src/components/Login/account-dropdown.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import Cookies from 'js-cookie'; -import { TOKEN_COOKIE_NAME } from '../../lib/utils'; -import { useEffect, useState } from 'preact/hooks'; - -export default function AccountDropdown() { - const [isOpen, setIsOpen] = useState(false); - - useEffect(() => { - // If user click outside the dropdown, and dropdown is open then close it. - const handleOpen = () => { - if (isOpen) setIsOpen(false); - }; - - document.addEventListener('click', handleOpen); - return () => document.removeEventListener('click', handleOpen); - }, [isOpen]); - - return ( -
- - -
-
    -
  • - - Your Profile - -
  • -
  • - -
  • -
-
-
- ); -} diff --git a/src/components/Login/account-nav.tsx b/src/components/Login/account-nav.tsx deleted file mode 100644 index 71765c654..000000000 --- a/src/components/Login/account-nav.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { useAuth } from '../../hooks/use-auth'; -import AccountDropdown from './account-dropdown'; - -export default function AccountNavigation() { - const { user, isLoading } = useAuth(); - - console.log('user', user, isLoading); - - return ( -
- {isLoading ? ( -
- -
- ) : ( - <> - {user ? ( - - ) : ( - - Register - - )} - - )} -
- ); -} - -export function Spinner({ className }: { className?: string }) { - return ( - - - - - ); -} diff --git a/src/components/Login/google-login.tsx b/src/components/Login/google-login.tsx index 0d103d0e2..35885fffd 100644 --- a/src/components/Login/google-login.tsx +++ b/src/components/Login/google-login.tsx @@ -1,7 +1,6 @@ import Cookies from 'js-cookie'; import { useEffect, useState } from 'preact/hooks'; import { TOKEN_COOKIE_NAME } from '../../lib/utils'; -import { Spinner } from './account-nav'; export default function GoogleLoginButton() { const [isLoading, setIsLoading] = useState(false); @@ -65,6 +64,30 @@ export default function GoogleLoginButton() { ); } +function Spinner({ className }: { className?: string }) { + return ( + + + + + ); +} + function GoogleLogo() { return ( @@ -28,8 +27,7 @@ import AccountNavigationAstro from './Login/account-navigation.astro'; Videos
  • - - +
  • diff --git a/src/components/Spinner.astro b/src/components/Spinner.astro new file mode 100644 index 000000000..a0e23961a --- /dev/null +++ b/src/components/Spinner.astro @@ -0,0 +1,23 @@ +--- +const { className = '', ...rest } = Astro.props; +--- + + + + + diff --git a/src/icons/google.svg b/src/icons/google.svg new file mode 100644 index 000000000..a2491e75b --- /dev/null +++ b/src/icons/google.svg @@ -0,0 +1,6 @@ + + + + + +