File tree Expand file tree Collapse file tree 3 files changed +27
-29
lines changed Expand file tree Collapse file tree 3 files changed +27
-29
lines changed Original file line number Diff line number Diff line change @@ -131,8 +131,6 @@ export const CLEAR_PERSISTED_STATE = 'CLEAR_PERSISTED_STATE';
131131
132132export const HIDE_RUNTIME_ERROR_WARNING = 'HIDE_RUNTIME_ERROR_WARNING' ;
133133export const SHOW_RUNTIME_ERROR_WARNING = 'SHOW_RUNTIME_ERROR_WARNING' ;
134- export const SET_ASSETS = 'SET_ASSETS' ;
135- export const DELETE_ASSET = 'DELETE_ASSET' ;
136134
137135export const TOGGLE_DIRECTION = 'TOGGLE_DIRECTION' ;
138136export const SET_SORTING = 'SET_SORTING' ;
Original file line number Diff line number Diff line change 11import apiClient from '../../../utils/apiClient' ;
22import * as ActionTypes from '../../../constants' ;
33import { startLoader , stopLoader } from './loader' ;
4+ import { assetsActions } from '../reducers/assets' ;
45
5- function setAssets ( assets , totalSize ) {
6- return {
7- type : ActionTypes . SET_ASSETS ,
8- assets,
9- totalSize
10- } ;
11- }
6+ const { setAssets, deleteAsset } = assetsActions ;
127
138export function getAssets ( ) {
149 return ( dispatch ) => {
1510 dispatch ( startLoader ( ) ) ;
1611 apiClient
1712 . get ( '/S3/objects' )
1813 . then ( ( response ) => {
19- dispatch ( setAssets ( response . data . assets , response . data . totalSize ) ) ;
14+ dispatch (
15+ setAssets ( {
16+ list : response . data . assets ,
17+ totalSize : response . data . totalSize
18+ } )
19+ ) ;
2020 dispatch ( stopLoader ( ) ) ;
2121 } )
2222 . catch ( ( ) => {
@@ -28,13 +28,6 @@ export function getAssets() {
2828 } ;
2929}
3030
31- export function deleteAsset ( assetKey ) {
32- return {
33- type : ActionTypes . DELETE_ASSET ,
34- key : assetKey
35- } ;
36- }
37-
3831export function deleteAssetRequest ( assetKey ) {
3932 return ( dispatch ) => {
4033 apiClient
Original file line number Diff line number Diff line change 1- import * as ActionTypes from '../../../constants ' ;
1+ import { createSlice } from '@reduxjs/toolkit ' ;
22
3- // 1,000,000 bytes in a MB. can't upload if totalSize is bigger than this.
43const initialState = {
54 list : [ ] ,
65 totalSize : 0
76} ;
87
9- const assets = ( state = initialState , action ) => {
10- switch ( action . type ) {
11- case ActionTypes . SET_ASSETS :
12- return { list : action . assets , totalSize : action . totalSize } ;
13- case ActionTypes . DELETE_ASSET :
14- return { list : state . list . filter ( ( asset ) => asset . key !== action . key ) } ;
15- default :
16- return state ;
8+ const assetsSlice = createSlice ( {
9+ name : 'assets' ,
10+ initialState,
11+ reducers : {
12+ setAssets : ( state , action ) => action . payload ,
13+ deleteAsset : ( state , action ) => {
14+ const key = action . payload ;
15+ const index = state . list . findIndex ( ( asset ) => asset . key === key ) ;
16+ if ( index !== - 1 ) {
17+ const asset = state . list [ index ] ;
18+ state . totalSize -= asset . size ;
19+ state . list . splice ( index , 1 ) ;
20+ }
21+ }
1722 }
18- } ;
23+ } ) ;
24+
25+ export const assetsActions = assetsSlice . actions ;
1926
20- export default assets ;
27+ export default assetsSlice . reducer ;
You can’t perform that action at this time.
0 commit comments