ActionBar.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React from "react";
  2. import Box from "@material-ui/core/Box";
  3. import IconButton from "@material-ui/core/IconButton";
  4. import OpenInNewIcon from '@material-ui/icons/OpenInNew';
  5. import AssignmentIcon from '@material-ui/icons/Assignment';
  6. import ShareIcon from '@material-ui/icons/Share';
  7. import { useStore } from "react-redux";
  8. import { RootState } from "../app/rootReducer";
  9. const copyToClipboard = (text: string) => navigator.clipboard.writeText(text)
  10. .then(
  11. () => console.log('Async: Copying to clipboard was successful!'),
  12. (err) => console.error('Async: Could not copy text: ', err)
  13. );
  14. const shareApp = (state: RootState) => copyToClipboard(`${window.location.href}?state=${encodeURIComponent(JSON.stringify(state))}`);
  15. export interface Props {
  16. fullPath: string;
  17. }
  18. const ActionBar: React.FC<Props> = ({ fullPath }) => {
  19. const store = useStore();
  20. return (
  21. < Box style={{ textAlign: "center", width: "100%", position: "fixed", bottom: "0", background: "white" }}>
  22. <IconButton title="Share application" color="secondary" onClick={_ => shareApp(store.getState())}>
  23. <ShareIcon fontSize="small" />
  24. </IconButton>
  25. <IconButton title="Copy link to clipboard" color="secondary" onClick={_ => copyToClipboard(fullPath)}>
  26. <AssignmentIcon fontSize="small" />
  27. </IconButton>
  28. <IconButton title="Open link in new window" color="primary" onClick={_ => window.open(fullPath)}>
  29. <OpenInNewIcon fontSize="large" />
  30. </IconButton>
  31. </Box >
  32. );
  33. };
  34. export default ActionBar;