Skip to content

Commit

Permalink
Adds loading to join room button
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathakurxd committed Mar 11, 2024
1 parent e6496e5 commit e661240
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/components/JoinForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import { ArrowRightIcon, Svg100MsLogoIcon } from '@100mslive/react-icons'
import { ArrowRightIcon, RefreshIcon, Svg100MsLogoIcon } from '@100mslive/react-icons'
import { useHMSActions } from '@100mslive/react-sdk'
import Image from 'next/image'
import { useState, ChangeEvent, FormEvent, useEffect } from 'react'
Expand All @@ -21,6 +21,7 @@ const JoinForm = () => {

const searchParams = useSearchParams()
const roomCodeParam = searchParams.get('room') || ''
const [loading, setLoading] = useState(false)

const handleTabClick = (tab) => {
setActiveTabRole(tab)
Expand All @@ -42,6 +43,7 @@ const JoinForm = () => {
// Type the event parameter
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault()
setLoading(true)

const { name: userName = '', roomCode = '' } = inputValues

Expand Down Expand Up @@ -97,9 +99,11 @@ const JoinForm = () => {
await hmsActions.join({ userName, authToken })
}
} else {
setLoading(false)
alert('Failed to create a new room')
}
} catch (e) {
setLoading(false)
alert('Failed to join room')
}
}
Expand Down Expand Up @@ -152,7 +156,14 @@ const JoinForm = () => {
)}

<button type="submit" className="btn-primary primary">
{roomCodeParam ? 'Accept Invite' : 'Join Room'}
{loading ? (
<RefreshIcon style={{ animation: 'spin 2s linear infinite' }} />
) : roomCodeParam ? (
'Accept Invite'
) : (
'Join Room'
)}

<ArrowRightIcon height={20} width={20} style={{ marginLeft: '4px' }} />
</button>
</form>
Expand Down

0 comments on commit e661240

Please sign in to comment.