diff --git a/client/modules/IDE/actions/projects.js b/client/modules/IDE/actions/projects.js
index 06c50cbbfa..5b4e51f322 100644
--- a/client/modules/IDE/actions/projects.js
+++ b/client/modules/IDE/actions/projects.js
@@ -1,6 +1,6 @@
import { apiClient } from '../../../utils/apiClient';
import * as ActionTypes from '../../../constants';
-import { startLoader, stopLoader } from '../reducers/loading';
+import { startLoader, stopLoader, setError } from '../reducers/loading';
// eslint-disable-next-line
export function getProjects(username) {
@@ -22,11 +22,11 @@ export function getProjects(username) {
dispatch(stopLoader());
})
.catch((error) => {
+ dispatch(setError(error?.response?.data || 'Failed to load sketches'));
dispatch({
type: ActionTypes.ERROR,
error: error?.response?.data
});
- dispatch(stopLoader());
});
};
}
diff --git a/client/modules/IDE/components/SketchList.jsx b/client/modules/IDE/components/SketchList.jsx
index c0e2cc42c5..97c88228da 100644
--- a/client/modules/IDE/components/SketchList.jsx
+++ b/client/modules/IDE/components/SketchList.jsx
@@ -10,6 +10,7 @@ import * as ProjectsActions from '../actions/projects';
import * as CollectionsActions from '../actions/collections';
import * as ToastActions from '../actions/toast';
import * as SortingActions from '../actions/sorting';
+import { clearError as clearLoadingError } from '../reducers/loading';
import getSortedSketches from '../selectors/projects';
import Loader from '../../App/components/loader';
import Overlay from '../../App/components/Overlay';
@@ -27,16 +28,19 @@ const SketchList = ({
sorting,
toggleDirectionForField,
resetSorting,
- mobile
+ mobile,
+ clearError
}) => {
const [isInitialDataLoad, setIsInitialDataLoad] = useState(true);
const [sketchToAddToCollection, setSketchToAddToCollection] = useState(null);
const { t } = useTranslation();
useEffect(() => {
+ setIsInitialDataLoad(true);
+ clearError();
getProjects(username);
resetSorting();
- }, [getProjects, username, resetSorting]);
+ }, [getProjects, username, resetSorting, clearError]);
useEffect(() => {
if (Array.isArray(sketches)) {
@@ -52,14 +56,38 @@ const SketchList = ({
[username, user.username, t]
);
- const isLoading = () => loading && isInitialDataLoad;
-
- const hasSketches = () => !isLoading() && sketches.length > 0;
+ const isLoading = () => isInitialDataLoad || loading.isLoading;
+ const hasError = () => loading.error && !loading.isLoading;
+ const hasSketches = () => !isLoading() && !hasError() && sketches.length > 0;
+ const isEmpty = () => !isLoading() && !hasError() && sketches.length === 0;
const renderLoader = () => isLoading() &&
+ {t('SketchList.LoadError', { error: loading.error })} +
+ +{t('SketchList.NoSketches')}
); @@ -127,6 +155,7 @@ const SketchList = ({