MCPcopy Index your code
hub / github.com/nukeop/nuclear / getDirectionalIndex

Function getDirectionalIndex

packages/player/src/stores/queueStore.ts:44–73  ·  view source on GitHub ↗
(
  state: Pick<QueueStore, 'items' | 'currentIndex'>,
  direction: 'forward' | 'backward',
)

Source from the content-addressed store, hash-verified

42});
43
44const getDirectionalIndex = (
45 state: Pick<QueueStore, 'items' | 'currentIndex'>,
46 direction: 'forward' | 'backward',
47): number => {
48 const { items, currentIndex } = state;
49 const shuffleEnabled =
50 (getSetting('core.playback.shuffle') as boolean) ?? false;
51 const repeatMode = (getSetting('core.playback.repeat') as string) ?? 'off';
52
53 if (items.length === 0) {
54 return currentIndex;
55 }
56
57 if (shuffleEnabled) {
58 return getShuffledIndex(items.length, currentIndex);
59 }
60
61 if (direction === 'forward') {
62 if (currentIndex < items.length - 1) {
63 return currentIndex + 1;
64 }
65 return repeatMode === 'all' ? 0 : currentIndex;
66 }
67
68 if (currentIndex > 0) {
69 return currentIndex - 1;
70 }
71
72 return repeatMode === 'all' ? items.length - 1 : currentIndex;
73};
74
75const getShuffledIndex = (length: number, currentIndex: number): number => {
76 if (length <= 1) {

Callers 1

queueStore.tsFile · 0.85

Calls 2

getSettingFunction · 0.90
getShuffledIndexFunction · 0.85

Tested by

no test coverage detected