-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d819d74
commit 277923f
Showing
2 changed files
with
113 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { useState } from 'react' | ||
import BasicModal from '@/modules/common/BasicModal' | ||
import Stack from 'react-bootstrap/Stack' | ||
import { toast } from 'react-toastify' | ||
import Button from 'react-bootstrap/Button' | ||
import { useNavigate, useParams } from 'react-router-dom' | ||
import { useCopyToClipboard } from 'react-use' | ||
import Row from 'react-bootstrap/Row' | ||
import Col from 'react-bootstrap/Col' | ||
|
||
function LeaveButton() { | ||
const navigate = useNavigate() | ||
const [show, setShow] = useState(false) | ||
|
||
return ( | ||
<> | ||
<Button size="sm" variant="secondary" onClick={() => setShow(true)}> | ||
Leave | ||
</Button> | ||
<BasicModal | ||
title="Leave Room" | ||
ok={{ | ||
label: 'Yes', | ||
}} | ||
cancel={{ | ||
label: 'No', | ||
}} | ||
show={show} | ||
onHide={() => { | ||
setShow(false) | ||
}} | ||
onCancel={() => { | ||
setShow(false) | ||
}} | ||
onOk={() => { | ||
setShow(false) | ||
navigate('/') | ||
}} | ||
> | ||
Are you sure you want to leave the room? | ||
</BasicModal> | ||
</> | ||
) | ||
} | ||
|
||
function ShareButton() { | ||
const [show, setShow] = useState(false) | ||
const { roomId } = useParams() | ||
const link = window.location.href | ||
const copy = useCopyToClipboard()[1] | ||
|
||
function copyCode() { | ||
copy(roomId as string) | ||
setShow(false) | ||
toast('The room code has been copied to the clipboard') | ||
} | ||
|
||
function copyUrl() { | ||
copy(link) | ||
setShow(false) | ||
toast('The join URL has been copied to the clipboard') | ||
} | ||
|
||
return ( | ||
<> | ||
<Button size="sm" variant="primary" onClick={() => setShow(true)}> | ||
Share | ||
</Button> | ||
<BasicModal | ||
title="Share" | ||
show={show} | ||
onHide={() => { | ||
setShow(false) | ||
}} | ||
> | ||
<Stack gap={2}> | ||
<div> | ||
Invite your friends! They can join through the <em>room code</em> or | ||
the <em>join URL</em>. Click to copy. | ||
</div> | ||
<div> | ||
Room code:{' '} | ||
<strong onClick={copyCode} className="cursor-pointer text-primary"> | ||
{roomId} | ||
</strong> | ||
</div> | ||
<div> | ||
Join URL:{' '} | ||
<strong onClick={copyUrl} className="cursor-pointer text-primary"> | ||
{link} | ||
</strong> | ||
</div> | ||
</Stack> | ||
</BasicModal> | ||
</> | ||
) | ||
} | ||
|
||
export function RoomToolbar() { | ||
return ( | ||
<Row className="justify-content-between align-items-center"> | ||
<Col xs="auto"> | ||
<LeaveButton /> | ||
</Col> | ||
<Col xs="auto"> | ||
<ShareButton /> | ||
</Col> | ||
</Row> | ||
) | ||
} |