jeffvli
3 years ago
4 changed files with 155 additions and 77 deletions
@ -1,49 +1,89 @@ |
|||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; |
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; |
||||
|
|
||||
type PlayQueueTypes = [ |
interface Entry { |
||||
{ |
id: string; |
||||
id: string; |
album: string; |
||||
album: string; |
albumId: string; |
||||
albumId: string; |
artist: string; |
||||
artist: string; |
bitRate: number; |
||||
bitRate: number; |
contentType: string; |
||||
contentType: string; |
coverArt: string; |
||||
coverArt: string; |
created: string; |
||||
created: string; |
duration: string; |
||||
duration: string; |
genre: string; |
||||
genre: string; |
index: number; |
||||
index: number; |
isDir: boolean; |
||||
isDir: boolean; |
isVideo: boolean; |
||||
isVideo: boolean; |
parent: string; |
||||
parent: string; |
path: string; |
||||
path: string; |
playCount: number; |
||||
playCount: number; |
size: number; |
||||
size: number; |
starred?: string; |
||||
starred?: string; |
streamUrl: string; |
||||
streamUrl: string; |
suffix: string; |
||||
suffix: string; |
title: string; |
||||
title: string; |
track: number; |
||||
track: number; |
type: string; |
||||
type: string; |
year: number; |
||||
year: number; |
} |
||||
} |
|
||||
]; |
|
||||
|
|
||||
const initialState: PlayQueueTypes[] = []; |
interface PlayQueue { |
||||
|
currentIndex: number; |
||||
|
volume: number; |
||||
|
isLoading: boolean; |
||||
|
entry: Entry[]; |
||||
|
} |
||||
|
|
||||
|
const initialState: PlayQueue = { |
||||
|
currentIndex: 0, |
||||
|
volume: 0.5, |
||||
|
isLoading: false, |
||||
|
entry: [], |
||||
|
}; |
||||
|
|
||||
const playQueueSlice = createSlice({ |
const playQueueSlice = createSlice({ |
||||
name: 'nowPlaying', |
name: 'nowPlaying', |
||||
initialState, |
initialState, |
||||
reducers: { |
reducers: { |
||||
setPlayQueue: (state, action: PayloadAction<PlayQueueTypes>) => { |
incrementCurrentIndex: (state) => { |
||||
action.payload.map((entry: any) => state.push(entry)); |
if (state.currentIndex <= state.entry.length) { |
||||
|
state.currentIndex += 1; |
||||
|
} else { |
||||
|
state.currentIndex = 0; |
||||
|
} |
||||
|
}, |
||||
|
decrementCurrentIndex: (state) => { |
||||
|
if (state.currentIndex >= 0) { |
||||
|
state.currentIndex -= 1; |
||||
|
} |
||||
|
}, |
||||
|
setCurrentIndex: (state, action: PayloadAction<PlayQueue>) => { |
||||
|
state.currentIndex = action.payload.currentIndex; |
||||
}, |
}, |
||||
appendPlayQueue: (state, action: PayloadAction<PlayQueueTypes>) => { |
setPlayQueue: (state, action: PayloadAction<Entry[]>) => { |
||||
action.payload.map((entry: any) => state.push(entry)); |
state.currentIndex = 0; |
||||
|
action.payload.map((entry: any) => state.entry.push(entry)); |
||||
|
}, |
||||
|
appendPlayQueue: (state, action: PayloadAction<Entry[]>) => { |
||||
|
action.payload.map((entry: any) => state.entry.push(entry)); |
||||
}, |
}, |
||||
clearPlayQueue: () => initialState, |
clearPlayQueue: () => initialState, |
||||
|
setIsLoading: (state) => { |
||||
|
state.isLoading = true; |
||||
|
}, |
||||
|
setIsLoaded: (state) => { |
||||
|
state.isLoading = false; |
||||
|
}, |
||||
}, |
}, |
||||
}); |
}); |
||||
|
|
||||
export const { setPlayQueue, clearPlayQueue } = playQueueSlice.actions; |
export const { |
||||
|
incrementCurrentIndex, |
||||
|
decrementCurrentIndex, |
||||
|
setCurrentIndex, |
||||
|
setPlayQueue, |
||||
|
clearPlayQueue, |
||||
|
setIsLoading, |
||||
|
setIsLoaded, |
||||
|
} = playQueueSlice.actions; |
||||
export default playQueueSlice.reducer; |
export default playQueueSlice.reducer; |
||||
|
Loading…
Reference in new issue