import React, { useReducer } from "react"; import Icon from "@material-ui/core/Icon"; import Fab from "@material-ui/core/Fab"; import { makeStyles } from "@material-ui/core/styles"; import { useTranslation } from "react-i18next"; import { useEvent } from "../../contexts/Event"; import { useToast } from "../../contexts/Toast"; const EventFab = ({ toggleNewCar }) => { const { t } = useTranslation(); const [open, toggleOpen] = useReducer((i) => !i, false); const classes = useStyles({ open }); const { event } = useEvent(); const { addToast } = useToast(); const onShare = async () => { if (!event) return null; // If navigator as share capability if (!!navigator.share) { const shareData = { title: `Caroster ${event.name}`, url: `${window.location.href}`, }; return await navigator.share(shareData); } // Else copy URL in clipboard else if (!!navigator.clipboard) { await navigator.clipboard.writeText(window.location.href); addToast(t("event.actions.copied")); return true; } }; return ( <>