From 8ad8201bfd007b7f7e584ffe88d529e05f2a5006 Mon Sep 17 00:00:00 2001 From: mbrucedogs Date: Tue, 22 Jul 2025 10:16:20 -0500 Subject: [PATCH] Signed-off-by: mbrucedogs --- src/components/common/SongInfo.tsx | 5 +++-- src/components/common/SongItem.tsx | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/common/SongInfo.tsx b/src/components/common/SongInfo.tsx index 3f01dbe..b99bcd3 100644 --- a/src/components/common/SongInfo.tsx +++ b/src/components/common/SongInfo.tsx @@ -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 = ({ 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 = ({ 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 diff --git a/src/components/common/SongItem.tsx b/src/components/common/SongItem.tsx index bff945d..d2c7186 100644 --- a/src/components/common/SongItem.tsx +++ b/src/components/common/SongItem.tsx @@ -217,8 +217,8 @@ const SongItem: React.FC = 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 = 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 () => {