Signed-off-by: mbrucedogs <mbrucedogs@gmail.com>

This commit is contained in:
mbrucedogs 2025-07-22 10:16:20 -05:00
parent b28c362efc
commit 8ad8201bfd
2 changed files with 9 additions and 6 deletions

View File

@ -7,7 +7,7 @@ import {
add, heart, heartOutline, ban, checkmark, people
} from 'ionicons/icons';
import { useAppSelector } from '../../redux';
import { selectIsAdmin, selectFavorites, selectSongs, selectQueue } from '../../redux';
import { selectIsAdmin, selectFavorites, selectSongs, selectQueue, selectCurrentSinger } from '../../redux';
import { useActions } from '../../hooks/useActions';
import { useModal } from '../../hooks/useModalContext';
@ -27,6 +27,7 @@ const SongInfo: React.FC<SongInfoProps> = ({ isOpen, onClose, song }) => {
const favorites = useAppSelector(selectFavorites);
const allSongs = useAppSelector(selectSongs);
const queue = useAppSelector(selectQueue);
const currentSingerName = useAppSelector(selectCurrentSinger);
const { handleToggleFavorite, handleToggleDisabled, isSongDisabled } = useActions();
const { openSelectSinger } = useModal();
@ -34,7 +35,7 @@ const SongInfo: React.FC<SongInfoProps> = ({ isOpen, onClose, song }) => {
const isInFavorites = (Object.values(favorites) as Song[]).some(favSong => favSong.path === song.path);
const isDisabled = isSongDisabled(song);
const isInQueue = (Object.values(queue) as QueueItem[]).some(queueItem => queueItem.song && queueItem.song.path === song.path);
const isInQueue = (Object.values(queue) as QueueItem[]).some(queueItem => queueItem.song && queueItem.song.path === song.path && queueItem.singer.name === currentSingerName);
const artistSongs = (Object.values(allSongs) as Song[]).filter(s =>
(s.artist || '').toLowerCase() === (song.artist || '').toLowerCase() && s.path !== song.path

View File

@ -217,8 +217,8 @@ const SongItem: React.FC<SongItemProps> = React.memo(({
// Memoized computations for performance
const isInQueue = useMemo(() =>
(Object.values(queue) as QueueItem[]).some(item => item.song.path === song.path),
[queue, song.path]
(Object.values(queue) as QueueItem[]).some(item => item.song.path === song.path && item.singer.name === currentSingerName),
[queue, song.path, currentSingerName]
);
const isInFavorites = useMemo(() =>
@ -248,11 +248,13 @@ const SongItem: React.FC<SongItemProps> = React.memo(({
const shouldShowCount = showCount !== undefined ? showCount : context === SongItemContext.QUEUE;
// Default values for action buttons based on context if not explicitly provided
const shouldShowInfoButton = showInfoButton !== undefined ? showInfoButton : [SongItemContext.SEARCH, SongItemContext.HISTORY].includes(context);
const shouldShowAddButton = showAddButton !== undefined ? showAddButton : [SongItemContext.SEARCH, SongItemContext.HISTORY].includes(context);
let shouldShowAddButton = showAddButton !== undefined ? showAddButton : [SongItemContext.SEARCH, SongItemContext.HISTORY].includes(context);
// Always hide the add button if the song is already in the queue for the current singer
if (isInQueue) shouldShowAddButton = false;
const shouldShowRemoveButton = showRemoveButton !== undefined ? showRemoveButton : context === SongItemContext.QUEUE && isAdmin;
const shouldShowDeleteButton = showDeleteButton !== undefined ? showDeleteButton : context === SongItemContext.HISTORY && isAdmin;
const shouldShowFavoriteButton = showFavoriteButton !== undefined ? showFavoriteButton : false; // Disabled for all contexts
const shouldShowInfoButton = showInfoButton !== undefined ? showInfoButton : [SongItemContext.SEARCH, SongItemContext.HISTORY].includes(context);
// Memoized handler functions for performance
const handleAddToQueueClick = useCallback(async () => {