Skip to content

Commit

Permalink
Added a simple menu item as a backup for copying the link in case the…
Browse files Browse the repository at this point in the history
… browser does not support web share api
  • Loading branch information
JBergVincit committed Jul 19, 2024
1 parent 30288a0 commit 2981fa3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
36 changes: 31 additions & 5 deletions frontend/src/components/CurrentBooking/AlterBookingDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
Spacer,
TimeTextBold
} from '../BookingDrawer/BookingDrawer';
import ShareMenu from './ShareMenu';
import { useState } from 'react';

const MIN_DURATION = 15;
const LAST_HOUR = 17;
Expand Down Expand Up @@ -87,13 +89,21 @@ const AlterBookingDrawer = (props: Props) => {
const text: string = 'Hello World! I shared this content via Web Share';
const url: string | undefined = booking?.meetingLink;

const [shareMenuOpen, setShareMenuOpen] = useState(false);
const [shareAnchorEl, setShareAnchorEl] =
React.useState<null | HTMLElement>(null);

const handleAlterTime = (minutes: number) => {
if (booking === undefined || minutes == 0) {
return;
}
onAlterTime(booking, minutes);
};

const shareMenuOnClose = (open: Boolean) => {
setShareMenuOpen(!shareMenuOpen);
};

const checkStartingTime = () => {
if (booking) {
const start = DateTime.fromISO(booking.startTime);
Expand Down Expand Up @@ -239,11 +249,18 @@ const AlterBookingDrawer = (props: Props) => {
cancelBooking(booking);
};

const handleOnShareClick = (shareDetails: ShareData) => {
const handleOnShareClick = (
event: HTMLElement | null,
shareDetails: ShareData
) => {
if (navigator.share) {
navigator.share(shareDetails).catch((error) => {
console.error('Something went wrong sharing the link', error);
});
} else if (event != null) {
console.log('Web Share API not enabled!');
setShareAnchorEl(event);
setShareMenuOpen(!shareMenuOpen);
}
};

Expand Down Expand Up @@ -294,16 +311,25 @@ const AlterBookingDrawer = (props: Props) => {
</RowCentered>
<Row>
<DrawerButtonSecondary
onClick={() =>
handleOnShareClick({
id="shareButton"
onClick={(
event: React.MouseEvent<HTMLButtonElement>
) => {
handleOnShareClick(event.currentTarget, {
url,
title,
text
})
}
});
}}
>
<ShareIcon /> <Spacer /> Share meeting
</DrawerButtonSecondary>
<ShareMenu
anchorEl={shareAnchorEl}
open={shareMenuOpen}
onClose={shareMenuOnClose}
url={url ? url : 'no link'}
></ShareMenu>
</Row>

<Row>
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/components/CurrentBooking/ShareMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';

interface Props {
anchorEl: HTMLElement | null;
open: boolean;
onClose: (open: boolean) => void;
url: string;
}

const ShareMenu = (props: Props) => {
const { anchorEl, open, onClose, url } = props;

const copy = () => {
navigator.clipboard.writeText(url).then((value) => {
onClose(!open);
});
};

return (
<Menu
open={open}
onClose={onClose}
anchorEl={anchorEl}
MenuListProps={{
'aria-labelledby': 'basic-button'
}}
>
<MenuItem onClick={copy}>Copy Link</MenuItem>
</Menu>
);
};

export default ShareMenu;

0 comments on commit 2981fa3

Please sign in to comment.