Skip to content

Commit

Permalink
fix: vk oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
Averito committed Jan 27, 2024
1 parent 4ffa4b0 commit 56427a1
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 164 deletions.
104 changes: 52 additions & 52 deletions client/src/components/Dropdown/Dropdown.module.scss
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
.dropdownWrapper {
position: relative;
}

.dropdownMenu {
position: absolute;
right: 0;
top: 0;
min-width: 100%;
background-color: #302457;
border-radius: 4px;
overflow: hidden auto;
transition: max-height 0.3s ease, padding 0.3s ease;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);

&::-webkit-scrollbar {
display: none;
}
}

.dropdownMenuOn {
max-height: 210px;
padding: 4px 0;

@media all and (max-width: 768px) {
max-height: 0;
padding: 0;
}
}

.dropdownMenuOnClickMod {
max-height: 200px;
padding: 4px 0;
}

.dropdownMenuOff {
max-height: 0;
padding: 0;
}

.menuItem {
padding: 8px 12px;
cursor: pointer;
transition: background-color 0.3s ease;
font-size: 14px;
width: 100%;
min-width: 160px;

&:hover {
background-color: #2b214f;
}
}
.dropdownWrapper {
position: relative;
}

.dropdownMenu {
position: absolute;
right: 0;
top: 0;
min-width: 100%;
background-color: #302457;
border-radius: 4px;
overflow: hidden auto;
transition: max-height 0.3s ease, padding 0.3s ease;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);

&::-webkit-scrollbar {
display: none;
}
}

.dropdownMenuOn {
max-height: 210px;
padding: 4px 0;

@media all and (max-width: 768px) {
max-height: 0;
padding: 0;
}
}

.dropdownMenuOnClickMod {
max-height: 200px;
padding: 4px 0;
}

.dropdownMenuOff {
max-height: 0;
padding: 0;
}

.menuItem {
padding: 8px 12px;
cursor: pointer;
transition: background-color 0.3s ease;
font-size: 14px;
width: 100%;
min-width: 160px;

&:hover {
background-color: #2b214f;
}
}
212 changes: 110 additions & 102 deletions client/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,102 +1,110 @@
import React, {
FC,
MouseEventHandler,
PropsWithChildren,
useRef,
useState
} from 'react'
import Link from 'next/link'
import classnames from 'classnames'

import styles from './Dropdown.module.scss'
import { useOutside } from '@hooks/useOutside'
import { defineEmits } from '@helpers/defineEmits'
import { DropdownProps } from './Dropdown.types'

export const Dropdown: FC<PropsWithChildren<DropdownProps>> = ({
options,
clickMod,
onOpen,
onClose,
margin,
children
}) => {
const [active, setActive] = useState<boolean>(false)

const emit = defineEmits<'open' | 'close'>({
open: onOpen ?? (() => {}),
close: onClose ?? (() => {})
})

let timeout = useRef<ReturnType<typeof setTimeout>>()
const onMouseEnter: MouseEventHandler<HTMLDivElement> = () => {
clearTimeout(timeout.current)
setActive(true)
emit('open')
}
const onMouseLeave: MouseEventHandler<HTMLDivElement> = () => {
timeout.current = setTimeout(() => {
setActive(false)
emit('close')
}, 200)
}

const open: MouseEventHandler<HTMLDivElement> = event => {
event.stopPropagation()
if (active) {
setActive(false)
emit('close')
return
}

setActive(true)
emit('open')
}

const dropdownChildren = useRef<HTMLDivElement>(null)
useOutside(dropdownChildren, () => {
if (!clickMod) return
setActive(false)
emit('close')
})

const dropdownMenuActive = active
? clickMod
? styles.dropdownMenuOnClickMod
: styles.dropdownMenuOn
: styles.dropdownMenuOff

const marginStyle = { margin }

return (
<div
onMouseEnter={!clickMod ? onMouseEnter : undefined}
onMouseLeave={!clickMod ? onMouseLeave : undefined}
>
<div
ref={dropdownChildren}
style={marginStyle}
onClick={clickMod ? open : undefined}
>
{children}
</div>
<div className={styles.dropdownWrapper}>
<div className={classnames(styles.dropdownMenu, dropdownMenuActive)}>
{options.map(option => (
<React.Fragment key={option.id}>
{option.href ? (
<div className={styles.menuItem} onClick={option.onClick}>
<Link href={option.href}>{option.label}</Link>
</div>
) : (
<div className={styles.menuItem} onClick={option.onClick}>
{option.label}
</div>
)}
</React.Fragment>
))}
</div>
</div>
</div>
)
}
import React, {
FC,
MouseEventHandler,
PropsWithChildren,
useRef,
useState
} from 'react'
import Link from 'next/link'
import classnames from 'classnames'

import styles from './Dropdown.module.scss'
import { useOutside } from '@hooks/useOutside'
import { defineEmits } from '@helpers/defineEmits'
import { DropdownProps } from './Dropdown.types'
import { useRouter } from 'next/router'

