storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/uploads/reducer.js (about) 1 /* 2 * MinIO Cloud Storage (C) 2018 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import * as uploadsActions from "./actions" 18 19 const add = (files, action) => ({ 20 ...files, 21 [action.slug]: { 22 loaded: 0, 23 size: action.size, 24 name: action.name 25 } 26 }) 27 28 const updateProgress = (files, action) => ({ 29 ...files, 30 [action.slug]: { 31 ...files[action.slug], 32 loaded: action.loaded 33 } 34 }) 35 36 const stop = (files, action) => { 37 const newFiles = Object.assign({}, files) 38 delete newFiles[action.slug] 39 return newFiles 40 } 41 42 export default (state = { files: {}, showAbortModal: false }, action) => { 43 switch (action.type) { 44 case uploadsActions.ADD: 45 return { 46 ...state, 47 files: add(state.files, action) 48 } 49 case uploadsActions.UPDATE_PROGRESS: 50 return { 51 ...state, 52 files: updateProgress(state.files, action) 53 } 54 case uploadsActions.STOP: 55 return { 56 ...state, 57 files: stop(state.files, action) 58 } 59 case uploadsActions.SHOW_ABORT_MODAL: 60 return { 61 ...state, 62 showAbortModal: action.show 63 } 64 default: 65 return state 66 } 67 }