Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature-achievement'
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamerblue committed Nov 11, 2024
2 parents 99bc0bf + 37ce902 commit e8a926e
Show file tree
Hide file tree
Showing 30 changed files with 1,518 additions and 18 deletions.
38 changes: 36 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "onlinejudge3-fe",
"version": "3.6.4",
"version": "3.7.0",
"description": "",
"scripts": {
"dev": "gulp dev",
Expand Down Expand Up @@ -63,6 +63,7 @@
"react-player": "~2.13.0",
"react-scroll": "^1.7.12",
"react-syntax-highlighter": "^9.0.0",
"react-toastify": "^8.2.0",
"react-tooltip": "^3.9.2",
"short-number": "^1.0.6",
"socket.io-client": "^2.4.0",
Expand Down
Binary file added public/assets/audio/achievement-receive.mp3
Binary file not shown.
Binary file added public/assets/audio/achievement-receive.wav
Binary file not shown.
Binary file added public/assets/audio/achievement-toast.mp3
Binary file not shown.
Binary file added public/assets/audio/achievement-toast.wav
Binary file not shown.
1 change: 1 addition & 0 deletions src/assets/svg/achievement-trophy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions src/components/AchievementToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { toast } from 'react-toastify';
import classNames from 'classnames';
import { Icon } from 'antd';
import { Howl } from 'howler';
import { IAchievement } from '@/common/interfaces/achievement';
import { EAchievementKey } from '@/common/configs/achievement.config';
import { getAchievementByKey } from '@/utils/achievement';
import AchievementTrophySvg from '@/assets/svg/achievement-trophy.svg';
import { EAchievementLevel } from '@/common/enums';

export interface IAchievementToastProps {
achievement: IAchievement;
}

class AchievementToast extends React.Component<IAchievementToastProps> {
componentDidMount() {
const sound = new Howl({
src: [`${process.env.PUBLIC_PATH}assets/audio/achievement-toast.mp3`],
});
setTimeout(() => sound.play(), 200);
}

render() {
const { achievement } = this.props;

return (
<div className="achievement-toast">
<div
className={classNames(
'achievement-toast-trophy',
`achievement-toast-trophy-${EAchievementLevel[achievement.level]}`,
)}
>
<Icon theme="outlined" component={AchievementTrophySvg} />
</div>
<div className="achievement-toast-info">
<div className="achievement-toast-title text-ellipsis">{achievement.title}</div>
<div className="achievement-toast-description text-ellipsis">
{achievement.description}
</div>
</div>
</div>
);
}
}

export default AchievementToast;

export function showAchievementToast(achievementKey: EAchievementKey) {
const achievement = getAchievementByKey(achievementKey);
return toast(<AchievementToast achievement={achievement} />, { containerId: 'achievement' });
}
27 changes: 27 additions & 0 deletions src/components/AchievementToastContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { ToastContainer, Zoom } from 'react-toastify';

class AchievementToastContainer extends React.Component {
render() {
return (
<ToastContainer
containerId="achievement"
position="bottom-center"
autoClose={8000}
hideProgressBar
newestOnTop={false}
closeOnClick
pauseOnFocusLoss
draggable
pauseOnHover
theme="colored"
className="achievement-toast-container"
bodyClassName="achievement-toast-body"
closeButton={false}
transition={Zoom}
/>
);
}
}

export default AchievementToastContainer;
Loading

0 comments on commit e8a926e

Please sign in to comment.