mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-13 20:10:07 +02:00
handle rating in context menu
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useSetRating } from '/@/renderer/features/shared/mutations/set-rating-mutation';
|
||||
import { useCurrentServerId } from '/@/renderer/store';
|
||||
import { useCurrentServer, useCurrentServerId } from '/@/renderer/store';
|
||||
import { ContextMenu } from '/@/shared/components/context-menu/context-menu';
|
||||
import { Rating } from '/@/shared/components/rating/rating';
|
||||
import { LibraryItem } from '/@/shared/types/domain-types';
|
||||
import { ServerType } from '/@/shared/types/types';
|
||||
|
||||
interface SetRatingActionProps {
|
||||
ids: string[];
|
||||
@@ -13,11 +15,15 @@ interface SetRatingActionProps {
|
||||
|
||||
export const SetRatingAction = ({ ids, itemType }: SetRatingActionProps) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const server = useCurrentServer();
|
||||
const serverId = useCurrentServerId();
|
||||
|
||||
const setRatingMutation = useSetRating({});
|
||||
|
||||
const isRatingSupported = useMemo(() => {
|
||||
return server?.type === ServerType.NAVIDROME || server?.type === ServerType.SUBSONIC;
|
||||
}, [server?.type]);
|
||||
|
||||
const onRating = (rating: number) => {
|
||||
setRatingMutation.mutate({
|
||||
apiClientProps: { serverId },
|
||||
@@ -29,6 +35,10 @@ export const SetRatingAction = ({ ids, itemType }: SetRatingActionProps) => {
|
||||
});
|
||||
};
|
||||
|
||||
if (!isRatingSupported) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<ContextMenu.Submenu>
|
||||
<ContextMenu.SubmenuTarget>
|
||||
@@ -42,22 +52,22 @@ export const SetRatingAction = ({ ids, itemType }: SetRatingActionProps) => {
|
||||
</ContextMenu.SubmenuTarget>
|
||||
<ContextMenu.SubmenuContent>
|
||||
<ContextMenu.Item onSelect={() => onRating(0)}>
|
||||
<Rating readOnly value={0} />
|
||||
<Rating preventDefault={false} readOnly stopPropagation={false} value={0} />
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Item onSelect={() => onRating(1)}>
|
||||
<Rating readOnly value={1} />
|
||||
<Rating preventDefault={false} readOnly stopPropagation={false} value={1} />
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Item onSelect={() => onRating(2)}>
|
||||
<Rating readOnly value={2} />
|
||||
<Rating preventDefault={false} readOnly stopPropagation={false} value={2} />
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Item onSelect={() => onRating(3)}>
|
||||
<Rating readOnly value={3} />
|
||||
<Rating preventDefault={false} readOnly stopPropagation={false} value={3} />
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Item onSelect={() => onRating(4)}>
|
||||
<Rating readOnly value={4} />
|
||||
<Rating preventDefault={false} readOnly stopPropagation={false} value={4} />
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Item onSelect={() => onRating(5)}>
|
||||
<Rating readOnly value={5} />
|
||||
<Rating preventDefault={false} readOnly stopPropagation={false} value={5} />
|
||||
</ContextMenu.Item>
|
||||
</ContextMenu.SubmenuContent>
|
||||
</ContextMenu.Submenu>
|
||||
|
||||
Reference in New Issue
Block a user