Skip to content

Commit

Permalink
Add copy meeting id button in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
third774 committed Sep 30, 2024
1 parent 12701e5 commit d2b2ac2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
62 changes: 39 additions & 23 deletions app/components/CopyButton.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,58 @@
import { VisuallyHidden } from '@radix-ui/react-visually-hidden'
import type { FC } from 'react'
import { useState } from 'react'
import {
type ComponentProps,
type ElementRef,
forwardRef,
type ReactNode,
useState,
} from 'react'
import { useTimeoutFn } from 'react-use'
import { useRoomUrl } from '~/hooks/useRoomUrl'
import { Button } from './Button'
import { Icon } from './Icon/Icon'
import { Tooltip } from './Tooltip'

interface CopyButtonProps {}

export const CopyButton: FC<CopyButtonProps> = () => {
const [copied, setCopied] = useState(false)
interface CopyButtonProps extends ComponentProps<'button'> {
contentValue: string
copiedMessage?: ReactNode
}

const roomUrl = useRoomUrl()
export const CopyButton = forwardRef<ElementRef<'button'>, CopyButtonProps>(
(
{
children = <VisuallyHidden>Copy</VisuallyHidden>,
copiedMessage = <VisuallyHidden>Copied!</VisuallyHidden>,
contentValue,
onClick,
...rest
},
ref
) => {
const [copied, setCopied] = useState(false)

const [_isReady, _cancel, reset] = useTimeoutFn(() => {
setCopied(false)
}, 2000)
const [_isReady, _cancel, reset] = useTimeoutFn(() => {
setCopied(false)
}, 2000)

return (
<Tooltip
content={copied ? 'Copied!' : 'Copy URL'}
open={copied ? true : undefined}
>
return (
<Button
displayType="secondary"
onClick={() => {
navigator.clipboard.writeText(roomUrl)
onClick={(e) => {
onClick && onClick(e)
navigator.clipboard.writeText(contentValue)
setCopied(true)
reset()
}}
ref={ref}
className="flex items-center gap-2 text-xs"
{...rest}
>
<Icon
type={copied ? 'ClipboardDocumentCheckIcon' : 'ClipboardDocumentIcon'}
className="text-xl"
/>
<VisuallyHidden>{copied ? 'Copied!' : 'Copy URL'}</VisuallyHidden>
{copied ? copiedMessage : children}
</Button>
</Tooltip>
)
}
)
}
)

CopyButton.displayName = 'CopyButton'
7 changes: 6 additions & 1 deletion app/routes/_room.$roomName._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Spinner } from '~/components/Spinner'
import { Tooltip } from '~/components/Tooltip'
import { useSubscribedState } from '~/hooks/rxjsHooks'
import { useRoomContext } from '~/hooks/useRoomContext'
import { useRoomUrl } from '~/hooks/useRoomUrl'
import { errorMessageMap } from '~/hooks/useUserMedia'
import getUsername from '~/utils/getUsername.server'

Expand Down Expand Up @@ -62,6 +63,8 @@ export default function Lobby() {
? errorMessageMap[userMedia.audioUnavailableReason]
: null

const roomUrl = useRoomUrl()

return (
<div className="flex flex-col items-center justify-center h-full p-4">
<div className="flex-1"></div>
Expand Down Expand Up @@ -167,7 +170,9 @@ export default function Lobby() {
<MicButton />
<CameraButton />
<SettingsButton />
<CopyButton></CopyButton>
<Tooltip content="Copy URL">
<CopyButton contentValue={roomUrl}></CopyButton>
</Tooltip>
</div>
</div>
<div className="flex flex-col justify-end flex-1">
Expand Down
4 changes: 4 additions & 0 deletions app/routes/_room.$roomName.room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Flipper } from 'react-flip-toolkit'
import { useMeasure, useMount, useWindowSize } from 'react-use'
import { Button } from '~/components/Button'
import { CameraButton } from '~/components/CameraButton'
import { CopyButton } from '~/components/CopyButton'
import { HighPacketLossWarningsToast } from '~/components/HighPacketLossWarningsToast'
import { IceDisconnectedToast } from '~/components/IceDisconnectedToast'
import { Icon } from '~/components/Icon/Icon'
Expand Down Expand Up @@ -335,6 +336,9 @@ function JoinedRoom({ bugReportsEnabled }: { bugReportsEnabled: boolean }) {
navigateToFeedbackPage={hasDb}
meetingId={meetingId}
/>
{debugEnabled && meetingId && (
<CopyButton contentValue={meetingId}>Meeting Id</CopyButton>
)}
</div>
</div>
<HighPacketLossWarningsToast />
Expand Down

0 comments on commit d2b2ac2

Please sign in to comment.