mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-17 08:54:27 +02:00
refactor scrobbling to use duration instead of progress (#2010)
- add scrobble status debug and indicator - add force / reset scrobble
This commit is contained in:
@@ -2,6 +2,7 @@ export * from './app.store';
|
||||
export * from './auth.store';
|
||||
export * from './full-screen-player.store';
|
||||
export * from './player.store';
|
||||
export * from './scrobble-debug.store';
|
||||
export * from './scroll.store';
|
||||
export * from './settings.store';
|
||||
export * from './timestamp.store';
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { createWithEqualityFn } from 'zustand/traditional';
|
||||
|
||||
import { PlayerStatus } from '/@/shared/types/types';
|
||||
|
||||
export type ScrobbleDebugSnapshot = {
|
||||
eligibilityMet: boolean;
|
||||
lastListenSampleTimeSec: null | number;
|
||||
listenedMs: number;
|
||||
playerStatus: PlayerStatus;
|
||||
positionSec: number;
|
||||
songId?: string;
|
||||
songName?: string;
|
||||
submitted: boolean;
|
||||
targetDurationSec: number;
|
||||
targetPercentage: number;
|
||||
trackDurationMs: number;
|
||||
};
|
||||
|
||||
const initialSnapshot: ScrobbleDebugSnapshot = {
|
||||
eligibilityMet: false,
|
||||
lastListenSampleTimeSec: null,
|
||||
listenedMs: 0,
|
||||
playerStatus: PlayerStatus.PAUSED,
|
||||
positionSec: 0,
|
||||
songId: undefined,
|
||||
songName: undefined,
|
||||
submitted: false,
|
||||
targetDurationSec: 240,
|
||||
targetPercentage: 75,
|
||||
trackDurationMs: 0,
|
||||
};
|
||||
|
||||
type ScrobbleDebugStore = {
|
||||
snapshot: ScrobbleDebugSnapshot;
|
||||
};
|
||||
|
||||
export const useScrobbleDebugStore = createWithEqualityFn<ScrobbleDebugStore>()(() => ({
|
||||
snapshot: initialSnapshot,
|
||||
}));
|
||||
|
||||
export const publishScrobbleDebug = (partial: Partial<ScrobbleDebugSnapshot>) => {
|
||||
useScrobbleDebugStore.setState((state) => ({
|
||||
snapshot: { ...state.snapshot, ...partial },
|
||||
}));
|
||||
};
|
||||
Reference in New Issue
Block a user