21128: Added button disable during async actions Arvados-DCO-1.1-Signed-off-by: Lisa...
[arvados-workbench2.git] / src / store / public-favorites / public-favorites-actions.ts
index 50b9070baf0987ab6ec64c4624cf301dee96d02d..7fb087883bf9e6f0cae9d292f988f903ad791f92 100644 (file)
@@ -2,13 +2,15 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { unionize, ofType, UnionOf } from "~/common/unionize";
+import { unionize, ofType, UnionOf } from "common/unionize";
 import { Dispatch } from "redux";
 import { RootState } from "../store";
 import { checkPublicFavorite } from "./public-favorites-reducer";
-import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
-import { ServiceRepository } from "~/services/services";
-import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
+import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
+import { ServiceRepository } from "services/services";
+import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
+import { setDisabledButton, removeDisabledButton } from "store/multiselect/multiselect-actions";
+import { MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-actions";
 
 export const publicFavoritesActions = unionize({
     TOGGLE_PUBLIC_FAVORITE: ofType<{ resourceUuid: string }>(),
@@ -21,8 +23,9 @@ export type PublicFavoritesAction = UnionOf<typeof publicFavoritesActions>;
 export const togglePublicFavorite = (resource: { uuid: string; name: string }) =>
     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
         dispatch(progressIndicatorActions.START_WORKING("togglePublicFavorite"));
-        const uuidPrefix = getState().config.uuidPrefix;
-        const uuid = `${uuidPrefix}-j7d0g-fffffffffffffff`;
+        dispatch<any>(setDisabledButton(MultiSelectMenuActionNames.ADD_TO_PUBLIC_FAVORITES))
+        const uuidPrefix = getState().auth.config.uuidPrefix;
+        const uuid = `${uuidPrefix}-j7d0g-publicfavorites`;
         dispatch(publicFavoritesActions.TOGGLE_PUBLIC_FAVORITE({ resourceUuid: resource.uuid }));
         const isPublicFavorite = checkPublicFavorite(resource.uuid, getState().publicFavorites);
         dispatch(snackbarActions.OPEN_SNACKBAR({
@@ -47,6 +50,7 @@ export const togglePublicFavorite = (resource: { uuid: string; name: string }) =
                     hideDuration: 2000,
                     kind: SnackbarKind.SUCCESS
                 }));
+                dispatch<any>(removeDisabledButton(MultiSelectMenuActionNames.ADD_TO_PUBLIC_FAVORITES))
                 dispatch(progressIndicatorActions.STOP_WORKING("togglePublicFavorite"));
             })
             .catch((e: any) => {
@@ -57,8 +61,8 @@ export const togglePublicFavorite = (resource: { uuid: string; name: string }) =
 
 export const updatePublicFavorites = (resourceUuids: string[]) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const uuidPrefix = getState().config.uuidPrefix;
-        const uuid = `${uuidPrefix}-j7d0g-fffffffffffffff`;
+        const uuidPrefix = getState().auth.config.uuidPrefix;
+        const uuid = `${uuidPrefix}-j7d0g-publicfavorites`;
         dispatch(publicFavoritesActions.CHECK_PRESENCE_IN_PUBLIC_FAVORITES(resourceUuids));
         services.favoriteService
             .checkPresenceInFavorites(uuid, resourceUuids)