2023-04-30 22:01:52 -07:00
|
|
|
/* eslint-disable import/no-cycle */
|
2023-01-06 00:39:49 -08:00
|
|
|
import type { ICellRendererParams } from '@ag-grid-community/core';
|
|
|
|
|
import { Rating } from '/@/renderer/components/rating';
|
|
|
|
|
import { CellContainer } from '/@/renderer/components/virtual-table/cells/generic-cell';
|
2023-04-30 22:01:52 -07:00
|
|
|
import { useSetRating } from '/@/renderer/features/shared';
|
2023-01-06 00:39:49 -08:00
|
|
|
|
2023-02-07 22:47:23 -08:00
|
|
|
export const RatingCell = ({ value, node }: ICellRendererParams) => {
|
2023-07-01 19:10:05 -07:00
|
|
|
const updateRatingMutation = useSetRating({});
|
2023-02-05 05:19:01 -08:00
|
|
|
|
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-02-05 05:19:01 -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
|
|
|
<Rating
|
|
|
|
|
size="xs"
|
|
|
|
|
value={value?.userRating}
|
|
|
|
|
onChange={handleUpdateRating}
|
|
|
|
|
/>
|
|
|
|
|
</CellContainer>
|
|
|
|
|
);
|
2023-01-06 00:39:49 -08:00
|
|
|
};
|