add folder browsing support (#315)

This commit is contained in:
jeffvli
2025-12-02 21:30:44 -08:00
parent 355257104d
commit 917bf91583
53 changed files with 2382 additions and 299 deletions
@@ -2,7 +2,7 @@ import {
ItemListStateActions,
ItemListStateItemWithRequiredProperties,
} from '/@/renderer/components/item-list/helpers/item-list-state';
import { Album, AlbumArtist, Artist, Playlist, Song } from '/@/shared/types/domain-types';
import { Album, AlbumArtist, Artist, Folder, Playlist, Song } from '/@/shared/types/domain-types';
/**
* Type guard to assert that an item has the required properties for dragging
@@ -28,13 +28,13 @@ const hasRequiredDragProperties = (
* Otherwise, select and drag only the current item.
* If internalState is not provided, returns the single item wrapped in an array.
*
* @param data - The item data to drag (Album, AlbumArtist, Artist, Playlist, or Song)
* @param data - The item data to drag (Album, AlbumArtist, Artist, Folder, Playlist, or Song)
* @param internalState - The item list state actions (optional)
* @param updateSelection - Whether to update the selection state (default: true)
* @returns Array of items that should be dragged (with original values, asserting id, itemType, and _serverId)
*/
export const getDraggedItems = (
data: Album | AlbumArtist | Artist | Playlist | Song | undefined,
data: Album | AlbumArtist | Artist | Folder | Playlist | Song | undefined,
internalState?: ItemListStateActions,
updateSelection: boolean = true,
): ItemListStateItemWithRequiredProperties[] => {
@@ -299,10 +299,15 @@ export const useDefaultItemListControls = (args?: UseDefaultItemListControlsArgs
return;
}
// Use the item's _itemType if available, otherwise fall back to the prop itemType
// This allows mixed lists (e.g., folders + songs) to show the correct context menu
const actualItemType =
(item as any)?._itemType || itemTypeMapping[itemType] || itemType;
// If no internalState, call ContextMenuController directly
if (!internalState) {
return ContextMenuController.call({
cmd: { items: [item] as any[], type: itemType as any },
cmd: { items: [item] as any[], type: actualItemType as any },
event,
});
}
@@ -315,7 +320,7 @@ export const useDefaultItemListControls = (args?: UseDefaultItemListControlsArgs
if (internalState.getSelected().length === 0) {
internalState.setSelected([item]);
return ContextMenuController.call({
cmd: { items: [item] as any[], type: itemType as any },
cmd: { items: [item] as any[], type: actualItemType as any },
event,
});
}
@@ -323,15 +328,21 @@ export const useDefaultItemListControls = (args?: UseDefaultItemListControlsArgs
else if (!internalState.isSelected(rowId)) {
internalState.setSelected([item]);
return ContextMenuController.call({
cmd: { items: [item] as any[], type: itemType as any },
cmd: { items: [item] as any[], type: actualItemType as any },
event,
});
}
const selectedItems = internalState.getSelected();
// For multiple selected items, use the itemType prop (assumes all selected items are of the same type)
const selectedItemType =
selectedItems.length > 0 && (selectedItems[0] as any)?._itemType
? (selectedItems[0] as any)._itemType
: actualItemType;
return ContextMenuController.call({
cmd: { items: selectedItems as any[], type: itemType as any },
cmd: { items: selectedItems as any[], type: selectedItemType as any },
event,
});
},