feishin/src/renderer/features/context-menu/events.ts

81 lines
2 KiB
TypeScript
Raw Normal View History

2023-02-08 11:46:39 -08:00
import { GridOptions, RowNode } from '@ag-grid-community/core';
import { createUseExternalEvents } from '@mantine/utils';
2023-01-05 21:59:07 -08:00
import { LibraryItem } from '/@/renderer/api/types';
export type OpenContextMenuProps = {
2023-07-01 19:10:05 -07:00
context?: any;
data: any[];
dataNodes?: RowNode[];
menuItems: SetContextMenuItems;
2023-07-16 23:23:07 -07:00
resetGridCache?: () => void;
2023-07-01 19:10:05 -07:00
tableApi?: GridOptions['api'];
type: LibraryItem;
xPos: number;
yPos: number;
};
export type ContextMenuEvents = {
2023-07-01 19:10:05 -07:00
closeContextMenu: () => void;
openContextMenu: (args: OpenContextMenuProps) => void;
};
export type ContextMenuItemType =
2023-07-01 19:10:05 -07:00
| 'play'
| 'playLast'
| 'playNext'
2024-09-07 21:31:01 -07:00
| 'playShuffled'
2023-07-01 19:10:05 -07:00
| 'addToPlaylist'
| 'removeFromPlaylist'
| 'addToFavorites'
| 'removeFromFavorites'
| 'setRating'
| 'shareItem'
2023-07-01 19:10:05 -07:00
| 'deletePlaylist'
| 'createPlaylist'
| 'moveToBottomOfQueue'
| 'moveToTopOfQueue'
| 'removeFromQueue'
| 'deselectAll'
| 'showDetails'
| 'playSimilarSongs'
| 'download';
2024-08-26 21:35:12 -07:00
export const CONFIGURABLE_CONTEXT_MENU_ITEMS: ContextMenuItemType[] = [
'moveToBottomOfQueue',
'moveToTopOfQueue',
'play',
'playLast',
'playNext',
2024-09-07 21:31:01 -07:00
'playShuffled',
2024-08-26 21:35:12 -07:00
'playSimilarSongs',
'addToPlaylist',
'removeFromPlaylist',
'addToFavorites',
'removeFromFavorites',
'setRating',
'download',
'shareItem',
'showDetails',
];
export const CONTEXT_MENU_ITEM_MAPPING: { [k in ContextMenuItemType]?: string } = {
moveToBottomOfQueue: 'moveToBottom',
moveToTopOfQueue: 'moveToTop',
playLast: 'addLast',
playNext: 'addNext',
};
export type SetContextMenuItems = {
2023-07-01 19:10:05 -07:00
children?: boolean;
disabled?: boolean;
divider?: boolean;
id: ContextMenuItemType;
onClick?: () => void;
}[];
export const [useContextMenuEvents, createEvent] =
2023-07-01 19:10:05 -07:00
createUseExternalEvents<ContextMenuEvents>('context-menu');
export const openContextMenu = createEvent('openContextMenu');
export const closeContextMenu = createEvent('closeContextMenu');