Skip to content

Fix #2243 - AssetSize bar disappears when deleting an asset #2248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ export const CLEAR_PERSISTED_STATE = 'CLEAR_PERSISTED_STATE';

export const HIDE_RUNTIME_ERROR_WARNING = 'HIDE_RUNTIME_ERROR_WARNING';
export const SHOW_RUNTIME_ERROR_WARNING = 'SHOW_RUNTIME_ERROR_WARNING';
export const SET_ASSETS = 'SET_ASSETS';
export const DELETE_ASSET = 'DELETE_ASSET';

export const TOGGLE_DIRECTION = 'TOGGLE_DIRECTION';
export const SET_SORTING = 'SET_SORTING';
Expand Down
16 changes: 2 additions & 14 deletions client/modules/IDE/actions/assets.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import apiClient from '../../../utils/apiClient';
import * as ActionTypes from '../../../constants';
import { startLoader, stopLoader } from './loader';
import { assetsActions } from '../reducers/assets';

function setAssets(assets, totalSize) {
return {
type: ActionTypes.SET_ASSETS,
assets,
totalSize
};
}
const { setAssets, deleteAsset } = assetsActions;

export function getAssets() {
return async (dispatch) => {
Expand All @@ -26,13 +21,6 @@ export function getAssets() {
};
}

export function deleteAsset(assetKey) {
return {
type: ActionTypes.DELETE_ASSET,
key: assetKey
};
}

export function deleteAssetRequest(assetKey) {
return async (dispatch) => {
try {
Expand Down
31 changes: 19 additions & 12 deletions client/modules/IDE/reducers/assets.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import * as ActionTypes from '../../../constants';
import { createSlice } from '@reduxjs/toolkit';

// 1,000,000 bytes in a MB. can't upload if totalSize is bigger than this.
const initialState = {
list: [],
totalSize: 0
};

const assets = (state = initialState, action) => {
switch (action.type) {
case ActionTypes.SET_ASSETS:
return { list: action.assets, totalSize: action.totalSize };
case ActionTypes.DELETE_ASSET:
return { list: state.list.filter((asset) => asset.key !== action.key) };
default:
return state;
const assetsSlice = createSlice({
name: 'assets',
initialState,
reducers: {
setAssets: (state, action) => action.payload,
deleteAsset: (state, action) => {
const key = action.payload;
const index = state.list.findIndex((asset) => asset.key === key);
if (index !== -1) {
const asset = state.list[index];
state.totalSize -= asset.size;
state.list.splice(index, 1);
}
}
}
};
});

export const assetsActions = assetsSlice.actions;

export default assets;
export default assetsSlice.reducer;