Files
AdGuardHome/client/src/reducers/dashboard.js
Artem Krisanov 4afd39b22f AG-21136 - Added local storage theme key.
Updates#5444

Squashed commit of the following:

commit 7b0b108f41ebb5e98861cdd20029c12d3a3fc5f4
Merge: 38df28db0 e43ba1788
Author: Artem Krisanov <a.krisanov@adguard.com>
Date:   Mon Apr 17 15:58:15 2023 +0300

    Merge branch 'master' of ssh://bit.adguard.com:7999/dns/adguard-home into 5444-white-screen

commit 38df28db0739e47d3fb605f648fa493b58709d77
Author: Artem Krisanov <a.krisanov@adguard.com>
Date:   Fri Apr 14 17:54:00 2023 +0300

    Deleted useless tag.

commit 78ef9d911ccf74b69a9ae5626ea8f31cb9338ae0
Author: Artem Krisanov <a.krisanov@adguard.com>
Date:   Fri Apr 14 17:53:17 2023 +0300

    Set initial body data-theme.

commit f470b3aa79500edd0726b7ed37e6e5940b6ce3ff
Author: Artem Krisanov <a.krisanov@adguard.com>
Date:   Thu Apr 13 16:42:25 2023 +0300

    Revert login changes.

commit 7c4734ed02a670a59d0b9ff04e06bc1d396223a8
Author: Artem Krisanov <a.krisanov@adguard.com>
Date:   Thu Apr 13 15:51:24 2023 +0300

    Added setting theme into html.Changed overlay background color to variable.

commit a3743be0e69489489755db8ff55541b9a6281300
Author: Artem Krisanov <a.krisanov@adguard.com>
Date:   Wed Apr 12 17:58:47 2023 +0300

    Added local storage theme key.
2023-04-17 16:07:20 +03:00

186 lines
5.6 KiB
JavaScript

import { handleActions } from 'redux-actions';
import * as actions from '../actions';
import { areEqualVersions } from '../helpers/version';
import { STANDARD_DNS_PORT, STANDARD_WEB_PORT } from '../helpers/constants';
const dashboard = handleActions(
{
[actions.setDnsRunningStatus]: (state, { payload }) => (
{
...state,
isCoreRunning: payload,
}
),
[actions.dnsStatusRequest]: (state) => ({
...state,
processing: true,
}),
[actions.dnsStatusFailure]: (state) => ({
...state,
processing: false,
}),
[actions.dnsStatusSuccess]: (state, { payload }) => {
const {
version,
dns_port: dnsPort,
dns_addresses: dnsAddresses,
protection_enabled: protectionEnabled,
protection_disabled_duration: protectionDisabledDuration,
http_port: httpPort,
language,
} = payload;
const newState = {
...state,
isCoreRunning: true,
processing: false,
dnsVersion: version,
dnsPort,
dnsAddresses,
protectionEnabled,
protectionDisabledDuration,
language,
httpPort,
};
return newState;
},
[actions.getVersionRequest]: (state) => ({
...state,
processingVersion: true,
}),
[actions.getVersionFailure]: (state) => ({
...state,
processingVersion: false,
}),
[actions.getVersionSuccess]: (state, { payload }) => {
const currentVersion = state.dnsVersion === 'undefined' ? 0 : state.dnsVersion;
if (!payload.disabled && !areEqualVersions(currentVersion, payload.new_version)) {
const {
announcement_url: announcementUrl,
new_version: newVersion,
can_autoupdate: canAutoUpdate,
} = payload;
const newState = {
...state,
announcementUrl,
newVersion,
canAutoUpdate,
isUpdateAvailable: true,
processingVersion: false,
checkUpdateFlag: !payload.disabled,
};
return newState;
}
return {
...state,
processingVersion: false,
checkUpdateFlag: !payload.disabled,
};
},
[actions.getUpdateRequest]: (state) => ({
...state,
processingUpdate: true,
}),
[actions.getUpdateFailure]: (state) => ({
...state,
processingUpdate: false,
}),
[actions.getUpdateSuccess]: (state) => {
const newState = {
...state,
processingUpdate: false,
};
return newState;
},
[actions.toggleProtectionRequest]: (state) => ({
...state,
processingProtection: true,
}),
[actions.toggleProtectionFailure]: (state) => ({
...state,
processingProtection: false,
}),
[actions.toggleProtectionSuccess]: (state, { payload }) => {
const newState = {
...state,
protectionEnabled: !state.protectionEnabled,
processingProtection: false,
protectionDisabledDuration: payload.disabledDuration,
};
return newState;
},
[actions.setDisableDurationTime]: (state, { payload }) => ({
...state,
protectionDisabledDuration: payload.timeToEnableProtection,
}),
[actions.getClientsRequest]: (state) => ({
...state,
processingClients: true,
}),
[actions.getClientsFailure]: (state) => ({
...state,
processingClients: false,
}),
[actions.getClientsSuccess]: (state, { payload }) => {
const newState = {
...state,
...payload,
processingClients: false,
};
return newState;
},
[actions.getProfileRequest]: (state) => ({
...state,
processingProfile: true,
}),
[actions.getProfileFailure]: (state) => ({
...state,
processingProfile: false,
}),
[actions.getProfileSuccess]: (state, { payload }) => ({
...state,
name: payload.name,
theme: payload.theme,
processingProfile: false,
}),
[actions.changeThemeSuccess]: (state, { payload }) => ({
...state,
theme: payload.theme,
}),
},
{
processing: true,
isCoreRunning: true,
processingVersion: true,
processingClients: true,
processingUpdate: false,
processingProfile: true,
protectionEnabled: false,
protectionDisabledDuration: null,
protectionCountdownActive: false,
processingProtection: false,
httpPort: STANDARD_WEB_PORT,
dnsPort: STANDARD_DNS_PORT,
dnsAddresses: [],
dnsVersion: '',
clients: [],
autoClients: [],
supportedTags: [],
name: '',
theme: undefined,
checkUpdateFlag: false,
},
);
export default dashboard;