11<script setup lang="ts">
22import type { WsEvent } from " ~/config/types" ;
3+ import JSConfetti from " js-confetti" ;
34
45type Props = {
56 name: string ;
@@ -8,27 +9,48 @@ const props = defineProps<Props>();
89
910const icon = () => {
1011 const list = [
11- ' love1.svg' ,
12- ' love2.svg' ,
13- ' pampers.svg' ,
14- ' poop1.svg' ,
15- ' poop2.svg' ,
16- ' toilet.svg' ,
12+ ' ✌' , ' ⭐' , ' ❤️' , ' ☢' ,
13+ ' 😊' , ' 🔥' , ' ☀️' , ' 💀️' ,
14+ ' ⚡' , ' ⏰' , ' 🎈' , ' ⛄' ,
15+ ' 🎉' , ' 🎁' , ' 🎊' , ' 🎃' ,
16+ ' 🚀' , ' 🍕' , ' 🍔' , ' 🍟' ,
17+ ' 🍦' , ' 🏆' , ' 🏈' , ' 🏊' ,
18+ ' 🏄' , ' 🏂' , ' 🏇' , ' 🚴' ,
1719 ]
1820
1921 return list [Math .floor (Math .random () * list .length )];
2022};
2123
24+ const position = () => {
25+ const min = 10 ;
26+ const max = 80 ;
27+
28+ return Math .floor (Math .random () * (max - min + 1 )) + min ;
29+ }
30+
2231const likes = ref ([]);
2332
2433const app = useNuxtApp ();
2534const like = () => {
2635 app .$api .data .like (props .name );
2736};
2837
38+ const firework = (total : number = 40 ): void => {
39+ const jsConfetti = new JSConfetti ();
40+ jsConfetti .addConfetti ({
41+ emojis: [' 🦄' , ' ⭐' , ' 🎉' , ' 💖' , ' 🚀' , ' 😍' ],
42+ emojiSize: 50 ,
43+ confettiNumber: total ,
44+ });
45+ }
46+
2947app .$ws .channel (' events' ).listen ((data : WsEvent ): void => {
3048 if (data .event === ' liked' && data .data .key === props .name ) {
31- likes .value .push (icon ());
49+ likes .value .push ({ icon: icon (), position: position () });
50+
51+ if (likes .value .length > 10 ) {
52+ firework (10 );
53+ }
3254
3355 setTimeout (() => {
3456 likes .value .shift ();
@@ -39,8 +61,11 @@ app.$ws.channel('events').listen((data: WsEvent): void => {
3961
4062<template >
4163 <div class =" cursor-pointer relative" @click =" like" >
42- <span v-for =" icon in likes" class =" heart" >
43- <img class =" w-16" :src =" `/like/${icon}`" :alt =" icon" />
64+ <span v-for =" {icon, position} in likes"
65+ class =" icon"
66+ :style =" {left: `${position}px`}"
67+ >
68+ {{ icon }}
4469 </span >
4570 <slot ></slot >
4671 </div >
@@ -57,33 +82,32 @@ app.$ws.channel('events').listen((data: WsEvent): void => {
5782 }
5883 24% {
5984 transform : rotateZ (20deg ) scale (0.7 );
60- left : 3 px ;
85+ margin- left : 10 px ;
6186 opacity : 0.7
6287 }
6388 40% {
6489 transform : rotateZ (-11deg ) scale (0.6 );
65- left : -3 px ;
90+ margin-right : 10 px ;
6691 }
6792 70% {
6893 transform : rotateZ (10deg ) scale (0.4 );
69- left : 3 px ;
94+ margin- left : 10 px ;
7095 opacity : .5 ;
7196 }
7297 90% {
7398 transform : scale (0.2 );
74- left : -3 px ;
99+ margin-right : 10 px ;
75100 }
76101 100% {
77102 opacity : 0 ;
78- top : -200 px ;
103+ top : -300 px ;
79104 transform : rotateZ (-5deg ) scale (0.1 );
80105 }
81106}
82107
83- .heart {
84- position : absolute ;
108+ .icon {
109+ @ apply absolute text- 5 xl ;
85110 top : -60px ;
86- left : 0 ;
87111 animation : float 1.5s linear forwards ;
88112}
89113 </style >
0 commit comments