Skip to content

Commit 0f5494c

Browse files
authored
Merge pull request #2248 from lindapaiste/fix/asset-size
Fix #2243 - AssetSize bar disappears when deleting an asset
2 parents 0aadc8c + b422eb6 commit 0f5494c

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

client/constants.js

-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ export const CLEAR_PERSISTED_STATE = 'CLEAR_PERSISTED_STATE';
130130

131131
export const HIDE_RUNTIME_ERROR_WARNING = 'HIDE_RUNTIME_ERROR_WARNING';
132132
export const SHOW_RUNTIME_ERROR_WARNING = 'SHOW_RUNTIME_ERROR_WARNING';
133-
export const SET_ASSETS = 'SET_ASSETS';
134-
export const DELETE_ASSET = 'DELETE_ASSET';
135133

136134
export const TOGGLE_DIRECTION = 'TOGGLE_DIRECTION';
137135
export const SET_SORTING = 'SET_SORTING';

client/modules/IDE/actions/assets.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import apiClient from '../../../utils/apiClient';
22
import * as ActionTypes from '../../../constants';
33
import { 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

138
export function getAssets() {
149
return async (dispatch) => {
@@ -26,13 +21,6 @@ export function getAssets() {
2621
};
2722
}
2823

29-
export function deleteAsset(assetKey) {
30-
return {
31-
type: ActionTypes.DELETE_ASSET,
32-
key: assetKey
33-
};
34-
}
35-
3624
export function deleteAssetRequest(assetKey) {
3725
return async (dispatch) => {
3826
try {

client/modules/IDE/reducers/assets.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
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.
43
const 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;

0 commit comments

Comments
 (0)