Skip to content

Commit

Permalink
Fix listener is overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Mar 21, 2024
1 parent 37d15c7 commit 3b13296
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/components/posts/ModerationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function ModerationProvider({ children }: { children: ReactNode }
const iframeRef = useRef<HTMLIFrameElement | null>(null)

useEffect(() => {
window.onmessage = event => {
const listener = (event: MessageEvent<any>) => {
const message = parseGrillMessage(event.data + '')
if (!message) return

Expand All @@ -23,6 +23,8 @@ export default function ModerationProvider({ children }: { children: ReactNode }
setIsOpenModal(false)
}
}
window.addEventListener('message', listener)
return () => window.removeEventListener('message', listener)
}, [])

const value = useMemo(() => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/profile-selector/MyAccountMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useRouter } from 'next/router'
import React, { createContext, FC, useContext, useEffect, useRef, useState } from 'react'
import { isDevMode } from 'src/config/env'
import { parseGrillMessage } from 'src/utils/iframe'
import { getCurrentUrlOrigin } from 'src/utils/url'
import { InfoDetails } from '../profiles/address-views'
Expand Down Expand Up @@ -73,7 +74,7 @@ export const AccountMenu: React.FunctionComponent<AddressProps> = ({ address, ow
const router = useRouter()

useEffect(() => {
window.onmessage = event => {
function listener(event: MessageEvent<any>) {
const message = parseGrillMessage(event.data + '')
if (!message) return

Expand All @@ -89,11 +90,10 @@ export const AccountMenu: React.FunctionComponent<AddressProps> = ({ address, ow
setIsOpenProfileModal(false)
}
}
window.addEventListener('message', listener)
return () => window.removeEventListener('message', listener)
}, [])

const origin = getCurrentUrlOrigin()
const isDevMode = origin.includes('localhost')

return (
<span
onClick={() => {
Expand Down

0 comments on commit 3b13296

Please sign in to comment.