feishin/src/renderer/components/virtual-table/cells/rating-cell.tsx

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-01-06 00:39:49 -08:00
import type { ICellRendererParams } from '@ag-grid-community/core';
2023-01-06 00:39:49 -08:00
import { CellContainer } from '/@/renderer/components/virtual-table/cells/generic-cell';
import { useSetRating } from '/@/renderer/features/shared';
import { Rating } from '/@/shared/components/rating/rating';
2023-01-06 00:39:49 -08:00
export const RatingCell = ({ node, value }: ICellRendererParams) => {
2023-07-01 19:10:05 -07:00
const updateRatingMutation = useSetRating({});
2023-07-01 19:10:05 -07:00
const handleUpdateRating = (rating: number) => {
updateRatingMutation.mutate(
{
query: {
item: [value],
rating,
},
serverId: value?.serverId,
},
{
onSuccess: () => {
node.setData({ ...node.data, userRating: rating });
},
},
);
};
2023-07-01 19:10:05 -07:00
return (
<CellContainer position="center">
2023-07-01 19:10:05 -07:00
<Rating
onChange={handleUpdateRating}
2023-07-01 19:10:05 -07:00
size="xs"
value={value?.userRating}
/>
</CellContainer>
);
2023-01-06 00:39:49 -08:00
};