Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made it so you can open a leaderboard from an iframe notice. #577

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
// 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 @@
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 @@
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 @@
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 @@
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 @@
* 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
Loading