diff --git a/src/components/common/SongInfo.tsx b/src/components/common/SongInfo.tsx index 3da05d6..c73db69 100644 --- a/src/components/common/SongInfo.tsx +++ b/src/components/common/SongInfo.tsx @@ -14,6 +14,7 @@ import { useModal } from '../../hooks/useModalContext'; import { ModalHeader, InfiniteScrollList, SongItem } from './index'; import { SongInfoDisplay } from './SongItem'; import type { Song, QueueItem } from '../../types'; +import { SongItemContext } from '../../types'; interface SongInfoProps { isOpen: boolean; @@ -160,7 +161,7 @@ const SongInfo: React.FC = ({ isOpen, onClose, song }) => { renderItem={(song) => ( = React.memo(({ // Find queue item key for removal (only needed for queue context) const queueItemKey = useMemo(() => - context === 'queue' + context === SongItemContext.QUEUE ? (Object.entries(queue) as [string, QueueItem][]).find(([, item]) => item.song.path === song.path)?.[0] : null, [context, queue, song.path] @@ -242,14 +243,14 @@ const SongItem: React.FC = React.memo(({ }); // Default values based on context if not explicitly provided - const shouldShowPath = showPath !== undefined ? showPath : context !== 'queue'; - const shouldShowCount = showCount !== undefined ? showCount : context === 'queue'; + const shouldShowPath = showPath !== undefined ? showPath : context !== SongItemContext.QUEUE; + 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 : ['search', 'history'].includes(context); - const shouldShowAddButton = showAddButton !== undefined ? showAddButton : ['search', 'history'].includes(context); - const shouldShowRemoveButton = showRemoveButton !== undefined ? showRemoveButton : context === 'queue' && isAdmin; - const shouldShowDeleteButton = showDeleteButton !== undefined ? showDeleteButton : context === 'history' && isAdmin; + const shouldShowInfoButton = showInfoButton !== undefined ? showInfoButton : [SongItemContext.SEARCH, SongItemContext.HISTORY].includes(context); + const shouldShowAddButton = showAddButton !== undefined ? showAddButton : [SongItemContext.SEARCH, SongItemContext.HISTORY].includes(context); + 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 // Memoized handler functions for performance @@ -295,9 +296,9 @@ const SongItem: React.FC = React.memo(({ showDeleteButton={shouldShowDeleteButton} showFavoriteButton={shouldShowFavoriteButton} onDeleteItem={onDeleteItem} - onAddToQueue={context === 'queue' ? handleRemoveFromQueueClick : handleAddToQueueClick} - onRemoveFromQueue={context === 'queue' ? handleRemoveFromQueueClick : onDeleteItem} - onToggleFavorite={context === 'favorites' ? onDeleteItem : handleToggleFavoriteClick} + onAddToQueue={context === SongItemContext.QUEUE ? handleRemoveFromQueueClick : handleAddToQueueClick} + onRemoveFromQueue={context === SongItemContext.QUEUE ? handleRemoveFromQueueClick : onDeleteItem} + onToggleFavorite={context === SongItemContext.FAVORITES ? onDeleteItem : handleToggleFavoriteClick} onShowSongInfo={handleSelectSinger} /> diff --git a/src/features/Favorites/Favorites.tsx b/src/features/Favorites/Favorites.tsx index 22bd2da..79a7e82 100644 --- a/src/features/Favorites/Favorites.tsx +++ b/src/features/Favorites/Favorites.tsx @@ -5,6 +5,7 @@ import { useAppSelector } from '../../redux'; import { selectFavorites } from '../../redux'; import { debugLog } from '../../utils/logger'; import type { Song } from '../../types'; +import { SongItemContext } from '../../types'; const Favorites: React.FC = () => { const { @@ -31,7 +32,7 @@ const Favorites: React.FC = () => { renderItem={(song) => ( { const { @@ -54,7 +55,7 @@ const History: React.FC = () => {
handleDeleteFromHistory(song)} isAdmin={isAdmin} showAddButton={true} diff --git a/src/features/NewSongs/NewSongs.tsx b/src/features/NewSongs/NewSongs.tsx index 59a7332..6178cd4 100644 --- a/src/features/NewSongs/NewSongs.tsx +++ b/src/features/NewSongs/NewSongs.tsx @@ -5,6 +5,7 @@ import { useAppSelector } from '../../redux'; import { selectNewSongsArray } from '../../redux'; import { debugLog } from '../../utils/logger'; import type { Song } from '../../types'; +import { SongItemContext } from '../../types'; const NewSongs: React.FC = () => { const { @@ -30,7 +31,7 @@ const NewSongs: React.FC = () => { renderItem={(song) => ( { const { @@ -52,7 +53,7 @@ const Search: React.FC = () => { renderItem={(song) => ( { const { @@ -124,7 +125,7 @@ const SongLists: React.FC = () => { void; isAdmin?: boolean; className?: string;