Signed-off-by: mbrucedogs <mbrucedogs@gmail.com>
This commit is contained in:
parent
ba326cd265
commit
589f6b3ad5
@ -14,6 +14,7 @@ import { useModal } from '../../hooks/useModalContext';
|
|||||||
import { ModalHeader, InfiniteScrollList, SongItem } from './index';
|
import { ModalHeader, InfiniteScrollList, SongItem } from './index';
|
||||||
import { SongInfoDisplay } from './SongItem';
|
import { SongInfoDisplay } from './SongItem';
|
||||||
import type { Song, QueueItem } from '../../types';
|
import type { Song, QueueItem } from '../../types';
|
||||||
|
import { SongItemContext } from '../../types';
|
||||||
|
|
||||||
interface SongInfoProps {
|
interface SongInfoProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@ -160,7 +161,7 @@ const SongInfo: React.FC<SongInfoProps> = ({ isOpen, onClose, song }) => {
|
|||||||
renderItem={(song) => (
|
renderItem={(song) => (
|
||||||
<SongItem
|
<SongItem
|
||||||
song={song}
|
song={song}
|
||||||
context="search"
|
context={SongItemContext.SEARCH}
|
||||||
showAddButton={true}
|
showAddButton={true}
|
||||||
showInfoButton={true}
|
showInfoButton={true}
|
||||||
showFavoriteButton={false}
|
showFavoriteButton={false}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import { useActions } from '../../hooks/useActions';
|
|||||||
import { useModal } from '../../hooks/useModalContext';
|
import { useModal } from '../../hooks/useModalContext';
|
||||||
import { debugLog } from '../../utils/logger';
|
import { debugLog } from '../../utils/logger';
|
||||||
import type { SongItemProps, QueueItem, Song } from '../../types';
|
import type { SongItemProps, QueueItem, Song } from '../../types';
|
||||||
|
import { SongItemContext } from '../../types';
|
||||||
import { ActionButtonVariant, ActionButtonSize, ActionButtonIconSlot } from '../../types';
|
import { ActionButtonVariant, ActionButtonSize, ActionButtonIconSlot } from '../../types';
|
||||||
import { Icons } from '../../constants';
|
import { Icons } from '../../constants';
|
||||||
|
|
||||||
@ -226,7 +227,7 @@ const SongItem: React.FC<SongItemProps> = React.memo(({
|
|||||||
|
|
||||||
// Find queue item key for removal (only needed for queue context)
|
// Find queue item key for removal (only needed for queue context)
|
||||||
const queueItemKey = useMemo(() =>
|
const queueItemKey = useMemo(() =>
|
||||||
context === 'queue'
|
context === SongItemContext.QUEUE
|
||||||
? (Object.entries(queue) as [string, QueueItem][]).find(([, item]) => item.song.path === song.path)?.[0]
|
? (Object.entries(queue) as [string, QueueItem][]).find(([, item]) => item.song.path === song.path)?.[0]
|
||||||
: null,
|
: null,
|
||||||
[context, queue, song.path]
|
[context, queue, song.path]
|
||||||
@ -242,14 +243,14 @@ const SongItem: React.FC<SongItemProps> = React.memo(({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Default values based on context if not explicitly provided
|
// Default values based on context if not explicitly provided
|
||||||
const shouldShowPath = showPath !== undefined ? showPath : context !== 'queue';
|
const shouldShowPath = showPath !== undefined ? showPath : context !== SongItemContext.QUEUE;
|
||||||
const shouldShowCount = showCount !== undefined ? showCount : context === 'queue';
|
const shouldShowCount = showCount !== undefined ? showCount : context === SongItemContext.QUEUE;
|
||||||
|
|
||||||
// Default values for action buttons based on context if not explicitly provided
|
// Default values for action buttons based on context if not explicitly provided
|
||||||
const shouldShowInfoButton = showInfoButton !== undefined ? showInfoButton : ['search', 'history'].includes(context);
|
const shouldShowInfoButton = showInfoButton !== undefined ? showInfoButton : [SongItemContext.SEARCH, SongItemContext.HISTORY].includes(context);
|
||||||
const shouldShowAddButton = showAddButton !== undefined ? showAddButton : ['search', 'history'].includes(context);
|
const shouldShowAddButton = showAddButton !== undefined ? showAddButton : [SongItemContext.SEARCH, SongItemContext.HISTORY].includes(context);
|
||||||
const shouldShowRemoveButton = showRemoveButton !== undefined ? showRemoveButton : context === 'queue' && isAdmin;
|
const shouldShowRemoveButton = showRemoveButton !== undefined ? showRemoveButton : context === SongItemContext.QUEUE && isAdmin;
|
||||||
const shouldShowDeleteButton = showDeleteButton !== undefined ? showDeleteButton : context === 'history' && isAdmin;
|
const shouldShowDeleteButton = showDeleteButton !== undefined ? showDeleteButton : context === SongItemContext.HISTORY && isAdmin;
|
||||||
const shouldShowFavoriteButton = showFavoriteButton !== undefined ? showFavoriteButton : false; // Disabled for all contexts
|
const shouldShowFavoriteButton = showFavoriteButton !== undefined ? showFavoriteButton : false; // Disabled for all contexts
|
||||||
|
|
||||||
// Memoized handler functions for performance
|
// Memoized handler functions for performance
|
||||||
@ -295,9 +296,9 @@ const SongItem: React.FC<SongItemProps> = React.memo(({
|
|||||||
showDeleteButton={shouldShowDeleteButton}
|
showDeleteButton={shouldShowDeleteButton}
|
||||||
showFavoriteButton={shouldShowFavoriteButton}
|
showFavoriteButton={shouldShowFavoriteButton}
|
||||||
onDeleteItem={onDeleteItem}
|
onDeleteItem={onDeleteItem}
|
||||||
onAddToQueue={context === 'queue' ? handleRemoveFromQueueClick : handleAddToQueueClick}
|
onAddToQueue={context === SongItemContext.QUEUE ? handleRemoveFromQueueClick : handleAddToQueueClick}
|
||||||
onRemoveFromQueue={context === 'queue' ? handleRemoveFromQueueClick : onDeleteItem}
|
onRemoveFromQueue={context === SongItemContext.QUEUE ? handleRemoveFromQueueClick : onDeleteItem}
|
||||||
onToggleFavorite={context === 'favorites' ? onDeleteItem : handleToggleFavoriteClick}
|
onToggleFavorite={context === SongItemContext.FAVORITES ? onDeleteItem : handleToggleFavoriteClick}
|
||||||
onShowSongInfo={handleSelectSinger}
|
onShowSongInfo={handleSelectSinger}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { useAppSelector } from '../../redux';
|
|||||||
import { selectFavorites } from '../../redux';
|
import { selectFavorites } from '../../redux';
|
||||||
import { debugLog } from '../../utils/logger';
|
import { debugLog } from '../../utils/logger';
|
||||||
import type { Song } from '../../types';
|
import type { Song } from '../../types';
|
||||||
|
import { SongItemContext } from '../../types';
|
||||||
|
|
||||||
const Favorites: React.FC = () => {
|
const Favorites: React.FC = () => {
|
||||||
const {
|
const {
|
||||||
@ -31,7 +32,7 @@ const Favorites: React.FC = () => {
|
|||||||
renderItem={(song) => (
|
renderItem={(song) => (
|
||||||
<SongItem
|
<SongItem
|
||||||
song={song}
|
song={song}
|
||||||
context="favorites"
|
context={SongItemContext.FAVORITES}
|
||||||
showInfoButton={true}
|
showInfoButton={true}
|
||||||
showAddButton={false}
|
showAddButton={false}
|
||||||
showDeleteButton={true}
|
showDeleteButton={true}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import { useAppSelector } from '../../redux';
|
|||||||
import { selectHistory, selectIsAdmin } from '../../redux';
|
import { selectHistory, selectIsAdmin } from '../../redux';
|
||||||
import { formatDate } from '../../utils/dataProcessing';
|
import { formatDate } from '../../utils/dataProcessing';
|
||||||
import type { Song } from '../../types';
|
import type { Song } from '../../types';
|
||||||
|
import { SongItemContext } from '../../types';
|
||||||
|
|
||||||
const History: React.FC = () => {
|
const History: React.FC = () => {
|
||||||
const {
|
const {
|
||||||
@ -54,7 +55,7 @@ const History: React.FC = () => {
|
|||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<SongItem
|
<SongItem
|
||||||
song={song}
|
song={song}
|
||||||
context="history"
|
context={SongItemContext.HISTORY}
|
||||||
onDeleteItem={() => handleDeleteFromHistory(song)}
|
onDeleteItem={() => handleDeleteFromHistory(song)}
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
showAddButton={true}
|
showAddButton={true}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { useAppSelector } from '../../redux';
|
|||||||
import { selectNewSongsArray } from '../../redux';
|
import { selectNewSongsArray } from '../../redux';
|
||||||
import { debugLog } from '../../utils/logger';
|
import { debugLog } from '../../utils/logger';
|
||||||
import type { Song } from '../../types';
|
import type { Song } from '../../types';
|
||||||
|
import { SongItemContext } from '../../types';
|
||||||
|
|
||||||
const NewSongs: React.FC = () => {
|
const NewSongs: React.FC = () => {
|
||||||
const {
|
const {
|
||||||
@ -30,7 +31,7 @@ const NewSongs: React.FC = () => {
|
|||||||
renderItem={(song) => (
|
renderItem={(song) => (
|
||||||
<SongItem
|
<SongItem
|
||||||
song={song}
|
song={song}
|
||||||
context="search"
|
context={SongItemContext.SEARCH}
|
||||||
showAddButton={true}
|
showAddButton={true}
|
||||||
showInfoButton={true}
|
showInfoButton={true}
|
||||||
showFavoriteButton={false}
|
showFavoriteButton={false}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { useSearch, useDebugLogging } from '../../hooks';
|
|||||||
import { useAppSelector } from '../../redux';
|
import { useAppSelector } from '../../redux';
|
||||||
import { selectIsAdmin, selectSongs } from '../../redux';
|
import { selectIsAdmin, selectSongs } from '../../redux';
|
||||||
import type { Song } from '../../types';
|
import type { Song } from '../../types';
|
||||||
|
import { SongItemContext } from '../../types';
|
||||||
|
|
||||||
const Search: React.FC = () => {
|
const Search: React.FC = () => {
|
||||||
const {
|
const {
|
||||||
@ -52,7 +53,7 @@ const Search: React.FC = () => {
|
|||||||
renderItem={(song) => (
|
renderItem={(song) => (
|
||||||
<SongItem
|
<SongItem
|
||||||
song={song}
|
song={song}
|
||||||
context="search"
|
context={SongItemContext.SEARCH}
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
showAddButton={true}
|
showAddButton={true}
|
||||||
showInfoButton={true}
|
showInfoButton={true}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import { useAppSelector } from '../../redux';
|
|||||||
import { selectSongList } from '../../redux';
|
import { selectSongList } from '../../redux';
|
||||||
import type { SongListSong, SongList, Song } from '../../types';
|
import type { SongListSong, SongList, Song } from '../../types';
|
||||||
import { debugLog } from '../../utils/logger';
|
import { debugLog } from '../../utils/logger';
|
||||||
|
import { SongItemContext } from '../../types';
|
||||||
|
|
||||||
const SongLists: React.FC = () => {
|
const SongLists: React.FC = () => {
|
||||||
const {
|
const {
|
||||||
@ -124,7 +125,7 @@ const SongLists: React.FC = () => {
|
|||||||
<SongItem
|
<SongItem
|
||||||
key={song.key || `${song.title}-${song.artist}-${sidx}`}
|
key={song.key || `${song.title}-${song.artist}-${sidx}`}
|
||||||
song={song}
|
song={song}
|
||||||
context="search"
|
context={SongItemContext.SEARCH}
|
||||||
showAddButton={true}
|
showAddButton={true}
|
||||||
showInfoButton={true}
|
showInfoButton={true}
|
||||||
showFavoriteButton={false}
|
showFavoriteButton={false}
|
||||||
|
|||||||
@ -164,9 +164,19 @@ export interface ActionButtonProps {
|
|||||||
'aria-label'?: string;
|
'aria-label'?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum SongItemContext {
|
||||||
|
SEARCH = 'search',
|
||||||
|
QUEUE = 'queue',
|
||||||
|
FAVORITES = 'favorites',
|
||||||
|
HISTORY = 'history',
|
||||||
|
SONGLISTS = 'songlists',
|
||||||
|
TOP100 = 'top100',
|
||||||
|
NEW = 'new',
|
||||||
|
}
|
||||||
|
|
||||||
export interface SongItemProps {
|
export interface SongItemProps {
|
||||||
song: Song;
|
song: Song;
|
||||||
context: 'search' | 'queue' | 'favorites' | 'history' | 'songlists' | 'top100' | 'new';
|
context: SongItemContext;
|
||||||
onDeleteItem?: () => void;
|
onDeleteItem?: () => void;
|
||||||
isAdmin?: boolean;
|
isAdmin?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user