mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-17 17:04:16 +02:00
normalize controls onto lists
This commit is contained in:
@@ -2,19 +2,14 @@ import {
|
||||
ItemTableListInnerColumn,
|
||||
TableColumnContainer,
|
||||
} from '/@/renderer/components/item-list/item-table-list/item-table-list-column';
|
||||
import { useCreateFavorite } from '/@/renderer/features/shared/mutations/create-favorite-mutation';
|
||||
import { useDeleteFavorite } from '/@/renderer/features/shared/mutations/delete-favorite-mutation';
|
||||
import { ItemListItem } from '/@/renderer/components/item-list/types';
|
||||
import { ActionIcon } from '/@/shared/components/action-icon/action-icon';
|
||||
import { LibraryItem } from '/@/shared/types/domain-types';
|
||||
|
||||
export const FavoriteColumn = (props: ItemTableListInnerColumn) => {
|
||||
const row: boolean | undefined = (props.data as (any | undefined)[])[props.rowIndex]?.[
|
||||
props.columns[props.columnIndex].id
|
||||
];
|
||||
|
||||
const createFavorite = useCreateFavorite({});
|
||||
const deleteFavorite = useDeleteFavorite({});
|
||||
|
||||
if (typeof row === 'boolean') {
|
||||
return (
|
||||
<TableColumnContainer {...props}>
|
||||
@@ -26,36 +21,14 @@ export const FavoriteColumn = (props: ItemTableListInnerColumn) => {
|
||||
fill: row ? 'primary' : undefined,
|
||||
size: 'md',
|
||||
}}
|
||||
onClick={() => {
|
||||
if (!props.data?.[props.rowIndex]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (row) {
|
||||
deleteFavorite.mutate({
|
||||
apiClientProps: {
|
||||
serverId: (props.data as any)[props.rowIndex]
|
||||
.serverId as string,
|
||||
},
|
||||
query: {
|
||||
id: [(props.data as any)[props.rowIndex].id as string],
|
||||
type: (props.data as any)[props.rowIndex]
|
||||
.itemType as LibraryItem,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
createFavorite.mutate({
|
||||
apiClientProps: {
|
||||
serverId: (props.data as any)[props.rowIndex]
|
||||
.serverId as string,
|
||||
},
|
||||
query: {
|
||||
id: [(props.data as any)[props.rowIndex].id as string],
|
||||
type: (props.data as any)[props.rowIndex]
|
||||
.itemType as LibraryItem,
|
||||
},
|
||||
});
|
||||
}
|
||||
onClick={(event) => {
|
||||
props.controls.onFavorite?.({
|
||||
event,
|
||||
favorite: !row,
|
||||
internalState: props.internalState,
|
||||
item: props.data[props.rowIndex] as ItemListItem,
|
||||
itemType: props.itemType,
|
||||
});
|
||||
}}
|
||||
size="xs"
|
||||
variant="subtle"
|
||||
|
||||
@@ -2,7 +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 { ItemListItem } from '/@/renderer/components/item-list/types';
|
||||
import { Rating } from '/@/shared/components/rating/rating';
|
||||
|
||||
export const RatingColumn = (props: ItemTableListInnerColumn) => {
|
||||
@@ -10,35 +10,20 @@ 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({
|
||||
apiClientProps: { serverId: item.serverId as string },
|
||||
query: {
|
||||
id: [item.id],
|
||||
rating: newRating,
|
||||
type: item.itemType,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
if (typeof row === 'number' || row === null) {
|
||||
return (
|
||||
<TableColumnContainer {...props}>
|
||||
<Rating
|
||||
className={row ? undefined : 'hover-only-flex'}
|
||||
onChange={handleChangeRating}
|
||||
onChange={(rating) => {
|
||||
props.controls.onRating?.({
|
||||
event: null,
|
||||
internalState: props.internalState,
|
||||
item: props.data[props.rowIndex] as ItemListItem,
|
||||
itemType: props.itemType,
|
||||
rating,
|
||||
});
|
||||
}}
|
||||
size="xs"
|
||||
value={row || 0}
|
||||
/>
|
||||
|
||||
@@ -21,11 +21,7 @@ export const RowIndexColumn = (props: ItemTableListInnerColumn) => {
|
||||
icon="arrowDownS"
|
||||
iconProps={{ color: 'muted', size: 'md' }}
|
||||
onClick={(e) =>
|
||||
controls.onItemExpand?.(
|
||||
props.data[props.rowIndex] as any,
|
||||
props.itemType,
|
||||
e,
|
||||
)
|
||||
controls.onExpand?.(props.data[props.rowIndex] as any, props.itemType, e)
|
||||
}
|
||||
size="xs"
|
||||
variant="subtle"
|
||||
|
||||
Reference in New Issue
Block a user