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 { CellContainer } from '/@/renderer/components/virtual-table/cells/generic-cell';
|
2023-04-30 22:01:52 -07:00
|
|
|
import { useCreateFavorite, useDeleteFavorite } from '/@/renderer/features/shared';
|
2025-06-24 00:04:36 -07:00
|
|
|
import { ActionIcon } from '/@/shared/components/action-icon/action-icon';
|
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 (
|
2025-06-24 00:04:36 -07:00
|
|
|
<CellContainer position="center">
|
|
|
|
|
<ActionIcon
|
|
|
|
|
icon="favorite"
|
|
|
|
|
iconProps={{
|
|
|
|
|
fill: !value ? undefined : 'primary',
|
2023-07-01 19:10:05 -07:00
|
|
|
}}
|
2025-06-24 00:04:36 -07:00
|
|
|
onClick={handleToggleFavorite}
|
|
|
|
|
size="sm"
|
2023-07-01 19:10:05 -07:00
|
|
|
variant="subtle"
|
2025-06-24 00:04:36 -07:00
|
|
|
/>
|
2023-07-01 19:10:05 -07:00
|
|
|
</CellContainer>
|
|
|
|
|
);
|
2023-01-06 00:39:49 -08:00
|
|
|
};
|