From 3139666dcdf42ef849518c82b6ac32863b555ed4 Mon Sep 17 00:00:00 2001 From: Spicer Matthews Date: Sat, 20 Apr 2024 15:51:06 -0700 Subject: [PATCH] Made it so you can open a leaderboard from an iframe notice. --- src/components/notification/Notification.js | 24 +++++++++++++++++++-- src/pages/index.js | 14 ++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/components/notification/Notification.js b/src/components/notification/Notification.js index a21cba31..c8833526 100644 --- a/src/components/notification/Notification.js +++ b/src/components/notification/Notification.js @@ -21,7 +21,7 @@ if (isBrowser) { // Example Overrides: ?notification-override=leaderboard-change-flat // Example Overrides: ?notification-override=leaderboard-change-down // Example Overrides: ?notification-override=leaderboard-change-up -const Notification = ({ slot, user }) => { +const Notification = ({ slot, user, onOpenLeaderboard }) => { const [show, setShow] = useState(true) const [height, setHeight] = useState(0) @@ -51,6 +51,22 @@ const Notification = ({ slot, user }) => { setHeight(0) } + // See if we have any actions + if (event.data.action) { + switch (event.data.action) { + // Open the leaderboard + case 'leaderboard-open': + if (onOpenLeaderboard) { + onOpenLeaderboard() + } + break + + // Default do nothing + default: + break + } + } + // Log or use the received message // console.log('Received message from child:', event.data, event.origin) } @@ -83,8 +99,12 @@ Notification.propTypes = { user: PropTypes.shape({ userId: PropTypes.string, }).isRequired, + + onOpenLeaderboard: PropTypes.func, } -Notification.defaultProps = {} +Notification.defaultProps = { + onOpenLeaderboard: null, +} export default Notification diff --git a/src/pages/index.js b/src/pages/index.js index 44e8175d..eee20356 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -766,6 +766,10 @@ const Index = ({ data: fallbackData, userAgent }) => { setShowLeaderboardFunc(false) } + const openLeaderboard = () => { + setShowLeaderboardFunc(true) + } + return ( <> @@ -864,9 +868,7 @@ const Index = ({ data: fallbackData, userAgent }) => { backgroundColor: 'white', boxShadow: '0px 2px 4px grey', }} - onClick={() => - setShowLeaderboardFunc(!showLeaderboardFunc) - } + onClick={openLeaderboard} >
{ * that appear via the UserImpact component. */}
- + {/*