-
-
Save DanyF-github/d295c0ade7e1e61bbf889f3b52eb3e5d to your computer and use it in GitHub Desktop.
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
// client/src/components/Videocall/StartButton.tsx | |
import { useMutation } from '@apollo/client'; | |
import React from 'react'; | |
import { useHistory } from 'react-router-dom'; | |
import { START_VIDEOCALL_SESSION } from '../../data/mutations'; | |
import { GET_START_CALL_SETTINGS } from '../../data/queries'; | |
const startCallButton = { | |
padding: '10pt', | |
borderRadius: '3px', | |
border: '0px', | |
}; | |
const StartButton = () => { | |
// we use the useMutation hook to create a mutate function | |
const [startSession] = useMutation(START_VIDEOCALL_SESSION, { | |
// the update() function allows to run code after running the mutation | |
update(client, { data: { startVideocallSession } }) { | |
// here we write the resulting data into the cache | |
client.writeQuery({ | |
query: GET_START_CALL_SETTINGS, | |
data: { | |
sessionDetails: startVideocallSession | |
}, | |
variables: { | |
uuid: startVideocallSession.uuid | |
} | |
}); | |
}, | |
onCompleted({startVideocallSession}) { | |
// after creating the session we move to a different page | |
history.push(`/session/${startVideocallSession.uuid}`); | |
} | |
}); | |
const history = useHistory(); | |
// we render the button and call the mutate function on click | |
return ( | |
<div> | |
<button | |
style={startCallButton} | |
onClick={() => { | |
startSession(); | |
}} | |
> | |
Start Call | |
</button> | |
</div> | |
); | |
}; | |
export default StartButton; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment