mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
feat: enable scrobbling on song repeat and fix package name typo (#1662)
- Add `handleScrobbleFromRepeat` callback to reset scrobble state and send 'start' event when player repeats a song, ensuring accurate scrobbling in repeat mode. - Fix typo in `web.vite.config.ts` by correcting '@tanstack_react-query-persist-client' to '@tanstack/react-query-persist-client' for proper package reference.
This commit is contained in:
@@ -407,6 +407,47 @@ export const useScrobble = () => {
|
|||||||
[isScrobbleEnabled, isPrivateModeEnabled, sendScrobble],
|
[isScrobbleEnabled, isPrivateModeEnabled, sendScrobble],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleScrobbleFromRepeat = useCallback(() => {
|
||||||
|
if (!isScrobbleEnabled || isPrivateModeEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentSong = usePlayerStore.getState().getCurrentSong();
|
||||||
|
const currentStatus = usePlayerStore.getState().player.status;
|
||||||
|
|
||||||
|
if (currentStatus !== PlayerStatus.PLAYING || !currentSong?.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsCurrentSongScrobbled(false);
|
||||||
|
lastProgressEventRef.current = 0;
|
||||||
|
previousTimestampRef.current = 0;
|
||||||
|
|
||||||
|
sendScrobble.mutate(
|
||||||
|
{
|
||||||
|
apiClientProps: { serverId: currentSong._serverId || '' },
|
||||||
|
query: {
|
||||||
|
albumId: currentSong.albumId,
|
||||||
|
event: 'start',
|
||||||
|
id: currentSong.id,
|
||||||
|
position: 0,
|
||||||
|
submission: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess: () => {
|
||||||
|
logFn.debug(logMsg[LogCategory.SCROBBLE].scrobbledStart, {
|
||||||
|
category: LogCategory.SCROBBLE,
|
||||||
|
meta: {
|
||||||
|
id: currentSong.id,
|
||||||
|
reason: 'from repeat',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}, [isScrobbleEnabled, isPrivateModeEnabled, sendScrobble]);
|
||||||
|
|
||||||
// Update previous timestamp on progress for use in status change handler
|
// Update previous timestamp on progress for use in status change handler
|
||||||
const handleProgressUpdate = useCallback(
|
const handleProgressUpdate = useCallback(
|
||||||
(properties: { timestamp: number }, prev: { timestamp: number }) => {
|
(properties: { timestamp: number }, prev: { timestamp: number }) => {
|
||||||
@@ -420,10 +461,17 @@ export const useScrobble = () => {
|
|||||||
{
|
{
|
||||||
onCurrentSongChange: handleScrobbleFromSongChange,
|
onCurrentSongChange: handleScrobbleFromSongChange,
|
||||||
onPlayerProgress: handleProgressUpdate,
|
onPlayerProgress: handleProgressUpdate,
|
||||||
|
onPlayerRepeated: handleScrobbleFromRepeat,
|
||||||
onPlayerSeekToTimestamp: handleScrobbleFromSeek,
|
onPlayerSeekToTimestamp: handleScrobbleFromSeek,
|
||||||
onPlayerStatus: handleScrobbleFromStatus,
|
onPlayerStatus: handleScrobbleFromStatus,
|
||||||
},
|
},
|
||||||
[handleScrobbleFromSongChange, handleProgressUpdate, handleScrobbleFromSeek],
|
[
|
||||||
|
handleScrobbleFromSongChange,
|
||||||
|
handleProgressUpdate,
|
||||||
|
handleScrobbleFromRepeat,
|
||||||
|
handleScrobbleFromSeek,
|
||||||
|
handleScrobbleFromStatus,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ export default defineConfig({
|
|||||||
'@atlaskit/pragmatic-drag-and-drop',
|
'@atlaskit/pragmatic-drag-and-drop',
|
||||||
'@atlaskit/pragmatic-drag-and-drop-auto-scroll',
|
'@atlaskit/pragmatic-drag-and-drop-auto-scroll',
|
||||||
'@atlaskit/pragmatic-drag-and-drop-hitbox',
|
'@atlaskit/pragmatic-drag-and-drop-hitbox',
|
||||||
'@tanstack_react-query-persist-client',
|
'@tanstack/react-query-persist-client',
|
||||||
'idb-keyval',
|
'idb-keyval',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user