Make both claimPreview and claimPreviewTile use the same context-menu function.
Consolidated into `openClaimPreviewMenu`. We'll only update that function next time for context-menu additions.
This commit is contained in:
parent
232841ef5e
commit
cf832d14b4
3 changed files with 23 additions and 11 deletions
|
@ -5,7 +5,7 @@ import { NavLink, withRouter } from 'react-router-dom';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import { SIMPLE_SITE } from 'config';
|
import { SIMPLE_SITE } from 'config';
|
||||||
import { parseURI, convertToShareLink } from 'lbry-redux';
|
import { parseURI, convertToShareLink } from 'lbry-redux';
|
||||||
import { openCopyLinkMenu } from 'util/context-menu';
|
import { openClaimPreviewMenu } from 'util/context-menu';
|
||||||
import { formatLbryUrlForWeb } from 'util/url';
|
import { formatLbryUrlForWeb } from 'util/url';
|
||||||
import { isEmpty } from 'util/object';
|
import { isEmpty } from 'util/object';
|
||||||
import FileThumbnail from 'component/fileThumbnail';
|
import FileThumbnail from 'component/fileThumbnail';
|
||||||
|
@ -193,10 +193,7 @@ const ClaimPreview = forwardRef<any, {}>((props: Props, ref: any) => {
|
||||||
// @if TARGET='app'
|
// @if TARGET='app'
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (claim) {
|
openClaimPreviewMenu(claim, e);
|
||||||
const shareLink = convertToShareLink(claim.canonical_url || claim.permanent_url);
|
|
||||||
openCopyLinkMenu(shareLink.replace(/#/g, ':'), e);
|
|
||||||
}
|
|
||||||
// @endif
|
// @endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { parseURI } from 'lbry-redux';
|
||||||
import FileProperties from 'component/fileProperties';
|
import FileProperties from 'component/fileProperties';
|
||||||
import FileDownloadLink from 'component/fileDownloadLink';
|
import FileDownloadLink from 'component/fileDownloadLink';
|
||||||
import ClaimRepostAuthor from 'component/claimRepostAuthor';
|
import ClaimRepostAuthor from 'component/claimRepostAuthor';
|
||||||
|
import { openClaimPreviewMenu } from 'util/context-menu';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
uri: string,
|
uri: string,
|
||||||
|
@ -150,10 +151,19 @@ function ClaimPreviewTile(props: Props) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleContextMenu(e) {
|
||||||
|
// @if TARGET='app'
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
openClaimPreviewMenu(claim, e);
|
||||||
|
// @endif
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
role="link"
|
role="link"
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
|
onContextMenu={handleContextMenu}
|
||||||
className={classnames('card claim-preview--tile', {
|
className={classnames('card claim-preview--tile', {
|
||||||
'claim-preview__wrapper--channel': isChannel,
|
'claim-preview__wrapper--channel': isChannel,
|
||||||
})}
|
})}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { clipboard, remote } from 'electron';
|
import { clipboard, remote } from 'electron';
|
||||||
|
import { convertToShareLink } from 'lbry-redux';
|
||||||
const isDev = process.env.NODE_ENV !== 'production';
|
const isDev = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
function injectDevelopmentTemplate(event, templates) {
|
function injectDevelopmentTemplate(event, templates) {
|
||||||
|
@ -105,15 +106,19 @@ export function openSnippetMenu(codeMirror, event) {
|
||||||
openContextMenu(event, templates, false, selection);
|
openContextMenu(event, templates, false, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openCopyLinkMenu(text, event) {
|
export function openClaimPreviewMenu(claim, event) {
|
||||||
const templates = [
|
let templates = [];
|
||||||
{
|
|
||||||
|
if (claim) {
|
||||||
|
const shareLink = convertToShareLink(claim.canonical_url || claim.permanent_url);
|
||||||
|
templates.push({
|
||||||
label: 'Copy link',
|
label: 'Copy link',
|
||||||
click: () => {
|
click: () => {
|
||||||
clipboard.writeText(text);
|
clipboard.writeText(shareLink);
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
];
|
}
|
||||||
|
|
||||||
openContextMenu(event, templates);
|
openContextMenu(event, templates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue