From 0f211b00b89ddf8f23227bf7ef0ad00d8031b9ed Mon Sep 17 00:00:00 2001 From: Lei Nelissen Date: Sun, 28 Jan 2024 23:52:53 +0100 Subject: [PATCH] fix: move sleep-timer to separate reducer --- src/store/index.ts | 7 ++++--- src/store/music/actions.ts | 6 ++---- src/store/music/index.ts | 14 +++----------- src/store/sleep-timer/index.ts | 23 +++++++++++++++++++++++ 4 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 src/store/sleep-timer/index.ts diff --git a/src/store/index.ts b/src/store/index.ts index 9d2368d..964451b 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -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> = { key: 'root', @@ -59,9 +60,8 @@ const persistConfig: PersistConfig> = { 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); diff --git a/src/store/music/actions.ts b/src/store/music/actions.ts index 4b99cad..8cb8085 100644 --- a/src/store/music/actions.ts +++ b/src/store/music/actions.ts @@ -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; } -); - -export const setTimerDate = createAction('SET_TIMER_DATE'); \ No newline at end of file +); \ No newline at end of file diff --git a/src/store/music/index.ts b/src/store/music/index.ts index a736b93..7777913 100644 --- a/src/store/music/index.ts +++ b/src/store/music/index.ts @@ -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; 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, - })); } }); diff --git a/src/store/sleep-timer/index.ts b/src/store/sleep-timer/index.ts new file mode 100644 index 0000000..f968838 --- /dev/null +++ b/src/store/sleep-timer/index.ts @@ -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) { + state.date = action.payload?.getTime() || null; + } + }, +}); + +export const { setTimerDate } = sleepTimer.actions; + +export default sleepTimer; \ No newline at end of file