export const Dropdown: FC<PropsWithChildren<DropdownProps>> = ({
options,
clickMod,
onOpen,
onClose,
margin,
children
}) => {
const router = useRouter()
const [active, setActive] = useState<boolean>(false)

const emit = defineEmits<'open' | 'close'>({
open: onOpen ?? (() => {}),
close: onClose ?? (() => {})
})

let timeout = useRef<ReturnType<typeof setTimeout>>()
const onMouseEnter: MouseEventHandler<HTMLDivElement> = () => {
clearTimeout(timeout.current)
setActive(true)
emit('open')
}
const onMouseLeave: MouseEventHandler<HTMLDivElement> = () => {
timeout.current = setTimeout(() => {
setActive(false)
emit('close')
}, 200)
}

const open: MouseEventHandler<HTMLDivElement> = event => {
event.stopPropagation()
if (active) {
setActive(false)
emit('close')
return
}

setActive(true)
emit('open')
}

const goTo = (href: string) => {
return () => {
void router.push(href)
}
}

const dropdownChildren = useRef<HTMLDivElement>(null)
useOutside(dropdownChildren, () => {
if (!clickMod) return
setActive(false)
emit('close')
})

const dropdownMenuActive = active
? clickMod
? styles.dropdownMenuOnClickMod
: styles.dropdownMenuOn
: styles.dropdownMenuOff

const marginStyle = { margin }

return (
<div
onMouseEnter={!clickMod ? onMouseEnter : undefined}
onMouseLeave={!clickMod ? onMouseLeave : undefined}
>
<div
ref={dropdownChildren}
style={marginStyle}
onClick={clickMod ? open : undefined}
>
{children}
</div>
<div className={styles.dropdownWrapper}>
<div className={classnames(styles.dropdownMenu, dropdownMenuActive)}>
{options.map(option => (
<React.Fragment key={option.id}>
{option.href ? (
<div className={styles.menuItem} onClick={goTo(option.href)}>
<Link href={option.href}>{option.label}</Link>
</div>
) : (
<div className={styles.menuItem} onClick={option.onClick}>
{option.label}
</div>
)}
</React.Fragment>
))}
</div>
</div>
</div>
)
}
6 changes: 2 additions & 4 deletions client/src/layouts/MainLayout/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { observer } from 'mobx-react-lite'
import { useRouter } from 'next/router'
import { AiOutlineSearch } from 'react-icons/ai'
import { FC } from 'react'
import Link from 'next/link'
import Image from 'next/image'
Expand All @@ -12,7 +11,6 @@ import { Dropdown } from '@components/Dropdown'
import userStore from '@stores/user.store'
import { useMenu } from '@layouts/MainLayout/components/Header/hooks/useMenu'
import { Averlist } from '@averlistApi/types'
import { averlist } from '@averlistApi/averlist'
import {
HeaderSearch,
Hamburger
Expand Down Expand Up @@ -75,13 +73,13 @@ export const Header: FC = observer(() => {
<Hamburger />
<div className={styles.containerBlock1}>
<div className={styles.containerBlock1WithSearch}>
<h1
<a
className={styles.title}
data-text='Averlist'
onClick={onClickOnTitle}
>
Averlist
</h1>
</a>
<HeaderSearch />
</div>
<nav>
Expand Down
12 changes: 6 additions & 6 deletions client/src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { useRouter } from 'next/router'
export const Login: NextPage = () => {
const router = useRouter()

const signInGoogle: MouseEventHandler<HTMLDivElement> = () => {
void router.push('/api/v1/auth/google')
}
// const signInGoogle: MouseEventHandler<HTMLDivElement> = () => {
// void router.push('/api/v1/auth/google')
// }

const signInYandex: MouseEventHandler<HTMLDivElement> = () => {
void router.push('/api/v1/auth/yandex')
Expand All @@ -38,9 +38,9 @@ export const Login: NextPage = () => {
<div className={styles.container} style={containerBackground}>
<div className={styles.form}>
<div className={styles.servicesButtons}>
<div className={styles.button} onClick={signInGoogle}>
<FaGoogle size={30} color='white' />
</div>
{/*<div className={styles.button} onClick={signInGoogle}>*/}
{/* <FaGoogle size={30} color='white' />*/}
{/*</div>*/}
<div className={styles.button} onClick={signInYandex}>
<FaYandex size={30} color='white' />
</div>
Expand Down
2 changes: 2 additions & 0 deletions client/src/stores/user.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getCurrentAvatar } from '@helpers/getCurrentAvatar'
import { getCurrentName } from '@helpers/getCurrentName'
import { errorToast, successToast } from '@helpers/toasts'
import { averlist } from '@averlistApi/averlist'
import { deleteCookie } from 'cookies-next'

class UserStore {
@observable public isAuth = true
Expand Down Expand Up @@ -53,6 +54,7 @@ class UserStore {

@action
public logout() {
deleteCookie('averlist-session')
this.isAuth = false
this.user = {} as Averlist.User
this._currentAvatar = defaultAvatar.src
Expand Down

0 comments on commit 56427a1

Please sign in to comment.