merge master
authorPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Tue, 24 Jul 2018 11:19:03 +0000 (13:19 +0200)
committerPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Tue, 24 Jul 2018 11:19:03 +0000 (13:19 +0200)
Feature #13781

Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>

1  2 
src/store/favorites/favorites-actions.ts
src/store/project/project-action.ts
src/store/store.ts

index 0000000000000000000000000000000000000000,225c9b35c36ce934721c1c10f5cb2883a15e4594..c38f4d1a1aa2690779692ff70e51c2cf1e276bfa
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,44 +1,44 @@@
 -        const promise = isFavorite
+ // Copyright (C) The Arvados Authors. All rights reserved.
+ //
+ // SPDX-License-Identifier: AGPL-3.0
+ import { unionize, ofType, UnionOf } from "unionize";
+ import { Dispatch } from "redux";
+ import { favoriteService } from "../../services/services";
+ import { RootState } from "../store";
+ import { checkFavorite } from "./favorites-reducer";
+ export const favoritesActions = unionize({
+     TOGGLE_FAVORITE: ofType<{ resourceUuid: string }>(),
+     CHECK_PRESENCE_IN_FAVORITES: ofType<string[]>(),
+     UPDATE_FAVORITES: ofType<Record<string, boolean>>()
+ }, { tag: 'type', value: 'payload' });
+ export type FavoritesAction = UnionOf<typeof favoritesActions>;
+ export const toggleFavorite = (resource: { uuid: string; name: string }) =>
+     (dispatch: Dispatch, getState: () => RootState) => {
+         const userUuid = getState().auth.user!.uuid;
+         dispatch(favoritesActions.TOGGLE_FAVORITE({ resourceUuid: resource.uuid }));
+         const isFavorite = checkFavorite(resource.uuid, getState().favorites);
 -            .then(fav => {
++        const promise: (any) = isFavorite
+             ? favoriteService.delete({ userUuid, resourceUuid: resource.uuid })
+             : favoriteService.create({ userUuid, resource });
+         promise
++            .then(() => {
+                 dispatch(favoritesActions.UPDATE_FAVORITES({ [resource.uuid]: !isFavorite }));
+             });
+     };
+ export const checkPresenceInFavorites = (resourceUuids: string[]) =>
+     (dispatch: Dispatch, getState: () => RootState) => {
+         const userUuid = getState().auth.user!.uuid;
+         dispatch(favoritesActions.CHECK_PRESENCE_IN_FAVORITES(resourceUuids));
+         favoriteService
+             .checkPresenceInFavorites(userUuid, resourceUuids)
+             .then(results => {
+                 dispatch(favoritesActions.UPDATE_FAVORITES(results));
+             });
+     };
Simple merge
index 01b06b9528a727cd3cb9642a16bffeb0e17954ea,e7dbe16f49163f7b1cde01b8a08b7463b37bcbce..8a5136c91add44b378db23d3f9439d53d5496cd5
@@@ -14,7 -14,7 +14,8 @@@ import { dataExplorerReducer, DataExplo
  import { projectPanelMiddleware } from './project-panel/project-panel-middleware';
  import { detailsPanelReducer, DetailsPanelState } from './details-panel/details-panel-reducer';
  import { contextMenuReducer, ContextMenuState } from './context-menu/context-menu-reducer';
 +import { reducer as formReducer } from 'redux-form';
+ import { FavoritesState, favoritesReducer } from './favorites/favorites-reducer';
  
  const composeEnhancers =
      (process.env.NODE_ENV === 'development' &&
@@@ -39,7 -40,7 +41,8 @@@ const rootReducer = combineReducers(
      sidePanel: sidePanelReducer,
      detailsPanel: detailsPanelReducer,
      contextMenu: contextMenuReducer,
-     form: formReducer
++    form: formReducer,
+     favorites: favoritesReducer,
  });