Skip to content

Commit

Permalink
feat: improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
lauti7 committed Dec 6, 2023
1 parent ce0e717 commit 41194b9
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/containers/UserInformation/UserInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const UserInformation = (props: Props) => {
activeTab: 'newest' as 'newest' | 'read',
isLoading: false,
isOnboarding: checkIsOnboarding(),
isOpen: false
})
const [notificationsModalOpen, setNotificationsModalOpen] = useState(false)

let client: NotificationsAPI
if (identity) {
Expand Down Expand Up @@ -133,10 +133,9 @@ export const UserInformation = (props: Props) => {
}

const handleNotificationsOpen = async () => {
let currentState = notificationsState.isOpen
console.log("current state clicks > ", currentState)
let currentState = notificationsModalOpen

setNotificationsState({ ...notificationsState, isOpen: !currentState })
setNotificationsModalOpen(!currentState)

if (!currentState) {
const unreadNotifications = notificationsState.notifications.filter((notification) => !notification.read).map(({ id }) => id)
Expand All @@ -162,14 +161,36 @@ export const UserInformation = (props: Props) => {
}
}, [identity])

useEffect(() => {
function handleClickOutside(event: MouseEvent) {
const element = document.querySelector(".notifications-feed")
if (element && !element.contains(event.target as Node)) {
event.preventDefault()
event.stopPropagation()
handleNotificationsOpen()
}
}

if (notificationsModalOpen) {
document.addEventListener('mousedown', handleClickOutside)
} else {
document.removeEventListener('mousedown', handleClickOutside)
}

return () => {
document.removeEventListener('mousedown', handleClickOutside)
}

}, [notificationsModalOpen])

return (
<UserMenuComponent
notifications={

Check failure on line 188 in src/containers/UserInformation/UserInformation.tsx

View workflow job for this annotation

GitHub Actions / Build and Test

No overload matches this call.
withNotifications ? {
locale: props.locale as NotificationLocale,
isLoading: notificationsState.isLoading,
isOnboarding: notificationsState.isOnboarding,
isOpen: notificationsState.isOpen,
isOpen: notificationsModalOpen,
items: notificationsState.notifications,
activeTab: notificationsState.activeTab,
onClick: handleNotificationsOpen,
Expand Down

0 comments on commit 41194b9

Please sign in to comment.