@@ -3,7 +3,7 @@ import Box from '@suid/material/Box'
3
3
import Container from '@suid/material/Container'
4
4
import { createTheme , ThemeProvider } from '@suid/material/styles'
5
5
import { Component , createSignal , onMount , Show } from 'solid-js'
6
- import { useNavigate , useParams } from '@solidjs/router'
6
+ import { useLocation , useNavigate , useParams } from '@solidjs/router'
7
7
import { Button , Card , CardContent , Stack , Typography } from '@suid/material'
8
8
import { grey } from '@suid/material/colors'
9
9
@@ -19,6 +19,7 @@ export default function RoomPage() {
19
19
const [ store , setStore ] = createLocalStore ( )
20
20
const params = useParams ( )
21
21
const navigate = useNavigate ( )
22
+ const location = useLocation ( )
22
23
const [ anotherPlayer , setAnotherPlayer ] = createSignal < FetchedUser | null > (
23
24
null
24
25
)
@@ -54,6 +55,9 @@ export default function RoomPage() {
54
55
const isUserPlayer1 = ( ) => store . room ?. player1_id === store . user ?. id
55
56
const isWaitingForGameToStart = ( ) => ! isUserPlayer1 ( ) && ! store . room ?. game_id
56
57
58
+ const copyLinkToClipboard = async ( ) =>
59
+ navigator . clipboard . writeText ( window . location . href )
60
+
57
61
async function enterRoom ( ) {
58
62
const room = await api . enterRoom ( store . room . id )
59
63
setStore ( 'room' , room )
@@ -81,6 +85,14 @@ export default function RoomPage() {
81
85
: anotherPlayer ( ) ?. username
82
86
}
83
87
> </ PlayerCard >
88
+ < Show when = { isUserPlayer1 ( ) && store . room ?. player2_id === null } >
89
+ < Button
90
+ color = "secondary"
91
+ onClick = { async ( ) => await copyLinkToClipboard ( ) }
92
+ >
93
+ < Typography > Copy This Link</ Typography >
94
+ </ Button >
95
+ </ Show >
84
96
85
97
< Show when = { ! isUserPlayer1 ( ) && store . room ?. player2_id === null } >
86
98
< Button variant = "contained" onClick = { ( ) => enterRoom ( ) } >
0 commit comments