Skip to content
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
Binary file added public/sfx/confetti.mp3
Binary file not shown.
Binary file added public/sfx/punch.mp3
Binary file not shown.
3 changes: 2 additions & 1 deletion src/modules/users/components/CurrentUser/CurrentUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export function CurrentUser({ mobileView = false }: CurrentUserOptions) {

<PunchableAvatar
src={user?.image ?? ""}
spread={180}
soundUrl={"/sfx/confetti.mp3"}
spread={360}
angle={225}
gravity={1}
shapes={["circle", "square"]}
Expand Down
17 changes: 12 additions & 5 deletions src/modules/users/components/PunchableAvatar/PunchableAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import { useEffect, useState } from "react";
import { Avatar } from "@mantine/core";
import { useHover, useMouse } from "@mantine/hooks";
import { useIsMobile } from "~/modules/system";
import confetti from "canvas-confetti";

import styles from "./PunchableAvatar.module.scss";

interface PunchableAvatarOptions {
src: string;
soundUrl?: string | null;
spread?: number;
angle?: number;
gravity?: number;
Expand All @@ -19,6 +21,7 @@ interface PunchableAvatarOptions {

export function PunchableAvatar({
src,
soundUrl = null,
spread = 90,
angle = 90,
gravity = 10,
Expand All @@ -28,16 +31,18 @@ export function PunchableAvatar({
}: PunchableAvatarOptions) {
const { x: mouseX, y: mouseY } = useMouse();
const [rotateValue, setRotateValue] = useState(0);
const isMobile = useIsMobile();

const { ref, hovered } = useHover();

useEffect(() => {
if (rotateValue != 0) {
setTimeout(() => {
if (!hovered) setRotateValue(0);
if (!hovered && !isMobile) setRotateValue(0);
if (isMobile) setRotateValue(0);
}, 1000);
}
}, [hovered, rotateValue]);
}, [hovered, isMobile, rotateValue]);

return (
<Avatar
Expand All @@ -51,9 +56,11 @@ export function PunchableAvatar({
e.currentTarget.getBoundingClientRect();
e.preventDefault();

// const audio = new Audio("/sfx/punch.mp3");
// audio.volume = 0.25;
// void audio.play();
if (soundUrl) {
const audio = new Audio(soundUrl);
audio.volume = 0.25;
void audio.play();
}

// Trigger confetti at mouse position
void confetti({
Expand Down
2 changes: 1 addition & 1 deletion src/modules/users/components/UserListItem/UserListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function UserListItem({ user }: UserListItemOptions) {
return (
<Card>
<Flex w={"100%"} align={"center"} gap={"sm"}>
<PunchableAvatar src={user?.image ?? ""} />
<PunchableAvatar soundUrl={"/sfx/punch.mp3"} scalar={2} src={user?.image ?? ""} />
<Flex direction={"column"}>
<Text fw={"600"}>{user?.name}</Text>
<Badge className={styles.roleBadge} size="xs" color={roleColor}>
Expand Down