X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/ea54fb82c3a59ca8a959643f8bec4776635433e0..5ec3f2a5dd1e0dd3cf439b46ea9eebecbd0eb250:/src/store/favorites/favorites-actions.ts diff --git a/src/store/favorites/favorites-actions.ts b/src/store/favorites/favorites-actions.ts index 5a3001fb..3a16c562 100644 --- a/src/store/favorites/favorites-actions.ts +++ b/src/store/favorites/favorites-actions.ts @@ -5,6 +5,7 @@ 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 { snackbarActions, SnackbarKind } from "../snackbar/snackbar-actions"; import { ServiceRepository } from "~/services/services"; @@ -20,14 +21,18 @@ export type FavoritesAction = UnionOf; export const toggleFavorite = (resource: { uuid: string; name: string }) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise => { + const userUuid = getUserUuid(getState()); + if (!userUuid) { + return Promise.reject("No user"); + } dispatch(progressIndicatorActions.START_WORKING("toggleFavorite")); - const userUuid = getState().auth.user!.uuid; dispatch(favoritesActions.TOGGLE_FAVORITE({ resourceUuid: resource.uuid })); const isFavorite = checkFavorite(resource.uuid, getState().favorites); dispatch(snackbarActions.OPEN_SNACKBAR({ message: isFavorite ? "Removing from favorites..." - : "Adding to favorites..." + : "Adding to favorites...", + kind: SnackbarKind.INFO })); const promise: any = isFavorite @@ -55,7 +60,8 @@ export const toggleFavorite = (resource: { uuid: string; name: string }) => 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)