2024-10-04 05:22:51 +03:00
|
|
|
import type { UnstyledButtonProps } from '@mantine/core';
|
2025-05-18 14:03:18 -07:00
|
|
|
|
|
|
|
|
import React, { MouseEvent } from 'react';
|
2024-10-04 05:22:51 +03:00
|
|
|
import { RiPlayFill } from 'react-icons/ri';
|
|
|
|
|
import styled from 'styled-components';
|
2025-05-18 14:03:18 -07:00
|
|
|
|
2024-10-04 05:22:51 +03:00
|
|
|
import { usePlayQueueAdd } from '/@/renderer/features/player';
|
2025-05-18 14:03:18 -07:00
|
|
|
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
|
2025-05-20 19:23:36 -07:00
|
|
|
import { LibraryItem } from '/@/shared/types/domain-types';
|
|
|
|
|
import { Play } from '/@/shared/types/types';
|
2024-10-04 05:22:51 +03:00
|
|
|
|
2025-05-18 14:03:18 -07:00
|
|
|
type PlayButtonType = React.ComponentPropsWithoutRef<'button'> & UnstyledButtonProps;
|
2024-10-04 05:22:51 +03:00
|
|
|
|
|
|
|
|
const PlayButton = styled.button<PlayButtonType>`
|
|
|
|
|
position: absolute;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
width: 30px;
|
|
|
|
|
height: 30px;
|
|
|
|
|
background-color: rgb(255 255 255);
|
|
|
|
|
border: none;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
opacity: 0.8;
|
|
|
|
|
transition: scale 0.1s ease-in-out;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
scale: 1.1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
scale: 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
svg {
|
|
|
|
|
fill: rgb(0 0 0);
|
|
|
|
|
stroke: rgb(0 0 0);
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const ListConverControlsContainer = styled.div`
|
|
|
|
|
position: absolute;
|
|
|
|
|
z-index: 100;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const ListCoverControls = ({
|
2025-05-18 14:03:18 -07:00
|
|
|
context,
|
2024-10-04 05:22:51 +03:00
|
|
|
itemData,
|
|
|
|
|
itemType,
|
2024-10-09 18:20:04 -07:00
|
|
|
uniqueId,
|
2024-10-04 05:22:51 +03:00
|
|
|
}: {
|
2024-10-09 18:20:04 -07:00
|
|
|
context: Record<string, any>;
|
2024-10-04 05:22:51 +03:00
|
|
|
itemData: any;
|
|
|
|
|
itemType: LibraryItem;
|
2024-10-09 18:20:04 -07:00
|
|
|
uniqueId?: string;
|
2024-10-04 05:22:51 +03:00
|
|
|
}) => {
|
|
|
|
|
const playButtonBehavior = usePlayButtonBehavior();
|
|
|
|
|
const handlePlayQueueAdd = usePlayQueueAdd();
|
2024-10-09 18:20:04 -07:00
|
|
|
const isQueue = Boolean(context?.isQueue);
|
2024-10-04 05:22:51 +03:00
|
|
|
|
|
|
|
|
const handlePlay = async (e: MouseEvent<HTMLButtonElement>, playType?: Play) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
|
|
handlePlayQueueAdd?.({
|
|
|
|
|
byItemType: {
|
|
|
|
|
id: [itemData.id],
|
|
|
|
|
type: itemType,
|
|
|
|
|
},
|
|
|
|
|
playType: playType || playButtonBehavior,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-09 18:20:04 -07:00
|
|
|
const handlePlayFromQueue = () => {
|
|
|
|
|
context.handleDoubleClick({
|
|
|
|
|
data: {
|
|
|
|
|
uniqueId,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-04 05:22:51 +03:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<ListConverControlsContainer className="card-controls">
|
2024-10-09 18:20:04 -07:00
|
|
|
<PlayButton onClick={isQueue ? handlePlayFromQueue : handlePlay}>
|
2024-10-04 05:22:51 +03:00
|
|
|
<RiPlayFill size={20} />
|
|
|
|
|
</PlayButton>
|
|
|
|
|
</ListConverControlsContainer>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|