mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2026-01-21 11:22:47 +01:00
Change hashlink icon, copy to clip board on click
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { faTrashAlt, faHashtag } from '@fortawesome/free-solid-svg-icons';
|
||||
import { faTrashAlt, faHashtag, faLink, faCheck } from '@fortawesome/free-solid-svg-icons';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import AppState from '../AppState';
|
||||
import loglevel from 'loglevel';
|
||||
|
||||
|
||||
type DisplayResultProps = {
|
||||
@@ -16,15 +17,28 @@ type DisplayResultProps = {
|
||||
|
||||
const DisplayResultView: React.FunctionComponent<DisplayResultProps> = (props) => {
|
||||
|
||||
const resultKey : number = props.resultKey;
|
||||
const appState = props.appState;
|
||||
const link = window.location.origin + window.location.pathname + '#' + props.inputHash;
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
async function copyLink(e: any) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(link);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
return false;
|
||||
} catch (err) {
|
||||
loglevel.debug(err);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return <div className="result">
|
||||
<div className="input mono">
|
||||
<span className="cur">></span>
|
||||
<span className="input-string">{props.input}</span>
|
||||
<a className="hashLink" title="Link for this expression" href={window.location.pathname + '#' + props.inputHash}>
|
||||
<FontAwesomeIcon className="icon" icon={faHashtag} size="xs" />
|
||||
<a className="hashLink" title="Copy link link for this expression" onClick={async (e) => {return await copyLink(e)}} href={link}>
|
||||
<FontAwesomeIcon className="icon" icon={copied ? faCheck : faLink} size="xs" />
|
||||
</a>
|
||||
<button className="hashLink" title="Remove this result" onClick={() => appState.removeResult(props.resultIndex)}>
|
||||
<FontAwesomeIcon className="icon" icon={faTrashAlt} size="xs" />
|
||||
|
||||
Reference in New Issue
Block a user