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 fa2520b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
23 changes: 21 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,21 @@ const Notification = ({ slot, user }) => {
setHeight(0)
}

// See if we have any actions
if (event.data.action) {
switch (event.data.action) {
case 'leaderboard-open':

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

View check run for this annotation

Codecov / codecov/patch

src/components/notification/Notification.js#L57

Added line #L57 was not covered by tests
if (onOpenLeaderboard) {
onOpenLeaderboard()

Check warning on line 59 in src/components/notification/Notification.js

View check run for this annotation

Codecov / codecov/patch

src/components/notification/Notification.js#L59

Added line #L59 was not covered by tests
}
break

Check warning on line 61 in src/components/notification/Notification.js

View check run for this annotation

Codecov / codecov/patch

src/components/notification/Notification.js#L61

Added line #L61 was not covered by tests

// Default do nothing
default:
break

Check warning on line 65 in src/components/notification/Notification.js

View check run for this annotation

Codecov / codecov/patch

src/components/notification/Notification.js#L64-L65

Added lines #L64 - L65 were not covered by tests
}
}

// Log or use the received message
// console.log('Received message from child:', event.data, event.origin)
}
Expand Down Expand Up @@ -83,8 +98,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)

Check warning on line 770 in src/pages/index.js

View check run for this annotation

Codecov / codecov/patch

src/pages/index.js#L770

Added line #L770 was not covered by tests
}

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 fa2520b

Please sign in to comment.