mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00:00
61 lines
2 KiB
TypeScript
61 lines
2 KiB
TypeScript
import type { ICellRendererParams } from '@ag-grid-community/core';
|
|
|
|
import { CellContainer } from '/@/renderer/components/virtual-table/cells/generic-cell';
|
|
import { useCreateFavorite } from '/@/renderer/features/shared/mutations/create-favorite-mutation';
|
|
import { useDeleteFavorite } from '/@/renderer/features/shared/mutations/delete-favorite-mutation';
|
|
import { ActionIcon } from '/@/shared/components/action-icon/action-icon';
|
|
|
|
export const FavoriteCell = ({ data, node, value }: ICellRendererParams) => {
|
|
const createMutation = useCreateFavorite({});
|
|
const deleteMutation = useDeleteFavorite({});
|
|
|
|
const handleToggleFavorite = () => {
|
|
const newFavoriteValue = !value;
|
|
|
|
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 });
|
|
},
|
|
},
|
|
);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<CellContainer position="center">
|
|
<ActionIcon
|
|
icon="favorite"
|
|
iconProps={{
|
|
fill: !value ? undefined : 'primary',
|
|
}}
|
|
onClick={handleToggleFavorite}
|
|
size="sm"
|
|
variant="subtle"
|
|
/>
|
|
</CellContainer>
|
|
);
|
|
};
|