App.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import './App.css';
  2. import React from 'react';
  3. import Container from '@material-ui/core/Container';
  4. import Grid from '@material-ui/core/Grid';
  5. import InputLabel from '@material-ui/core/InputLabel';
  6. import IconButton from '@material-ui/core/IconButton';
  7. import OpenInNewIcon from '@material-ui/icons/OpenInNew';
  8. import AssignmentIcon from '@material-ui/icons/Assignment';
  9. import ShareIcon from '@material-ui/icons/Share';
  10. import BasePath from '../features/BasePath/BasePath';
  11. import PluginPath from '../features/PluginPath/PluginPath';
  12. import ConfigOverride from '../features/ConfigOverride/ConfigOverride';
  13. import { useMemo } from 'react';
  14. import { useSelector, useStore } from 'react-redux';
  15. import { RootState } from './rootReducer';
  16. const copyToClipboard = (text: string) => navigator.clipboard.writeText(text)
  17. .then(
  18. () => console.log('Async: Copying to clipboard was successful!'),
  19. (err) => console.error('Async: Could not copy text: ', err)
  20. );
  21. const shareApp = (state: RootState) => copyToClipboard(`${window.location.href}?state=${encodeURIComponent(JSON.stringify(state))}`);
  22. const App: React.FC = () => {
  23. const store = useStore();
  24. const { basePath, pluginPath, configOverride } = useSelector((state: RootState) => ({
  25. basePath: state.basePath.value,
  26. pluginPath: state.pluginPath.value,
  27. configOverride: state.configOverride.value
  28. }));
  29. const fullPath = useMemo(() => `${basePath}configoverride=${encodeURIComponent(configOverride)}`, [basePath, configOverride]);
  30. return (
  31. <Container className="App">
  32. <Grid container spacing={3} direction="column">
  33. <Grid item xs={12}>
  34. <BasePath />
  35. </Grid>
  36. <Grid item xs={12}>
  37. <PluginPath />
  38. </Grid>
  39. <Grid item xs={12}>
  40. <ConfigOverride pluginPath={pluginPath} />
  41. </Grid>
  42. <Grid item xs={12}>
  43. <InputLabel id="link-label">Link</InputLabel>
  44. <div style={{ overflowWrap: "break-word" }}>{fullPath}</div>
  45. </Grid>
  46. <Grid item xs={12} style={{ textAlign: "center" }}>
  47. <IconButton title="Share application" color="secondary" onClick={_ => shareApp(store.getState())}>
  48. <ShareIcon fontSize="small" />
  49. </IconButton>
  50. <IconButton title="Copy link to clipboard" color="secondary" onClick={_ => copyToClipboard(fullPath)}>
  51. <AssignmentIcon fontSize="small" />
  52. </IconButton>
  53. <IconButton title="Open link new window" color="primary" onClick={_ => window.open(fullPath)}>
  54. <OpenInNewIcon fontSize="large" />
  55. </IconButton>
  56. </Grid>
  57. </Grid>
  58. </Container>
  59. );
  60. }
  61. export default App;