fix: move sleep-timer to separate reducer
This commit is contained in:
@@ -9,6 +9,7 @@ import music, { initialState as musicInitialState } from './music';
|
||||
import downloads, { initialState as downloadsInitialState } from './downloads';
|
||||
import { PersistState } from 'redux-persist/es/types';
|
||||
import { ColorScheme } from './settings/types';
|
||||
import sleepTimer from './sleep-timer';
|
||||
|
||||
const persistConfig: PersistConfig<Omit<AppState, '_persist'>> = {
|
||||
key: 'root',
|
||||
@@ -59,9 +60,8 @@ const persistConfig: PersistConfig<Omit<AppState, '_persist'>> = {
|
||||
4: (state: AppState) => {
|
||||
return {
|
||||
...state,
|
||||
music: {
|
||||
...state.music,
|
||||
timerDate: Date
|
||||
sleepTimer: {
|
||||
date: null,
|
||||
}
|
||||
};
|
||||
},
|
||||
@@ -72,6 +72,7 @@ const reducers = combineReducers({
|
||||
settings,
|
||||
music: music.reducer,
|
||||
downloads: downloads.reducer,
|
||||
sleepTimer: sleepTimer.reducer,
|
||||
});
|
||||
|
||||
const persistedReducer = persistReducer(persistConfig, reducers);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createAction, createAsyncThunk, createEntityAdapter } from '@reduxjs/toolkit';
|
||||
import { createAsyncThunk, createEntityAdapter } from '@reduxjs/toolkit';
|
||||
import { Album, AlbumTrack, Playlist } from './types';
|
||||
import { AsyncThunkAPI } from '..';
|
||||
import { retrieveAllAlbums, retrieveAlbumTracks, retrieveRecentAlbums, searchItem, retrieveAlbum, retrieveAllPlaylists, retrievePlaylistTracks } from '@/utility/JellyfinApi';
|
||||
@@ -111,6 +111,4 @@ export const fetchTracksByPlaylist = createAsyncThunk<AlbumTrack[], string, Asyn
|
||||
const credentials = thunkAPI.getState().settings.jellyfin;
|
||||
return retrievePlaylistTracks(ItemId, credentials) as Promise<AlbumTrack[]>;
|
||||
}
|
||||
);
|
||||
|
||||
export const setTimerDate = createAction<Date|null>('SET_TIMER_DATE');
|
||||
);
|
||||
@@ -8,8 +8,7 @@ import {
|
||||
playlistAdapter,
|
||||
fetchAllPlaylists,
|
||||
fetchTracksByPlaylist,
|
||||
fetchAlbum,
|
||||
setTimerDate
|
||||
fetchAlbum
|
||||
} from './actions';
|
||||
import { createSlice, Dictionary, EntityId } from '@reduxjs/toolkit';
|
||||
import { Album, AlbumTrack, Playlist } from './types';
|
||||
@@ -34,8 +33,7 @@ export interface State {
|
||||
entities: Dictionary<Playlist>;
|
||||
ids: EntityId[];
|
||||
lastRefreshed?: number,
|
||||
},
|
||||
timerDate?: Date | null;
|
||||
}
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
@@ -52,8 +50,7 @@ export const initialState: State = {
|
||||
playlists: {
|
||||
...playlistAdapter.getInitialState(),
|
||||
isLoading: false,
|
||||
},
|
||||
timerDate: null
|
||||
}
|
||||
};
|
||||
|
||||
const music = createSlice({
|
||||
@@ -156,11 +153,6 @@ const music = createSlice({
|
||||
|
||||
// Reset any caches we have when a new server is set
|
||||
builder.addCase(setJellyfinCredentials, () => initialState);
|
||||
|
||||
builder.addCase(setTimerDate, (state, action) => ({
|
||||
...state,
|
||||
timerDate: action.payload,
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
23
src/store/sleep-timer/index.ts
Normal file
23
src/store/sleep-timer/index.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { PayloadAction, createSlice } from '@reduxjs/toolkit';
|
||||
|
||||
export interface State {
|
||||
date: number | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
date: null,
|
||||
};
|
||||
|
||||
const sleepTimer = createSlice({
|
||||
name: 'sleep-timer',
|
||||
initialState,
|
||||
reducers: {
|
||||
setTimerDate(state, action: PayloadAction<Date | null>) {
|
||||
state.date = action.payload?.getTime() || null;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const { setTimerDate } = sleepTimer.actions;
|
||||
|
||||
export default sleepTimer;
|
||||
Reference in New Issue
Block a user