Project started 🥂
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { createSlice, type PayloadAction } from '@reduxjs/toolkit';
|
||||
|
||||
type RepeatMode = 'none' | 'one' | 'all';
|
||||
|
||||
interface PlayerState {
|
||||
currentTrackId: string | null;
|
||||
isPlaying: boolean;
|
||||
position: number;
|
||||
duration: number;
|
||||
volume: number;
|
||||
muted: boolean;
|
||||
repeat: RepeatMode;
|
||||
shuffle: boolean;
|
||||
isNowPlayingOpen: boolean;
|
||||
isQueueOpen: boolean;
|
||||
}
|
||||
|
||||
const initialState: PlayerState = {
|
||||
currentTrackId: null,
|
||||
isPlaying: false,
|
||||
position: 0,
|
||||
duration: 0,
|
||||
volume: 0.8,
|
||||
muted: false,
|
||||
repeat: 'none',
|
||||
shuffle: false,
|
||||
isNowPlayingOpen: false,
|
||||
isQueueOpen: false,
|
||||
};
|
||||
|
||||
export const playerSlice = createSlice({
|
||||
name: 'player',
|
||||
initialState,
|
||||
reducers: {
|
||||
play(state, action: PayloadAction<string>) {
|
||||
state.currentTrackId = action.payload;
|
||||
state.isPlaying = true;
|
||||
state.position = 0;
|
||||
},
|
||||
pause(state) { state.isPlaying = false; },
|
||||
resume(state) { state.isPlaying = true; },
|
||||
stop(state) { state.isPlaying = false; state.currentTrackId = null; state.position = 0; },
|
||||
setPosition(state, action: PayloadAction<number>) { state.position = action.payload; },
|
||||
setDuration(state, action: PayloadAction<number>) { state.duration = action.payload; },
|
||||
setVolume(state, action: PayloadAction<number>) { state.volume = action.payload; },
|
||||
toggleMute(state) { state.muted = !state.muted; },
|
||||
setRepeat(state, action: PayloadAction<RepeatMode>) { state.repeat = action.payload; },
|
||||
toggleShuffle(state) { state.shuffle = !state.shuffle; },
|
||||
toggleNowPlaying(state) { state.isNowPlayingOpen = !state.isNowPlayingOpen; },
|
||||
toggleQueue(state) { state.isQueueOpen = !state.isQueueOpen; },
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
play, pause, resume, stop,
|
||||
setPosition, setDuration,
|
||||
setVolume, toggleMute,
|
||||
setRepeat, toggleShuffle,
|
||||
toggleNowPlaying, toggleQueue,
|
||||
} = playerSlice.actions;
|
||||
export default playerSlice.reducer;
|
||||
Reference in New Issue
Block a user