-
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
5431048
commit 1f00bf2
Showing
21 changed files
with
296 additions
and
8 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
client/src/components/BluetoothConnectDialog/BluetoothConnectDialog.lazy.tsx
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,15 @@ | ||
import React, { lazy, Suspense } from 'react'; | ||
|
||
const LazyBluetoothConnectDialog = lazy( | ||
() => import('./BluetoothConnectDialog'), | ||
); | ||
|
||
const BluetoothConnectDialog = ( | ||
props: JSX.IntrinsicAttributes & { children?: React.ReactNode }, | ||
) => ( | ||
<Suspense fallback={null}> | ||
<LazyBluetoothConnectDialog {...props} /> | ||
</Suspense> | ||
); | ||
|
||
export default BluetoothConnectDialog; |
1 change: 1 addition & 0 deletions
1
client/src/components/BluetoothConnectDialog/BluetoothConnectDialog.module.scss
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 @@ | ||
.BluetoothConnectDialog {} |
12 changes: 12 additions & 0 deletions
12
client/src/components/BluetoothConnectDialog/BluetoothConnectDialog.stories.tsx
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,12 @@ | ||
/* eslint-disable */ | ||
import BluetoothConnectDialog from './BluetoothConnectDialog'; | ||
|
||
export default { | ||
title: "BluetoothConnectDialog", | ||
}; | ||
|
||
export const Default = () => <BluetoothConnectDialog />; | ||
|
||
Default.story = { | ||
name: 'default', | ||
}; |
14 changes: 14 additions & 0 deletions
14
client/src/components/BluetoothConnectDialog/BluetoothConnectDialog.test.tsx
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,14 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import BluetoothConnectDialog from './BluetoothConnectDialog'; | ||
|
||
describe('<BluetoothConnectDialog />', () => { | ||
test('it should mount', () => { | ||
render(<BluetoothConnectDialog />); | ||
|
||
const bluetoothConnectDialog = screen.getByTestId('BluetoothConnectDialog'); | ||
|
||
expect(bluetoothConnectDialog).toBeInTheDocument(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
client/src/components/BluetoothConnectDialog/BluetoothConnectDialog.tsx
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,48 @@ | ||
import { Container, Dialog, DialogTitle } from '@mui/material'; | ||
import React, { FC, useEffect, useState } from 'react'; | ||
import styles from './BluetoothConnectDialog.module.scss'; | ||
import BluetoothDeviceSelection from '../BluetoothDeviceSelection/BluetoothDeviceSelection'; | ||
import UnsupportedPlatform from '../UnsupportedPlatform/UnsupportedPlatform'; | ||
|
||
interface BluetoothConnectDialogProps { | ||
open: boolean; | ||
onClose: (device: BluetoothDevice) => void; | ||
} | ||
|
||
const BluetoothConnectDialog: FC<BluetoothConnectDialogProps> = ( | ||
props: BluetoothConnectDialogProps, | ||
) => { | ||
const { onClose, open } = props; | ||
const [supportsBluetooth, setSupportsBluetooth] = useState(false); | ||
|
||
useEffect(() => { | ||
if (navigator.bluetooth) { | ||
navigator.bluetooth | ||
.getAvailability() | ||
.then((isAvailable) => setSupportsBluetooth(isAvailable)) | ||
.catch(() => setSupportsBluetooth(false)); | ||
} | ||
}, []); | ||
|
||
const handleClose = (device: BluetoothDevice) => { | ||
onClose(device); | ||
}; | ||
|
||
return ( | ||
<Container | ||
className={styles.BluetoothConnectDialog} | ||
data-testid="BluetoothConnectDialog" | ||
> | ||
<Dialog fullWidth={true} onClose={handleClose} open={open}> | ||
<DialogTitle>Connect to headset</DialogTitle> | ||
{supportsBluetooth ? ( | ||
<BluetoothDeviceSelection handleDeviceClick={handleClose} /> | ||
) : ( | ||
<UnsupportedPlatform /> | ||
)} | ||
</Dialog> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default BluetoothConnectDialog; |
11 changes: 11 additions & 0 deletions
11
client/src/components/BluetoothConnectionOptions/BluetoothConnectionOptions.lazy.tsx
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,11 @@ | ||
import React, { lazy, Suspense } from 'react'; | ||
|
||
const LazyBluetoothConnectionOptions = lazy(() => import('./BluetoothConnectionOptions')); | ||
|
||
const BluetoothConnectionOptions = (props: JSX.IntrinsicAttributes & { children?: React.ReactNode; }) => ( | ||
<Suspense fallback={null}> | ||
<LazyBluetoothConnectionOptions {...props} /> | ||
</Suspense> | ||
); | ||
|
||
export default BluetoothConnectionOptions; |
1 change: 1 addition & 0 deletions
1
client/src/components/BluetoothConnectionOptions/BluetoothConnectionOptions.module.scss
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 @@ | ||
.BluetoothConnectionOptions {} |
12 changes: 12 additions & 0 deletions
12
client/src/components/BluetoothConnectionOptions/BluetoothConnectionOptions.stories.tsx
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,12 @@ | ||
/* eslint-disable */ | ||
import BluetoothConnectionOptions from './BluetoothConnectionOptions'; | ||
|
||
export default { | ||
title: "BluetoothConnectionOptions", | ||
}; | ||
|
||
export const Default = () => <BluetoothConnectionOptions />; | ||
|
||
Default.story = { | ||
name: 'default', | ||
}; |
14 changes: 14 additions & 0 deletions
14
client/src/components/BluetoothConnectionOptions/BluetoothConnectionOptions.test.tsx
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,14 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import BluetoothConnectionOptions from './BluetoothConnectionOptions'; | ||
|
||
describe('<BluetoothConnectionOptions />', () => { | ||
test('it should mount', () => { | ||
render(<BluetoothConnectionOptions />); | ||
|
||
const bluetoothConnectionOptions = screen.getByTestId('BluetoothConnectionOptions'); | ||
|
||
expect(bluetoothConnectionOptions).toBeInTheDocument(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
client/src/components/BluetoothConnectionOptions/BluetoothConnectionOptions.tsx
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,48 @@ | ||
import React, { FC, useContext } from 'react'; | ||
import { Button, Container } from '@mui/material'; | ||
import styles from './BluetoothConnectionOptions.module.scss'; | ||
import { BluetoothSearching, BluetoothDisabled } from '@mui/icons-material'; | ||
import BluetoothConnectDialog from '../BluetoothConnectDialog/BluetoothConnectDialog'; | ||
import { HeadsetContext } from '../../contexts/HeadsetContext'; | ||
|
||
const BluetoothConnectionOptions: FC<{}> = () => { | ||
const { headset, setHeadset } = useContext(HeadsetContext); | ||
const [open, setOpen] = React.useState(false); | ||
|
||
const handleOpen = () => { | ||
setOpen(true); | ||
}; | ||
|
||
const handleClose = (device: BluetoothDevice) => { | ||
setOpen(false); | ||
connectDevice(device); | ||
}; | ||
|
||
const connectDevice = (device: BluetoothDevice) => { | ||
setHeadset(device); | ||
}; | ||
|
||
const disconnectDevice = () => { | ||
setHeadset(undefined); | ||
}; | ||
|
||
return ( | ||
<Container | ||
className={styles.BluetoothConnectionOptions} | ||
data-testid="BluetoothConnectionOptions" | ||
> | ||
{!headset ? ( | ||
<Button variant="outlined" onClick={handleOpen}> | ||
<BluetoothSearching /> Connect | ||
</Button> | ||
) : ( | ||
<Button variant="outlined" onClick={() => disconnectDevice()}> | ||
<BluetoothDisabled /> Disconnect | ||
</Button> | ||
)} | ||
<BluetoothConnectDialog open={open} onClose={handleClose} /> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default BluetoothConnectionOptions; |
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
11 changes: 11 additions & 0 deletions
11
client/src/components/HeadsetMonitor/HeadsetMonitor.lazy.tsx
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,11 @@ | ||
import React, { lazy, Suspense } from 'react'; | ||
|
||
const LazyHeadsetMonitor = lazy(() => import('./HeadsetMonitor')); | ||
|
||
const HeadsetMonitor = (props: JSX.IntrinsicAttributes & { children?: React.ReactNode; }) => ( | ||
<Suspense fallback={null}> | ||
<LazyHeadsetMonitor {...props} /> | ||
</Suspense> | ||
); | ||
|
||
export default HeadsetMonitor; |
1 change: 1 addition & 0 deletions
1
client/src/components/HeadsetMonitor/HeadsetMonitor.module.scss
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 @@ | ||
.HeadsetMonitor {} |
12 changes: 12 additions & 0 deletions
12
client/src/components/HeadsetMonitor/HeadsetMonitor.stories.tsx
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,12 @@ | ||
/* eslint-disable */ | ||
import HeadsetMonitor from './HeadsetMonitor'; | ||
|
||
export default { | ||
title: "HeadsetMonitor", | ||
}; | ||
|
||
export const Default = () => <HeadsetMonitor />; | ||
|
||
Default.story = { | ||
name: 'default', | ||
}; |
14 changes: 14 additions & 0 deletions
14
client/src/components/HeadsetMonitor/HeadsetMonitor.test.tsx
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,14 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import HeadsetMonitor from './HeadsetMonitor'; | ||
|
||
describe('<HeadsetMonitor />', () => { | ||
test('it should mount', () => { | ||
render(<HeadsetMonitor />); | ||
|
||
const headsetMonitor = screen.getByTestId('HeadsetMonitor'); | ||
|
||
expect(headsetMonitor).toBeInTheDocument(); | ||
}); | ||
}); |
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,14 @@ | ||
import { Container } from '@mui/material'; | ||
import React, { FC } from 'react'; | ||
import BluetoothConnectionOptions from '../BluetoothConnectionOptions/BluetoothConnectionOptions'; | ||
import styles from './HeadsetMonitor.module.scss'; | ||
|
||
const HeadsetMonitor: FC<{}> = () => { | ||
return ( | ||
<Container className={styles.HeadsetMonitor} data-testid="HeadsetMonitor"> | ||
<BluetoothConnectionOptions /> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default HeadsetMonitor; |
11 changes: 11 additions & 0 deletions
11
client/src/components/UnsupportedPlatform/UnsupportedPlatform.lazy.tsx
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,11 @@ | ||
import React, { lazy, Suspense } from 'react'; | ||
|
||
const LazyUnsupportedPlatform = lazy(() => import('./UnsupportedPlatform')); | ||
|
||
const UnsupportedPlatform = (props: JSX.IntrinsicAttributes & { children?: React.ReactNode; }) => ( | ||
<Suspense fallback={null}> | ||
<LazyUnsupportedPlatform {...props} /> | ||
</Suspense> | ||
); | ||
|
||
export default UnsupportedPlatform; |
1 change: 1 addition & 0 deletions
1
client/src/components/UnsupportedPlatform/UnsupportedPlatform.module.scss
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 @@ | ||
.UnsupportedPlatform {} |
12 changes: 12 additions & 0 deletions
12
client/src/components/UnsupportedPlatform/UnsupportedPlatform.stories.tsx
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,12 @@ | ||
/* eslint-disable */ | ||
import UnsupportedPlatform from './UnsupportedPlatform'; | ||
|
||
export default { | ||
title: "UnsupportedPlatform", | ||
}; | ||
|
||
export const Default = () => <UnsupportedPlatform />; | ||
|
||
Default.story = { | ||
name: 'default', | ||
}; |
14 changes: 14 additions & 0 deletions
14
client/src/components/UnsupportedPlatform/UnsupportedPlatform.test.tsx
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,14 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import UnsupportedPlatform from './UnsupportedPlatform'; | ||
|
||
describe('<UnsupportedPlatform />', () => { | ||
test('it should mount', () => { | ||
render(<UnsupportedPlatform />); | ||
|
||
const unsupportedPlatform = screen.getByTestId('UnsupportedPlatform'); | ||
|
||
expect(unsupportedPlatform).toBeInTheDocument(); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
client/src/components/UnsupportedPlatform/UnsupportedPlatform.tsx
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,19 @@ | ||
import { Container, Typography } from '@mui/material'; | ||
import React, { FC } from 'react'; | ||
import styles from './UnsupportedPlatform.module.scss'; | ||
|
||
const UnsupportedPlatform: FC<{}> = () => { | ||
return ( | ||
<Container | ||
className={styles.UnsupportedPlatform} | ||
data-testid="UnsupportedPlatform" | ||
> | ||
<Typography textAlign="center"> | ||
Sadly, the platform you are running this application on is currently | ||
unsupported. | ||
</Typography> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default UnsupportedPlatform; |