fix internalState on expanded album item

This commit is contained in:
jeffvli
2025-11-28 14:39:18 -08:00
parent 3f8a3a5e03
commit 5d0124369e
@@ -11,6 +11,7 @@ import { useDefaultItemListControls } from '/@/renderer/components/item-list/hel
import {
ItemListStateActions,
ItemListStateItem,
useItemDraggingState,
useItemListState,
useItemSelectionState,
} from '/@/renderer/components/item-list/helpers/item-list-state';
@@ -30,7 +31,6 @@ import { LibraryItem, Song } from '/@/shared/types/domain-types';
import { DragOperation, DragTarget, DragTargetMap } from '/@/shared/types/drag-and-drop';
interface AlbumTracksTableProps {
internalState?: ItemListStateActions;
isDark?: boolean;
serverId: string;
songs?: Array<{
@@ -57,6 +57,7 @@ interface TrackRowProps {
const TrackRow = ({ controls, internalState, serverId, song }: TrackRowProps) => {
const rowId = internalState.extractRowId(song);
const isSelected = useItemSelectionState(internalState, rowId);
const isDraggingState = useItemDraggingState(internalState, rowId);
const songWithMetadata = {
...song,
@@ -101,7 +102,7 @@ const TrackRow = ({ controls, internalState, serverId, song }: TrackRowProps) =>
isEnabled: true,
});
const isDragging = internalState.isDragging(song.id) || isDraggingLocal;
const isDragging = isDraggingState || isDraggingLocal;
const containerRef = useRef<HTMLDivElement>(null);
const mergedRef = useMergedRef(containerRef, dragRef);
@@ -134,12 +135,7 @@ const TrackRow = ({ controls, internalState, serverId, song }: TrackRowProps) =>
);
};
const AlbumTracksTable = ({
internalState: parentInternalState,
isDark,
serverId,
songs,
}: AlbumTracksTableProps) => {
const AlbumTracksTable = ({ isDark, serverId, songs }: AlbumTracksTableProps) => {
const getDataFn = useCallback(() => songs || [], [songs]);
const extractRowId = useCallback((item: unknown) => {
@@ -149,9 +145,9 @@ const AlbumTracksTable = ({
return undefined;
}, []);
// Use parent internalState if available, otherwise create a local one
const localInternalState = useItemListState(getDataFn, extractRowId);
const internalState = parentInternalState || localInternalState;
// Always use a local state for tracks - tracks are separate entities from albums
// and need their own selection state. The parentInternalState is for album-level operations.
const internalState = useItemListState(getDataFn, extractRowId);
const controls = useDefaultItemListControls();
@@ -262,7 +258,6 @@ export const ExpandedAlbumListItem = ({ internalState, item }: ExpandedAlbumList
</Group>
</div>
<AlbumTracksTable
internalState={internalState}
isDark={color.isDark}
serverId={item._serverId}
songs={data?.songs}