Create actions for resolving resource favorite status
[arvados-workbench2.git] / src / store / favorites / favorites-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { unionize, ofType, UnionOf } from "unionize";
6 import { Dispatch } from "../../../node_modules/redux";
7 import { favoriteService } from "../../services/services";
8
9 export const favoritesActions = unionize({
10     CHECK_PRESENCE_IN_FAVORITES: ofType<string[]>(),
11     UPDATE_FAVORITES: ofType<Record<string, boolean>>()
12 }, { tag: 'type', value: 'payload' });
13
14 export type FavoritesAction = UnionOf<typeof favoritesActions>;
15
16 export const checkPresenceInFavorites = (userUuid: string, resourceUuids: string[]) =>
17     (dispatch: Dispatch) => {
18         dispatch(favoritesActions.CHECK_PRESENCE_IN_FAVORITES(resourceUuids));
19         favoriteService
20             .checkPresenceInFavorites(userUuid, resourceUuids)
21             .then(results => {
22                 dispatch(favoritesActions.UPDATE_FAVORITES(results));
23             });
24     };
25