2022-12-19 15:59:14 -08:00
|
|
|
import type { MouseEvent } from 'react';
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import type { UnstyledButtonProps } from '@mantine/core';
|
|
|
|
|
import { Group } from '@mantine/core';
|
|
|
|
|
import { RiPlayFill, RiMore2Fill, RiHeartFill, RiHeartLine } from 'react-icons/ri';
|
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
import { _Button } from '/@/renderer/components/button';
|
2023-01-05 21:59:07 -08:00
|
|
|
import type { PlayQueueAddOptions } from '/@/renderer/types';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { Play } from '/@/renderer/types';
|
2023-03-30 06:44:33 -07:00
|
|
|
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
|
2023-01-05 21:59:07 -08:00
|
|
|
import { LibraryItem } from '/@/renderer/api/types';
|
2023-02-05 05:19:01 -08:00
|
|
|
import { useHandleGeneralContextMenu } from '/@/renderer/features/context-menu/hooks/use-handle-context-menu';
|
|
|
|
|
import {
|
|
|
|
|
ALBUM_CONTEXT_MENU_ITEMS,
|
|
|
|
|
ARTIST_CONTEXT_MENU_ITEMS,
|
|
|
|
|
} from '/@/renderer/features/context-menu/context-menu-items';
|
2022-12-19 15:59:14 -08:00
|
|
|
|
|
|
|
|
type PlayButtonType = UnstyledButtonProps & React.ComponentPropsWithoutRef<'button'>;
|
|
|
|
|
|
|
|
|
|
const PlayButton = styled.button<PlayButtonType>`
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
width: 50px;
|
|
|
|
|
height: 50px;
|
|
|
|
|
background-color: rgb(255, 255, 255);
|
|
|
|
|
border: none;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
opacity: 0.8;
|
|
|
|
|
transition: opacity 0.2s ease-in-out;
|
|
|
|
|
transition: scale 0.2s linear;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
scale: 1.1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
scale: 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
svg {
|
|
|
|
|
fill: rgb(0, 0, 0);
|
|
|
|
|
stroke: rgb(0, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const SecondaryButton = styled(_Button)`
|
|
|
|
|
opacity: 0.8;
|
|
|
|
|
transition: opacity 0.2s ease-in-out;
|
|
|
|
|
transition: scale 0.2s linear;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
scale: 1.1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
scale: 1;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const GridCardControlsContainer = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const ControlsRow = styled.div`
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: calc(100% / 3);
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
// const TopControls = styled(ControlsRow)`
|
|
|
|
|
// display: flex;
|
|
|
|
|
// align-items: flex-start;
|
|
|
|
|
// justify-content: space-between;
|
|
|
|
|
// padding: 0.5rem;
|
|
|
|
|
// `;
|
|
|
|
|
|
|
|
|
|
// const CenterControls = styled(ControlsRow)`
|
|
|
|
|
// display: flex;
|
|
|
|
|
// align-items: center;
|
|
|
|
|
// justify-content: center;
|
|
|
|
|
// padding: 0.5rem;
|
|
|
|
|
// `;
|
|
|
|
|
|
|
|
|
|
const BottomControls = styled(ControlsRow)`
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: flex-end;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
padding: 1rem 0.5rem;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const FavoriteWrapper = styled.span<{ isFavorite: boolean }>`
|
|
|
|
|
svg {
|
|
|
|
|
fill: ${(props) => props.isFavorite && 'var(--primary-color)'};
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2022-12-20 04:11:06 -08:00
|
|
|
export const CardControls = ({
|
|
|
|
|
itemData,
|
|
|
|
|
itemType,
|
|
|
|
|
handlePlayQueueAdd,
|
|
|
|
|
}: {
|
2022-12-31 19:26:58 -08:00
|
|
|
handlePlayQueueAdd?: (options: PlayQueueAddOptions) => void;
|
2022-12-20 04:11:06 -08:00
|
|
|
itemData: any;
|
|
|
|
|
itemType: LibraryItem;
|
|
|
|
|
}) => {
|
2023-03-30 06:44:33 -07:00
|
|
|
const playButtonBehavior = usePlayButtonBehavior();
|
2022-12-19 15:59:14 -08:00
|
|
|
|
|
|
|
|
const handlePlay = (e: MouseEvent<HTMLButtonElement>, playType?: Play) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
2022-12-31 19:26:58 -08:00
|
|
|
handlePlayQueueAdd?.({
|
2022-12-20 04:11:06 -08:00
|
|
|
byItemType: {
|
2023-01-03 02:13:04 -08:00
|
|
|
id: [itemData.id],
|
2022-12-20 04:11:06 -08:00
|
|
|
type: itemType,
|
|
|
|
|
},
|
|
|
|
|
play: playType || playButtonBehavior,
|
2022-12-19 15:59:14 -08:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-05 05:19:01 -08:00
|
|
|
const handleContextMenu = useHandleGeneralContextMenu(
|
|
|
|
|
itemType,
|
|
|
|
|
itemType === LibraryItem.ALBUM ? ALBUM_CONTEXT_MENU_ITEMS : ARTIST_CONTEXT_MENU_ITEMS,
|
|
|
|
|
);
|
2023-01-29 18:40:26 -08:00
|
|
|
|
2022-12-19 15:59:14 -08:00
|
|
|
return (
|
|
|
|
|
<GridCardControlsContainer>
|
|
|
|
|
<BottomControls>
|
|
|
|
|
<PlayButton onClick={handlePlay}>
|
|
|
|
|
<RiPlayFill size={25} />
|
|
|
|
|
</PlayButton>
|
|
|
|
|
<Group spacing="xs">
|
|
|
|
|
<SecondaryButton
|
|
|
|
|
disabled
|
|
|
|
|
p={5}
|
|
|
|
|
sx={{ svg: { fill: 'white !important' } }}
|
|
|
|
|
variant="subtle"
|
|
|
|
|
>
|
|
|
|
|
<FavoriteWrapper isFavorite={itemData?.isFavorite}>
|
|
|
|
|
{itemData?.isFavorite ? (
|
|
|
|
|
<RiHeartFill size={20} />
|
|
|
|
|
) : (
|
|
|
|
|
<RiHeartLine
|
|
|
|
|
color="white"
|
|
|
|
|
size={20}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</FavoriteWrapper>
|
|
|
|
|
</SecondaryButton>
|
2023-02-05 05:19:01 -08:00
|
|
|
<SecondaryButton
|
|
|
|
|
p={5}
|
|
|
|
|
sx={{ svg: { fill: 'white !important' } }}
|
|
|
|
|
variant="subtle"
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
handleContextMenu(e, [itemData]);
|
|
|
|
|
}}
|
2022-12-19 15:59:14 -08:00
|
|
|
>
|
2023-02-05 05:19:01 -08:00
|
|
|
<RiMore2Fill
|
|
|
|
|
color="white"
|
|
|
|
|
size={20}
|
|
|
|
|
/>
|
|
|
|
|
</SecondaryButton>
|
2022-12-19 15:59:14 -08:00
|
|
|
</Group>
|
|
|
|
|
</BottomControls>
|
|
|
|
|
</GridCardControlsContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|