Skip to content

Commit

Permalink
Merge pull request #91 from gardaholm/route-in-queue-icin
Browse files Browse the repository at this point in the history
Show Icon when Route in Queue
  • Loading branch information
marcodejongh authored Dec 27, 2024
2 parents 4708da2 + aa20ade commit 706a2f2
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions app/components/climb-card/climb-card-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useState } from 'react';
import { useQueueContext } from '../queue-control/queue-context';
import { BoardDetails, Climb } from '@/app/lib/types';
import { PlusCircleOutlined, HeartOutlined, InfoCircleOutlined } from '@ant-design/icons';
import { PlusCircleOutlined, HeartOutlined, InfoCircleOutlined, CheckCircleOutlined } from '@ant-design/icons';
import Link from 'next/link';
import { constructClimbInfoUrl } from '@/app/lib/url-utils';
import { message } from 'antd';
Expand All @@ -13,25 +13,26 @@ type ClimbCardActionsProps = {
boardDetails: BoardDetails;
};
const ClimbCardActions = ({ climb, boardDetails }: ClimbCardActionsProps) => {
const { addToQueue } = useQueueContext();
const [isAdded, setIsAdded] = useState(false);
const { addToQueue, queue } = useQueueContext();
const [isDuplicate, setDuplicateTimer] = useState(false);

if (!climb) {
return [];
}

const isAlreadyInQueue = queue.some((item) => item.climb.uuid === climb.uuid);

const handleAddToQueue = () => {
if (addToQueue && !isAdded) {
if (addToQueue && !isDuplicate) {
addToQueue(climb);

const climbName = climb.name || '';
message.info(`Successfully added ${climbName} to the queue`);

setIsAdded(true);
setDuplicateTimer(true);

// Reset the isAdded state after 3 seconds
setTimeout(() => {
setIsAdded(false);
setDuplicateTimer(false);
}, 3000);
}
};
Expand All @@ -45,11 +46,19 @@ const ClimbCardActions = ({ climb, boardDetails }: ClimbCardActionsProps) => {
<InfoCircleOutlined />
</Link>,
<HeartOutlined key="heart" onClick={() => message.info('TODO: Implement')} />,
<PlusCircleOutlined
key="edit"
onClick={handleAddToQueue}
style={{ color: isAdded ? 'gray' : 'inherit', cursor: isAdded ? 'not-allowed' : 'pointer' }}
/>,
isAlreadyInQueue ? (
<CheckCircleOutlined
key="edit"
onClick={handleAddToQueue}
style={{ color: '#52c41a', cursor: isDuplicate ? 'not-allowed' : 'pointer' }}
/>
) : (
<PlusCircleOutlined
key="edit"
onClick={handleAddToQueue}
style={{ color: 'inherit', cursor: isDuplicate ? 'not-allowed' : 'pointer' }}
/>
),
];
};

Expand Down

1 comment on commit 706a2f2

@vercel
Copy link

@vercel vercel bot commented on 706a2f2 Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.