Simple POC for moving download button to action bar

This commit is contained in:
Travis Ralston 2021-07-14 20:51:20 -06:00
parent aaa9040634
commit 0a99f76e7f
6 changed files with 237 additions and 24 deletions

View file

@ -32,6 +32,7 @@ import { replaceableComponent } from "../../../utils/replaceableComponent";
import { canCancel } from "../context_menus/MessageContextMenu";
import Resend from "../../../Resend";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import { canTileDownload } from "./IMediaBody";
const OptionsButton = ({ mxEvent, getTile, getReplyThread, permalinkCreator, onFocusChange }) => {
const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu();
@ -175,6 +176,16 @@ export default class MessageActionBar extends React.PureComponent {
});
};
onDownloadClick = async (ev) => {
// TODO: Maybe just call into MFileBody and render it as null
const src = this.props.getTile().getMediaHelper();
const a = document.createElement("a");
a.href = await src.sourceUrl.value;
a.download = "todo.png";
a.target = "_blank";
a.click();
};
/**
* Runs a given fn on the set of possible events to test. The first event
* that passes the checkFn will have fn executed on it. Both functions take
@ -267,6 +278,17 @@ export default class MessageActionBar extends React.PureComponent {
key="react"
/>);
}
const tile = this.props.getTile && this.props.getTile();
if (canTileDownload(tile)) {
toolbarOpts.splice(0, 0, <RovingAccessibleTooltipButton
className="mx_MessageActionBar_maskButton mx_MessageActionBar_downloadButton"
title={_t("Download")}
onClick={this.onDownloadClick}
disabled={false}
key="download"
/>);
}
}
if (allowCancel) {