diff --git a/components/vote/ParticipantCard.tsx b/components/vote/ParticipantCard.tsx
index 724fc02..8b7c7e9 100644
--- a/components/vote/ParticipantCard.tsx
+++ b/components/vote/ParticipantCard.tsx
@@ -3,6 +3,7 @@
import Image from 'next/image';
import placeholder from '@/public/person placeholder.svg';
import clsx from 'clsx';
+import { motion, usePresence, Variant, Transition } from 'framer-motion';
interface IProps {
number: number;
@@ -16,6 +17,7 @@ interface IProps {
voteStatus: string;
winner: boolean;
hasUrl: boolean;
+ index: number;
}
const ParticipantCard = ({
@@ -25,6 +27,7 @@ const ParticipantCard = ({
votes,
progress,
voteCode,
+ index,
hasUrl,
isFirst,
voteStatus,
@@ -32,9 +35,37 @@ const ParticipantCard = ({
}: IProps) => {
const substractedProgress = progress > 99 ? progress - 2 : progress;
+ const transition: Transition = {
+ type: 'spring',
+ stiffness: 500,
+ damping: 50,
+ mass: 1,
+ delay: index * 0.1,
+ };
+
+ const [isPresent, safeToRemove] = usePresence();
+
+ const animations = {
+ layout: true,
+ initial: 'out',
+ style: {
+ position: (isPresent ? 'static' : 'absolute') as 'static' | 'absolute', // Corrected cast
+ },
+ animate: isPresent ? 'in' : 'out',
+ variants: {
+ in: { scaleY: 1, opacity: 1 },
+ out: { scaleY: 0, opacity: 0, zIndex: -1 },
+ tapped: { scale: 0.98, opacity: 0.5, transition: { duration: 0.1 } },
+ },
+ onAnimationComplete: () => !isPresent && safeToRemove(),
+ transition,
+ };
+
return winner && votes !== 0 ? (
////////////////////////////////////////////// Winner card
-
+
{number}
@@ -104,15 +135,6 @@ const ParticipantCard = ({
-
- {/* Progress bar */}
- {/* */}
@@ -127,10 +149,13 @@ const ParticipantCard = ({
ugrat
) : null}
-
+
) : (
////////////////////////////////////////////// Simple card
-
+
{number}
{photo && name ? (
@@ -207,7 +232,7 @@ const ParticipantCard = ({
) : null}
-
+
);
};
diff --git a/components/vote/ParticipantsList.tsx b/components/vote/ParticipantsList.tsx
index b8acc19..ebe12e8 100644
--- a/components/vote/ParticipantsList.tsx
+++ b/components/vote/ParticipantsList.tsx
@@ -12,6 +12,7 @@ import Image from 'next/image';
import { useMediaQuery } from 'usehooks-ts';
import Countdown from './Countdown';
import Link from 'next/link';
+import { AnimatePresence } from 'framer-motion';
interface IParams {
vote_id?: string;
@@ -31,8 +32,6 @@ const ParticipantsList = ({ vote_id }: IParams) => {
const [voteStatus, setVoteStatus] = useState
();
const [winnersCount, setWinnersCount] = useState(0);
- console.log(participantsData);
-
// States realted to web socket
const [smsNumber, setSmsNumber] = useState(null);
const [socket, setSocket] = useState(null);
@@ -79,11 +78,13 @@ const ParticipantsList = ({ vote_id }: IParams) => {
socket.onopen = () => {
console.log('WebSocket is connected');
setIsConnected(true);
+ // addVotes();
pingInterval = setInterval(() => {
if (socket?.readyState === WebSocket.OPEN) {
try {
socket.send(JSON.stringify({ type: 'ping' }));
+ // addVotes();
} catch (error) {
console.error('Error sending ping:', error);
}
@@ -162,9 +163,11 @@ const ParticipantsList = ({ vote_id }: IParams) => {
// Update the corresponding voting item
const updatedItems = prevVotingItems.map((item, index) =>
- index === 5 ? { ...item, votes_count: item.votes_count + 10000 } : item,
+ index === 1 ? { ...item, votes_count: item.votes_count + 1 } : item,
);
+ console.log('votes updated');
+ console.log(updatedItems.sort((a, b) => b.votes_count - a.votes_count));
// Sort the updated items array by votes_count in descending order
return updatedItems.sort((a, b) => b.votes_count - a.votes_count);
});
@@ -234,7 +237,7 @@ const ParticipantsList = ({ vote_id }: IParams) => {
{participantsData && participantsData[0].votes_count > 0 ? (
- {participantsData.map((participant, id) =>
+ {participantsData.map((participant, index) =>
participant.votes_count === participantsData[0].votes_count ? (
participant.url ? (
{
className="w-full">
{
) : (
{
{winnersCount > 1 ? : null}
+
{participantsData
- ? participantsData.map((participant, id) =>
- participant.id !== participantsData[0].id && voteStatus ? (
+ ? participantsData.map((participant, index) =>
+ participant.votes_count !== participantsData[0].votes_count ? (
participant.url ? (
{