Skip to content

Commit

Permalink
Made it so you can open a leaderboard from an iframe notice.
Browse files Browse the repository at this point in the history
  • Loading branch information
Spicer Matthews committed Apr 20, 2024
1 parent f841985 commit 3139666
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
24 changes: 22 additions & 2 deletions src/components/notification/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Check failure on line 57 in src/components/notification/Notification.js

View workflow job for this annotation

GitHub Actions / test

Expected line before comment

Check failure on line 57 in src/components/notification/Notification.js

View workflow job for this annotation

GitHub Actions / test

Expected line before comment
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)
}
Expand Down Expand Up @@ -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
14 changes: 10 additions & 4 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,10 @@ const Index = ({ data: fallbackData, userAgent }) => {
setShowLeaderboardFunc(false)
}

const openLeaderboard = () => {
setShowLeaderboardFunc(true)
}

return (
<>
<Head>
Expand Down Expand Up @@ -864,9 +868,7 @@ const Index = ({ data: fallbackData, userAgent }) => {
backgroundColor: 'white',
boxShadow: '0px 2px 4px grey',
}}
onClick={() =>
setShowLeaderboardFunc(!showLeaderboardFunc)
}
onClick={openLeaderboard}
>
<div
style={{ display: 'flex', flexDirection: 'column' }}
Expand Down Expand Up @@ -978,7 +980,11 @@ const Index = ({ data: fallbackData, userAgent }) => {
* that appear via the UserImpact component.
*/}
<div className={classes.notificationsContainer}>
<Notification slot="top-right" user={user} />
<Notification
slot="top-right"
user={user}
onOpenLeaderboard={openLeaderboard}
/>

{/* <NotificationOld
className={classes.notification}
Expand Down

0 comments on commit 3139666

Please sign in to comment.