projects
/
arvados-workbench2.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
17109: Handles keep-web's inline wildcard urls correctly.
[arvados-workbench2.git]
/
src
/
store
/
favorites
/
favorites-actions.ts
diff --git
a/src/store/favorites/favorites-actions.ts
b/src/store/favorites/favorites-actions.ts
index e5a8e591d20d1527b0137fffc3a4c35c8cd4b1ff..3a16c562423122f58830770cc9fd4d30ea0e83b1 100644
(file)
--- a/
src/store/favorites/favorites-actions.ts
+++ b/
src/store/favorites/favorites-actions.ts
@@
-5,9
+5,11
@@
import { unionize, ofType, UnionOf } from "~/common/unionize";
import { Dispatch } from "redux";
import { RootState } from "../store";
import { unionize, ofType, UnionOf } from "~/common/unionize";
import { Dispatch } from "redux";
import { RootState } from "../store";
+import { getUserUuid } from "~/common/getuser";
import { checkFavorite } from "./favorites-reducer";
import { checkFavorite } from "./favorites-reducer";
-import { snackbarActions } from "../snackbar/snackbar-actions";
+import { snackbarActions
, SnackbarKind
} from "../snackbar/snackbar-actions";
import { ServiceRepository } from "~/services/services";
import { ServiceRepository } from "~/services/services";
+import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
export const favoritesActions = unionize({
TOGGLE_FAVORITE: ofType<{ resourceUuid: string }>(),
export const favoritesActions = unionize({
TOGGLE_FAVORITE: ofType<{ resourceUuid: string }>(),
@@
-19,10
+21,20
@@
export type FavoritesAction = UnionOf<typeof favoritesActions>;
export const toggleFavorite = (resource: { uuid: string; name: string }) =>
(dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
export const toggleFavorite = (resource: { uuid: string; name: string }) =>
(dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
- const userUuid = getState().auth.user!.uuid;
+ const userUuid = getUserUuid(getState());
+ if (!userUuid) {
+ return Promise.reject("No user");
+ }
+ dispatch(progressIndicatorActions.START_WORKING("toggleFavorite"));
dispatch(favoritesActions.TOGGLE_FAVORITE({ resourceUuid: resource.uuid }));
dispatch(favoritesActions.TOGGLE_FAVORITE({ resourceUuid: resource.uuid }));
- dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Working..." }));
const isFavorite = checkFavorite(resource.uuid, getState().favorites);
const isFavorite = checkFavorite(resource.uuid, getState().favorites);
+ dispatch(snackbarActions.OPEN_SNACKBAR({
+ message: isFavorite
+ ? "Removing from favorites..."
+ : "Adding to favorites...",
+ kind: SnackbarKind.INFO
+ }));
+
const promise: any = isFavorite
? services.favoriteService.delete({ userUuid, resourceUuid: resource.uuid })
: services.favoriteService.create({ userUuid, resource });
const promise: any = isFavorite
? services.favoriteService.delete({ userUuid, resourceUuid: resource.uuid })
: services.favoriteService.create({ userUuid, resource });
@@
-35,14
+47,21
@@
export const toggleFavorite = (resource: { uuid: string; name: string }) =>
message: isFavorite
? "Removed from favorites"
: "Added to favorites",
message: isFavorite
? "Removed from favorites"
: "Added to favorites",
- hideDuration: 2000
+ hideDuration: 2000,
+ kind: SnackbarKind.SUCCESS
}));
}));
+ dispatch(progressIndicatorActions.STOP_WORKING("toggleFavorite"));
+ })
+ .catch((e: any) => {
+ dispatch(progressIndicatorActions.STOP_WORKING("toggleFavorite"));
+ throw e;
});
};
export const updateFavorites = (resourceUuids: string[]) =>
(dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
});
};
export const updateFavorites = (resourceUuids: string[]) =>
(dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- const userUuid = getState().auth.user!.uuid;
+ const userUuid = getUserUuid(getState());
+ if (!userUuid) { return; }
dispatch(favoritesActions.CHECK_PRESENCE_IN_FAVORITES(resourceUuids));
services.favoriteService
.checkPresenceInFavorites(userUuid, resourceUuids)
dispatch(favoritesActions.CHECK_PRESENCE_IN_FAVORITES(resourceUuids));
services.favoriteService
.checkPresenceInFavorites(userUuid, resourceUuids)