From: Pawel Kowalczyk Date: Tue, 24 Jul 2018 11:19:03 +0000 (+0200) Subject: merge master X-Git-Tag: 1.2.0~33^2 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/48b6a6be504556c5624e505d18254cf144636dda merge master Feature #13781 Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- 48b6a6be504556c5624e505d18254cf144636dda diff --cc src/store/favorites/favorites-actions.ts index 00000000,225c9b35..c38f4d1a mode 000000,100644..100644 --- a/src/store/favorites/favorites-actions.ts +++ b/src/store/favorites/favorites-actions.ts @@@ -1,0 -1,44 +1,44 @@@ + // 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(), + UPDATE_FAVORITES: ofType>() + }, { tag: 'type', value: 'payload' }); + + export type FavoritesAction = UnionOf; + + 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); - const promise = isFavorite ++ const promise: (any) = isFavorite + ? favoriteService.delete({ userUuid, resourceUuid: resource.uuid }) + : favoriteService.create({ userUuid, resource }); + + promise - .then(fav => { ++ .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)); + }); + }; + diff --cc src/store/store.ts index 01b06b95,e7dbe16f..8a5136c9 --- a/src/store/store.ts +++ b/src/store/store.ts @@@ -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, });