From 79e437567aa6c4055cb819fc3937296c1a203c0c Mon Sep 17 00:00:00 2001 From: itayox <111698101+itayox@users.noreply.github.com> Date: Thu, 17 Aug 2023 22:37:01 +0300 Subject: [PATCH] Adding a share button (#100) * Adding a share button * Auto hide and change severity to info --------- Co-authored-by: Nicolas Vuillamy --- CHANGELOG.md | 1 + packages/app/src/app/components/Footer.tsx | 11 ++- .../app/src/app/components/ShareButton.tsx | 92 +++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 packages/app/src/app/components/ShareButton.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a6132f..e283ef3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ _Can be run using `npm run codetotal:beta`_ - Add link to packages' registry in SBOM panel - Fix Safari not showing Score component correctly #81 - Display "snippet" in results page instead of md5: xxxx + - Add a share button in the footer - Back-End - Bug fix: SBOM packages not showing up in report page. Async parsing of packages information in SBOM module diff --git a/packages/app/src/app/components/Footer.tsx b/packages/app/src/app/components/Footer.tsx index b9bee76..1adbe8f 100644 --- a/packages/app/src/app/components/Footer.tsx +++ b/packages/app/src/app/components/Footer.tsx @@ -3,10 +3,12 @@ import { FC } from "react"; import { makeStyles } from "tss-react/mui"; import { ReactComponent as BackgroundSvg } from "../../assets/bg.svg"; import oxLogo from "../../assets/ox.svg"; +import { ShareButton } from "./ShareButton"; import { ToggleThemeButton } from "./ToggleThemeButton"; export const Footer: FC = () => { const { classes } = useStyles(); + return (
@@ -45,7 +47,10 @@ export const Footer: FC = () => { MegaLinter - +
+ + +
@@ -97,4 +102,8 @@ const useStyles = makeStyles()((theme: Theme) => ({ width: "1.3em", height: "1.3em", }, + actions: { + display: "flex", + gap: theme.spacing(2), + }, })); diff --git a/packages/app/src/app/components/ShareButton.tsx b/packages/app/src/app/components/ShareButton.tsx new file mode 100644 index 0000000..5b43952 --- /dev/null +++ b/packages/app/src/app/components/ShareButton.tsx @@ -0,0 +1,92 @@ +import { Alert, AlertTitle, Button, Slide, Snackbar } from "@mui/material"; +import { FC, useState } from "react"; +import { makeStyles } from "tss-react/mui"; + +const CODE_TOTAL_URL = "https://codetotal.io"; + +export const ShareButton: FC = () => { + const { classes } = useStyles(); + const [error, setError] = useState(false); + const [loading, setLoading] = useState(false); + const [success, setSuccess] = useState(false); + + const handleShare = async () => { + try { + setLoading(true); + await navigator.clipboard.writeText(CODE_TOTAL_URL); + setSuccess(true); + } catch (err) { + setError(true); + setSuccess(false); + } finally { + setLoading(false); + } + }; + + const handleClose = () => { + setError(false); + setSuccess(false); + }; + + return ( + <> + + + + + Unable to copy URL to clipboard + Please copy or click the following URL manually to share:  + + {CODE_TOTAL_URL} + + + + + + + URL copied successfully +
+ Thank you for sharing CodeTotal with the community  + 💗 +
+
+
+ + ); +}; + +const useStyles = makeStyles()((theme) => ({ + link: { + color: "inherit", + fontWeight: "bold", + }, + thankYou: { + display: "flex", + alignItems: "center", + gap: theme.spacing(1), + }, +}));