2023-01-06 00:39:49 -08:00
|
|
|
import type { ICellRendererParams } from '@ag-grid-community/core';
|
2025-05-18 14:03:18 -07:00
|
|
|
|
2023-01-06 00:39:49 -08:00
|
|
|
import { RiHeartFill, RiHeartLine } from 'react-icons/ri';
|
2025-05-18 14:03:18 -07:00
|
|
|
|
2023-01-06 00:39:49 -08:00
|
|
|
import { Button } from '/@/renderer/components/button';
|
|
|
|
|
import { CellContainer } from '/@/renderer/components/virtual-table/cells/generic-cell';
|
2023-04-30 22:01:52 -07:00
|
|
|
import { useCreateFavorite, useDeleteFavorite } from '/@/renderer/features/shared';
|
2023-01-07 16:33:14 -08:00
|
|
|
|
2025-05-18 14:03:18 -07:00
|
|
|
export const FavoriteCell = ({ data, node, value }: ICellRendererParams) => {
|
2023-07-01 19:10:05 -07:00
|
|
|
const createMutation = useCreateFavorite({});
|
|
|
|
|
const deleteMutation = useDeleteFavorite({});
|
2023-01-07 16:33:14 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handleToggleFavorite = () => {
|
|
|
|
|
const newFavoriteValue = !value;
|
2023-01-07 16:33:14 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
if (newFavoriteValue) {
|
|
|
|
|
createMutation.mutate(
|
|
|
|
|
{
|
|
|
|
|
query: {
|
|
|
|
|
id: [data.id],
|
|
|
|
|
type: data.itemType,
|
|
|
|
|
},
|
|
|
|
|
serverId: data.serverId,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
node.setData({ ...data, userFavorite: newFavoriteValue });
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
deleteMutation.mutate(
|
|
|
|
|
{
|
|
|
|
|
query: {
|
|
|
|
|
id: [data.id],
|
|
|
|
|
type: data.itemType,
|
|
|
|
|
},
|
|
|
|
|
serverId: data.serverId,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
node.setData({ ...data, userFavorite: newFavoriteValue });
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-01-06 00:39:49 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
2023-09-22 02:34:57 -07:00
|
|
|
<CellContainer $position="center">
|
2023-07-01 19:10:05 -07:00
|
|
|
<Button
|
|
|
|
|
compact
|
2025-05-18 14:03:18 -07:00
|
|
|
onClick={handleToggleFavorite}
|
2023-07-01 19:10:05 -07:00
|
|
|
sx={{
|
|
|
|
|
svg: {
|
|
|
|
|
fill: !value
|
|
|
|
|
? 'var(--main-fg-secondary) !important'
|
|
|
|
|
: 'var(--primary-color) !important',
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
variant="subtle"
|
|
|
|
|
>
|
|
|
|
|
{!value ? <RiHeartLine size="1.3em" /> : <RiHeartFill size="1.3em" />}
|
|
|
|
|
</Button>
|
|
|
|
|
</CellContainer>
|
|
|
|
|
);
|
2023-01-06 00:39:49 -08:00
|
|
|
};
|