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

This commit is contained in:
mbrucedogs 2025-07-20 13:51:18 -05:00
parent 58b393f937
commit 40cf5f6bc1
5 changed files with 40 additions and 7 deletions

View File

@ -4,7 +4,7 @@ import { time } from 'ionicons/icons';
import { InfiniteScrollList, SongItem } from '../../components/common'; import { InfiniteScrollList, SongItem } from '../../components/common';
import { useHistory } from '../../hooks'; import { useHistory } from '../../hooks';
import { useAppSelector } from '../../redux'; import { useAppSelector } from '../../redux';
import { selectHistory } from '../../redux'; import { selectHistory, selectIsAdmin } from '../../redux';
import { debugLog } from '../../utils/logger'; import { debugLog } from '../../utils/logger';
import { formatDate } from '../../utils/dataProcessing'; import { formatDate } from '../../utils/dataProcessing';
import type { Song } from '../../types'; import type { Song } from '../../types';
@ -15,10 +15,11 @@ const History: React.FC = () => {
hasMore, hasMore,
loadMore, loadMore,
handleAddToQueue, handleAddToQueue,
handleToggleFavorite, handleDeleteFromHistory,
} = useHistory(); } = useHistory();
const history = useAppSelector(selectHistory); const history = useAppSelector(selectHistory);
const isAdmin = useAppSelector(selectIsAdmin);
const historyCount = Object.keys(history).length; const historyCount = Object.keys(history).length;
// Debug logging // Debug logging
@ -52,7 +53,12 @@ const History: React.FC = () => {
song={song} song={song}
context="history" context="history"
onAddToQueue={() => handleAddToQueue(song)} onAddToQueue={() => handleAddToQueue(song)}
onToggleFavorite={() => handleToggleFavorite(song)} onDelete={() => handleDeleteFromHistory(song)}
isAdmin={isAdmin}
showAddButton={true}
showInfoButton={true}
showDeleteButton={true}
showFavoriteButton={false}
/> />
</div> </div>
{renderExtraContent(song)} {renderExtraContent(song)}

View File

@ -12,7 +12,6 @@ const NewSongs: React.FC = () => {
hasMore, hasMore,
loadMore, loadMore,
handleAddToQueue, handleAddToQueue,
handleToggleFavorite,
} = useNewSongs(); } = useNewSongs();
const newSongsArray = useAppSelector(selectNewSongsArray); const newSongsArray = useAppSelector(selectNewSongsArray);
@ -34,7 +33,9 @@ const NewSongs: React.FC = () => {
song={song} song={song}
context="search" context="search"
onAddToQueue={() => handleAddToQueue(song)} onAddToQueue={() => handleAddToQueue(song)}
onToggleFavorite={() => handleToggleFavorite(song)} showAddButton={true}
showInfoButton={true}
showFavoriteButton={false}
/> />
)} )}
emptyTitle="No new songs" emptyTitle="No new songs"

View File

@ -13,7 +13,6 @@ const Search: React.FC = () => {
searchResults, searchResults,
handleSearchChange, handleSearchChange,
handleAddToQueue, handleAddToQueue,
handleToggleFavorite,
loadMore, loadMore,
} = useSearch(); } = useSearch();
@ -65,9 +64,11 @@ const Search: React.FC = () => {
song={song} song={song}
context="search" context="search"
onAddToQueue={() => handleAddToQueue(song)} onAddToQueue={() => handleAddToQueue(song)}
onToggleFavorite={() => handleToggleFavorite(song)}
onSelectSinger={() => openSongInfo(song)} onSelectSinger={() => openSongInfo(song)}
isAdmin={isAdmin} isAdmin={isAdmin}
showAddButton={true}
showInfoButton={true}
showFavoriteButton={false}
/> />
)} )}
emptyTitle={searchTerm ? "No songs found" : "No songs available"} emptyTitle={searchTerm ? "No songs found" : "No songs available"}

View File

@ -166,6 +166,12 @@ export const historyService = {
return await push(historyRef, song); return await push(historyRef, song);
}, },
// Remove song from history
removeFromHistory: async (controllerName: string, historyItemKey: string) => {
const historyItemRef = ref(database, `controllers/${controllerName}/history/${historyItemKey}`);
await remove(historyItemRef);
},
// Listen to history changes // Listen to history changes
subscribeToHistory: (controllerName: string, callback: (data: Record<string, Song>) => void) => { subscribeToHistory: (controllerName: string, callback: (data: Record<string, Song>) => void) => {
const historyRef = ref(database, `controllers/${controllerName}/history`); const historyRef = ref(database, `controllers/${controllerName}/history`);

View File

@ -4,12 +4,16 @@ import { debugLog } from '../utils/logger';
import { useSongOperations } from './useSongOperations'; import { useSongOperations } from './useSongOperations';
import { useToast } from './useToast'; import { useToast } from './useToast';
import { useDisabledSongs } from './useDisabledSongs'; import { useDisabledSongs } from './useDisabledSongs';
import { historyService } from '../firebase/services';
import { useAppSelector as useAppSelectorRedux } from '../redux';
import { selectControllerName } from '../redux';
import type { Song } from '../types'; import type { Song } from '../types';
const ITEMS_PER_PAGE = 20; const ITEMS_PER_PAGE = 20;
export const useHistory = () => { export const useHistory = () => {
const allHistoryItems = useAppSelector(selectHistoryArray); const allHistoryItems = useAppSelector(selectHistoryArray);
const controllerName = useAppSelectorRedux(selectControllerName);
const { addToQueue, toggleFavorite } = useSongOperations(); const { addToQueue, toggleFavorite } = useSongOperations();
const { showSuccess, showError } = useToast(); const { showSuccess, showError } = useToast();
const { disabledSongPaths, isSongDisabled, addDisabledSong, removeDisabledSong, loading: disabledSongsLoading } = useDisabledSongs(); const { disabledSongPaths, isSongDisabled, addDisabledSong, removeDisabledSong, loading: disabledSongsLoading } = useDisabledSongs();
@ -82,6 +86,20 @@ export const useHistory = () => {
} }
}, [isSongDisabled, addDisabledSong, removeDisabledSong, showError]); }, [isSongDisabled, addDisabledSong, removeDisabledSong, showError]);
const handleDeleteFromHistory = useCallback(async (song: Song) => {
if (!controllerName || !song.key) {
showError('Cannot delete history item - missing data');
return;
}
try {
await historyService.removeFromHistory(controllerName, song.key);
showSuccess('Removed from history');
} catch {
showError('Failed to remove from history');
}
}, [controllerName, showSuccess, showError]);
return { return {
historyItems, historyItems,
hasMore, hasMore,
@ -89,6 +107,7 @@ export const useHistory = () => {
handleAddToQueue, handleAddToQueue,
handleToggleFavorite, handleToggleFavorite,
handleToggleDisabled, handleToggleDisabled,
handleDeleteFromHistory,
isSongDisabled, isSongDisabled,
}; };
}; };