Skip to content

Commit

Permalink
supporting modal center notice. (#581)
Browse files Browse the repository at this point in the history
Co-authored-by: Spicer Matthews <[email protected]>
  • Loading branch information
spicermatthews and Spicer Matthews authored Jul 24, 2024
1 parent 0c38b7d commit 5fc5fa3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
62 changes: 61 additions & 1 deletion src/components/notification/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if (isBrowser) {
const Notification = ({ slot, user, onOpenLeaderboard }) => {
const [show, setShow] = useState(true)
const [height, setHeight] = useState(0)
const [showModal, setShowModal] = useState(false)
const [openWidget, setOpenWidget] = useState(false)
const [iframeUrl, setIframeUrl] = useState('')
const [notification, setNotification] = useState('')
Expand Down Expand Up @@ -84,9 +85,17 @@ const Notification = ({ slot, user, onOpenLeaderboard }) => {
if (event.data.show) {
setShow(true)
setHeight(event.data.height)

if (event.data.slot === 'modal-center') {
setShowModal(true)
}
} else {
setShow(false)
setHeight(0)

if (event.data.slot === 'modal-center') {
setShowModal(false)
}
}

// Did we get a new iframe URL?
Expand Down Expand Up @@ -126,7 +135,7 @@ const Notification = ({ slot, user, onOpenLeaderboard }) => {

return (
<>
{show && (
{show && (slot === 'top-right' || slot === 'top-center') && (
<iframe
id={`notification-${slot}`}
src={`${process.env.NEXT_PUBLIC_API_ENDPOINT}/v5/notifications?user_id=${user.userId}&slot=${slot}&override=${sParams.NotificationOverride}&version=${sParams.Version}`}
Expand All @@ -138,6 +147,57 @@ const Notification = ({ slot, user, onOpenLeaderboard }) => {
/>
)}

{slot === 'modal-center' && (
<iframe
id={`notification-hidden-${slot}`}
src={`${process.env.NEXT_PUBLIC_API_ENDPOINT}/v5/notifications?user_id=${user.userId}&slot=${slot}&override=${sParams.NotificationOverride}&version=${sParams.Version}`}
title={`notification-hidden-${slot}`}
style={{ marginTop: '10px', marginBottom: '10px' }}
frameBorder="0"
/>
)}

{showModal && slot === 'modal-center' && (
<Modal
id={`notification-modal-${slot}`}
open={showModal}
style={{
height: height + 30,
marginTop: 'auto',
marginBottom: 'auto',
marginLeft: 'auto',
marginRight: 'auto',
maxWidth: 800,
position: 'absolute',
backgroundColor: '#fff',
zIndex: 100000000,
}}
>
<div style={{ height: '100%' }}>
<div
style={{
height: '100%',
width: '100%',
padding: 0,
backgroundColor: 'white',
display: 'flex',
flexFlow: 'column',
}}
>
<iframe
id={`notification-${slot}`}
src={`${process.env.NEXT_PUBLIC_API_ENDPOINT}/v5/notifications?user_id=${user.userId}&slot=${slot}&override=${sParams.NotificationOverride}&version=${sParams.Version}`}
title={`notification-${slot}`}
style={{ marginTop: '10px', marginBottom: '10px' }}
width="100%"
height="100%"
frameBorder="0"
/>
</div>
</div>
</Modal>
)}

{/* Used for top-center modal windows */}
{iframeUrl && openWidget && (
<Modal
Expand Down
3 changes: 3 additions & 0 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,9 @@ const Index = ({ data: fallbackData, userAgent }) => {
{user && user.userId && notifSearch && notifSearch.variation && (
<SearchFullPage user={user} variation={notifSearch.variation} />
)}
{user && user.userId && (
<Notification slot="modal-center" user={user} />
)}
</div>
</>
)
Expand Down

0 comments on commit 5fc5fa3

Please sign in to comment.