2020-06-17 14:58:04 +02:00
|
|
|
import { createReducer } from '@reduxjs/toolkit';
|
2023-07-31 00:32:05 +03:00
|
|
|
import { setReceivedErrorReportingAlert, setBitrate, setJellyfinCredentials, setOnboardingStatus, setEnablePlaybackReporting, setColorScheme, setDateTime, setEnableSleepTime, setRemainingSleepTime } from './actions';
|
2023-04-28 21:01:21 +02:00
|
|
|
import { ColorScheme } from './types';
|
2020-06-17 14:58:04 +02:00
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
|
jellyfin?: {
|
|
|
|
|
uri: string;
|
|
|
|
|
user_id: string;
|
|
|
|
|
access_token: string;
|
|
|
|
|
device_id: string;
|
|
|
|
|
}
|
|
|
|
|
bitrate: number;
|
2020-08-09 17:49:36 +02:00
|
|
|
isOnboardingComplete: boolean;
|
2021-02-13 15:34:43 +01:00
|
|
|
hasReceivedErrorReportingAlert: boolean;
|
2023-04-27 15:08:10 +02:00
|
|
|
enablePlaybackReporting: boolean;
|
2023-04-28 21:01:21 +02:00
|
|
|
colorScheme: ColorScheme;
|
2023-07-31 00:32:05 +03:00
|
|
|
dateTime?: Date;
|
|
|
|
|
enableSleepTime: boolean
|
2020-06-17 14:58:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const initialState: State = {
|
2020-08-09 17:49:36 +02:00
|
|
|
bitrate: 140000000,
|
|
|
|
|
isOnboardingComplete: false,
|
2021-02-13 15:34:43 +01:00
|
|
|
hasReceivedErrorReportingAlert: false,
|
2023-04-27 15:08:10 +02:00
|
|
|
enablePlaybackReporting: true,
|
2023-04-28 21:01:21 +02:00
|
|
|
colorScheme: ColorScheme.System,
|
2023-07-31 00:32:05 +03:00
|
|
|
dateTime: new Date(),
|
|
|
|
|
enableSleepTime: false
|
2020-06-17 14:58:04 +02:00
|
|
|
};
|
|
|
|
|
|
2022-11-17 21:08:07 +01:00
|
|
|
const settings = createReducer(initialState, builder => {
|
|
|
|
|
builder.addCase(setJellyfinCredentials, (state, action) => ({
|
2020-06-17 14:58:04 +02:00
|
|
|
...state,
|
|
|
|
|
jellyfin: action.payload,
|
2022-11-17 21:08:07 +01:00
|
|
|
}));
|
|
|
|
|
builder.addCase(setBitrate, (state, action) => ({
|
2020-06-17 14:58:04 +02:00
|
|
|
...state,
|
|
|
|
|
bitrate: action.payload,
|
2022-11-17 21:08:07 +01:00
|
|
|
}));
|
|
|
|
|
builder.addCase(setOnboardingStatus, (state, action) => ({
|
2020-08-09 17:49:36 +02:00
|
|
|
...state,
|
|
|
|
|
isOnboardingComplete: action.payload,
|
2022-11-17 21:08:07 +01:00
|
|
|
}));
|
|
|
|
|
builder.addCase(setReceivedErrorReportingAlert, (state) => ({
|
2021-02-13 15:34:43 +01:00
|
|
|
...state,
|
|
|
|
|
hasReceivedErrorReportingAlert: true,
|
2022-11-17 21:08:07 +01:00
|
|
|
}));
|
2023-04-27 15:08:10 +02:00
|
|
|
builder.addCase(setEnablePlaybackReporting, (state, action) => ({
|
|
|
|
|
...state,
|
|
|
|
|
enablePlaybackReporting: action.payload,
|
|
|
|
|
}));
|
2023-04-28 21:01:21 +02:00
|
|
|
builder.addCase(setColorScheme, (state, action) => ({
|
|
|
|
|
...state,
|
|
|
|
|
colorScheme: action.payload,
|
|
|
|
|
}));
|
2023-07-31 00:32:05 +03:00
|
|
|
builder.addCase(setDateTime, (state, action) => ({
|
2023-07-20 03:34:04 +03:00
|
|
|
...state,
|
2023-07-31 00:32:05 +03:00
|
|
|
dateTime: action.payload,
|
2023-07-20 03:34:04 +03:00
|
|
|
}));
|
2023-07-31 00:32:05 +03:00
|
|
|
builder.addCase(setEnableSleepTime, (state, action) => ({
|
2023-07-20 03:34:04 +03:00
|
|
|
...state,
|
2023-07-31 00:32:05 +03:00
|
|
|
enableSleepTime: action.payload,
|
2023-07-20 03:34:04 +03:00
|
|
|
}));
|
|
|
|
|
builder.addCase(setRemainingSleepTime, (state, action) => ({
|
|
|
|
|
...state,
|
|
|
|
|
remainingSleepTime: action.payload,
|
|
|
|
|
}));
|
2020-06-17 14:58:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default settings;
|