Skip to content

Commit

Permalink
feat: Display noise level in red if currently triggering (#636)
Browse files Browse the repository at this point in the history
* feat: Display noise level in red if currently triggering

* ci: Format code

* Update condition

---------

Co-authored-by: Seam Bot <[email protected]>
  • Loading branch information
xplato and seambot authored Jun 27, 2024
1 parent 36efbdf commit a03f115
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .storybook/seed-fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,11 @@ export const seedFake = (db) => {
noiseaware_metadata: {
device_model: 'indoor',
noise_level_nrs: 1,
noise_level_decibel: 42,
noise_level_decibel: 80,
device_name: 'Living room',
device_id: 'noiseaware_123',
},
currently_triggering_noise_threshold_ids: [],
},
errors: [],
})
Expand Down
6 changes: 6 additions & 0 deletions assets/icons/noise-levels-red.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"luxon": "^3.3.0",
"queue": "^7.0.0",
"react-hook-form": "^7.46.1",
"seamapi": "^8.22.1",
"seamapi": "^8.24.0",
"uuid": "^9.0.0",
"zoned-time": "^1.1.2"
},
Expand Down
33 changes: 33 additions & 0 deletions src/lib/icons/NoiseLevelsRed.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/lib/ui/device/NoiseLevelStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import classNames from 'classnames'
import type { NoiseSensorDevice } from 'seamapi'

import { NoiseLevelsIcon } from 'lib/icons/NoiseLevels.js'
import { NoiseLevelsRedIcon } from 'lib/icons/NoiseLevelsRed.js'

interface NoiseLevelStatusProps {
device: NoiseSensorDevice
Expand All @@ -9,13 +11,22 @@ interface NoiseLevelStatusProps {
export function NoiseLevelStatus({
device,
}: NoiseLevelStatusProps): JSX.Element {
const isActivated =
(device?.properties?.currently_triggering_noise_threshold_ids ?? [])
?.length > 0

return (
<>
<span className='seam-label'>{t.noiseLevel}:</span>

<div className='seam-device-status'>
<NoiseLevelsIcon />
<span className='seam-text'>{getNoiseLevel(device)}</span>
{isActivated ? <NoiseLevelsRedIcon /> : <NoiseLevelsIcon />}
<span
className={classNames('seam-text', isActivated && 'seam-text-danger')}
>
{getNoiseLevel(device)}
{isActivated && ` (${t.noisy})`}
</span>
</div>
</>
)
Expand Down Expand Up @@ -55,4 +66,5 @@ const t = {
unknown: 'Unknown',
decibel: 'dB',
noiseAwareDefault: '0-40 dB',
noisy: 'noisy',
}

0 comments on commit a03f115

Please sign in to comment.