55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
import { createReducer } from '@reduxjs/toolkit';
|
|
|
|
import {
|
|
SET_DOWNLOAD_BEGIN,
|
|
setAllowDownload,
|
|
setDownloadEnd,
|
|
setDownloadProgress,
|
|
} from '../actions/download_actions';
|
|
|
|
const defaultDownloadState = {
|
|
DownloadActive: false,
|
|
DownloadingDependency: false,
|
|
DownloadingRelease: false,
|
|
DownloadingUpgrade: false,
|
|
DownloadName: '',
|
|
DownloadProgress: 0.0,
|
|
DownloadResult: null,
|
|
DownloadType: null,
|
|
};
|
|
|
|
export const downloadReducer = createReducer(
|
|
{
|
|
...defaultDownloadState,
|
|
AllowDownload: false,
|
|
},
|
|
{
|
|
[setAllowDownload]: (state, action) => {
|
|
return {
|
|
...state,
|
|
AllowDownload: action.payload,
|
|
};
|
|
},
|
|
[SET_DOWNLOAD_BEGIN]: (state, action) => {
|
|
return {
|
|
...state,
|
|
...defaultDownloadState,
|
|
DownloadActive: true,
|
|
DownloadName: action.payload.name,
|
|
DownloadType: action.payload.type,
|
|
DownloadURL: action.payload.url,
|
|
};
|
|
},
|
|
[setDownloadEnd]: (state, action) => {
|
|
return {
|
|
...state,
|
|
...defaultDownloadState,
|
|
DownloadResult: action.payload,
|
|
};
|
|
},
|
|
[setDownloadProgress]: (state, action) => {
|
|
return { ...state, DownloadProgress: action.payload };
|
|
},
|
|
}
|
|
);
|