55fe8cfdba19efe1c42b088e7ccc87471aaea97f
[arvados-workbench2.git] / src / views-components / context-menu / actions / favorite-action.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from "react";
6 import { ListItemIcon, ListItemText } from "@material-ui/core";
7 import { AddFavoriteIcon, RemoveFavoriteIcon } from "../../../components/icon/icon";
8 import { connect } from "react-redux";
9 import { RootState } from "../../../store/store";
10
11 const mapStateToProps = (state: RootState) => ({
12     isFavorite: state.contextMenu.resource !== undefined && state.favorites[state.contextMenu.resource.uuid] === true
13 });
14
15 export const ToggleFavoriteAction = connect(mapStateToProps)((props: { isFavorite: boolean }) =>
16     <>
17         <ListItemIcon>
18             {props.isFavorite
19                 ? <RemoveFavoriteIcon />
20                 : <AddFavoriteIcon />}
21         </ListItemIcon>
22         <ListItemText>
23             {props.isFavorite
24                 ? <>Remove from favorites</>
25                 : <>Add to favorites</>}
26         </ListItemText>
27     </>);