mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
handle favorite/rating column mutations
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
||||
ItemTableListInnerColumn,
|
||||
TableColumnContainer,
|
||||
} from '/@/renderer/components/item-list/item-table-list/item-table-list-column';
|
||||
import { useSetRating } from '/@/renderer/features/shared/mutations/set-rating-mutation';
|
||||
import { Rating } from '/@/shared/components/rating/rating';
|
||||
|
||||
export const RatingColumn = (props: ItemTableListInnerColumn) => {
|
||||
@@ -9,11 +10,34 @@ export const RatingColumn = (props: ItemTableListInnerColumn) => {
|
||||
props.columns[props.columnIndex].id
|
||||
];
|
||||
|
||||
const setRatingMutation = useSetRating({});
|
||||
|
||||
const handleChangeRating = (rating: number) => {
|
||||
const previousRating = row || 0;
|
||||
|
||||
let newRating = rating;
|
||||
|
||||
if (previousRating === rating) {
|
||||
newRating = 0;
|
||||
}
|
||||
|
||||
const item = props.data[props.rowIndex] as any;
|
||||
|
||||
setRatingMutation.mutate({
|
||||
query: {
|
||||
item: [item],
|
||||
rating: newRating,
|
||||
},
|
||||
serverId: item.serverId as string,
|
||||
});
|
||||
};
|
||||
|
||||
if (typeof row === 'number' || row === null) {
|
||||
return (
|
||||
<TableColumnContainer {...props}>
|
||||
<Rating
|
||||
className={row ? undefined : 'hover-only-flex'}
|
||||
onChange={handleChangeRating}
|
||||
size="xs"
|
||||
value={row || 0}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user