/* Copyright 2020 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React, {useContext} from "react"; import {MatrixCapabilities} from "matrix-widget-api"; import IconizedContextMenu, {IconizedContextMenuOption, IconizedContextMenuOptionList} from "./IconizedContextMenu"; import {ChevronFace} from "../../structures/ContextMenu"; import {_t} from "../../../languageHandler"; import {IApp} from "../../../stores/WidgetStore"; import defaultDispatcher from "../../../dispatcher/dispatcher"; import {AppTileActionPayload} from "../../../dispatcher/payloads/AppTileActionPayload"; import {Action} from "../../../dispatcher/actions"; import WidgetUtils from "../../../utils/WidgetUtils"; import {WidgetMessagingStore} from "../../../stores/widgets/WidgetMessagingStore"; import RoomContext from "../../../contexts/RoomContext"; interface IProps extends React.ComponentProps { app: IApp; } const RoomWidgetContextMenu: React.FC = ({ onFinished, app, ...props}) => { const {roomId} = useContext(RoomContext); const widgetMessaging = WidgetMessagingStore.instance.getMessagingForId(app.id); let snapshotButton; if (widgetMessaging?.hasCapability(MatrixCapabilities.Screenshots)) { const onSnapshotClick = () => { WidgetUtils.snapshotWidget(app); onFinished(); }; snapshotButton = ; } let deleteButton; if (WidgetUtils.canUserModifyWidgets(roomId)) { const onDeleteClick = () => { defaultDispatcher.dispatch({ action: Action.AppTileDelete, widgetId: app.id, }); onFinished(); }; deleteButton = ; } const onRevokeClick = () => { defaultDispatcher.dispatch({ action: Action.AppTileRevoke, widgetId: app.id, }); onFinished(); }; return { snapshotButton } { deleteButton } ; }; export default RoomWidgetContextMenu;