1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { CollectionUploaderAction, collectionUploaderActions, UploadFile } from "./collection-uploader-actions";
6 import * as _ from 'lodash';
8 export type CollectionUploaderState = UploadFile[];
10 const initialState: CollectionUploaderState = [];
12 export const collectionUploaderReducer = (state: CollectionUploaderState = initialState, action: CollectionUploaderAction) => {
13 return collectionUploaderActions.match(action, {
14 SET_UPLOAD_FILES: files => files.map((f, idx) => ({
25 const startTime = Date.now();
26 return state.map(f => ({...f, startTime, prevTime: startTime}));
28 SET_UPLOAD_PROGRESS: ({ fileId, loaded, total, currentTime }) => {
29 const files = _.cloneDeep(state);
30 const f = files.find(f => f.id === fileId);
32 f.prevLoaded = f.loaded;
35 f.prevTime = f.currentTime;
36 f.currentTime = currentTime;