-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add noise sensor activity list #633
Merged
Merged
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
2267b7e
Add `TabSet`
xplato 48f7ce1
ci: Format code
seambot eafb327
ci: Format code
seambot 0c3d879
Recalculate on window resize
xplato 874f692
Merge branch 'add-noise-sensor-events' of github.com:seamapi/react in…
xplato d12da0d
ci: Format code
seambot 33d9105
Format
xplato 00383c6
Merge branch 'add-noise-sensor-events' of github.com:seamapi/react in…
xplato acfce3f
ci: Format code
seambot e080073
Move ContentHeader, add on-fly adjustment
xplato 9c533fe
Merge branch 'add-noise-sensor-events' of github.com:seamapi/react in…
xplato c028e68
Add noise activity list (empty)
xplato 9995bd7
ci: Format code
seambot f2e0a34
Add useEvents
xplato e24cb2a
Merge branch 'add-noise-sensor-events' of github.com:seamapi/react in…
xplato 4393fa0
ci: Format code
seambot e938a59
Begin style improvements
xplato a9a7bf0
Merge branch 'add-noise-sensor-events' of github.com:seamapi/react in…
xplato cb0d044
Fix merge issues
xplato 530ceb0
ci: Format code
seambot 273dfc7
More style fixes
xplato 56d737b
Merge branch 'add-noise-sensor-events' of github.com:seamapi/react in…
xplato 509e710
ci: Format code
seambot 378ef0b
Update item style
xplato a67efcd
Merge branch 'add-noise-sensor-events' of github.com:seamapi/react in…
xplato 527234c
Annotate return type on `TabSet`
xplato fc28744
Remove console.log
xplato 44246ed
Update effect deps with `calculateHighlightStyle`
xplato 32645d0
Lint fixes
xplato 092cd27
ci: Format code
seambot beac826
Update types and row layout style
xplato 3b4269b
Merge branch 'add-noise-sensor-events' of github.com:seamapi/react in…
xplato df72852
ci: Format code
seambot e4f855b
Update layout style
xplato 860f96d
Merge branch 'add-noise-sensor-events' of github.com:seamapi/react in…
xplato 129fa67
Lint fixes
xplato 70a26f5
Merge branch 'main' into add-noise-sensor-events
xplato d6dcffc
Remove string template
xplato e2adad0
Remove string typeof checks
xplato 559000f
Use `globalThis`
xplato 4fc8500
Use `globalThis` (again)
xplato 1f5dc86
Use `tabTitles`
xplato 181ded4
Remove dates global func
xplato b9f7dfe
ci: Format code
seambot 5f45c4d
`useNow`
xplato 83b2a36
Merge branch 'add-noise-sensor-events' of github.com:seamapi/react in…
xplato 867eebb
ci: Format code
seambot bf0bee1
Remove `noise_detection.detected_noise`
xplato 68b7f6c
Merge branch 'add-noise-sensor-events' of github.com:seamapi/react in…
xplato 6ded29a
Replace with Luxon constants
xplato 1ef458c
Add expect err comment
xplato 87d1b1f
Add return type
xplato 6842ad9
Format fixes
xplato 2c0ac2f
Change var names
xplato adb3674
Remove TS comment
xplato 11710bc
Add refetchInterval
xplato cffa03a
Update comment
xplato f25dde1
Add issue link
xplato 68896c3
ci: Format code
seambot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,44 @@ | ||
import { useQuery, useQueryClient } from '@tanstack/react-query' | ||
import type { | ||
Event, | ||
EventsListRequest, | ||
EventsListResponse, | ||
SeamError, | ||
} from 'seamapi' | ||
|
||
import { useSeamClient } from 'lib/seam/use-seam-client.js' | ||
import type { UseSeamQueryResult } from 'lib/seam/use-seam-query-result.js' | ||
|
||
export type UseEventsParams = EventsListRequest | ||
export type UseEventsData = Event[] | ||
export interface UseEventsOptions { | ||
refetchInterval?: number | ||
} | ||
|
||
export function useEvents( | ||
params?: UseEventsParams, | ||
options?: UseEventsOptions | ||
): UseSeamQueryResult<'events', UseEventsData> { | ||
const { client } = useSeamClient() | ||
const queryClient = useQueryClient() | ||
|
||
const { data, ...rest } = useQuery<EventsListResponse['events'], SeamError>({ | ||
enabled: client != null, | ||
queryKey: ['events', 'list', params], | ||
queryFn: async () => { | ||
if (client == null) return [] | ||
return await client.events.list(params) | ||
}, | ||
onSuccess: (events) => { | ||
for (const event of events) { | ||
queryClient.setQueryData( | ||
['events', 'get', { event_id: event.event_id }], | ||
event | ||
) | ||
} | ||
}, | ||
refetchInterval: options?.refetchInterval ?? 30_000, | ||
}) | ||
|
||
return { ...rest, events: data } | ||
} |
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,110 @@ | ||
import classNames from 'classnames' | ||
import { | ||
type MouseEventHandler, | ||
useCallback, | ||
useEffect, | ||
useLayoutEffect, | ||
useState, | ||
} from 'react' | ||
|
||
interface TabSetProps<TabType extends string> { | ||
tabs: TabType[] | ||
tabTitles: Record<TabType, string> | ||
activeTab: TabType | ||
onTabChange: (tab: TabType) => void | ||
} | ||
|
||
interface HighlightStyle { | ||
left: number | ||
width: number | ||
} | ||
|
||
export function TabSet<TabType extends string>({ | ||
tabs, | ||
tabTitles, | ||
activeTab, | ||
onTabChange, | ||
}: TabSetProps<TabType>): JSX.Element { | ||
const [highlightStyle, setHighlightStyle] = useState<HighlightStyle>({ | ||
left: 0, | ||
width: 140, | ||
}) | ||
|
||
const calculateHighlightStyle = useCallback(() => { | ||
const tabButton: HTMLButtonElement | null = | ||
globalThis.document?.querySelector( | ||
`.seam-tab-button:nth-of-type(${tabs.indexOf(activeTab) + 1})` | ||
) | ||
|
||
setHighlightStyle({ | ||
left: tabButton?.offsetLeft ?? 0, | ||
width: tabButton?.offsetWidth ?? 140, | ||
}) | ||
}, [activeTab, tabs]) | ||
|
||
useLayoutEffect(() => { | ||
calculateHighlightStyle() | ||
}, [activeTab, calculateHighlightStyle]) | ||
|
||
useEffect(() => { | ||
globalThis.addEventListener?.('resize', calculateHighlightStyle) | ||
return () => { | ||
globalThis.removeEventListener?.('resize', calculateHighlightStyle) | ||
} | ||
}, [calculateHighlightStyle]) | ||
|
||
return ( | ||
<div className='seam-tab-set'> | ||
<div className='seam-tab-set-buttons'> | ||
<div className='seam-tab-set-highlight' style={highlightStyle} /> | ||
|
||
{tabs.map((tab) => ( | ||
<TabButton<TabType> | ||
key={tab} | ||
tab={tab} | ||
title={tabTitles[tab]} | ||
isActive={activeTab === tab} | ||
onTabChange={onTabChange} | ||
setHighlightStyle={setHighlightStyle} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
interface TabButtonProps<TabType> { | ||
tab: TabType | ||
title: string | ||
isActive: boolean | ||
onTabChange: (tab: TabType) => void | ||
setHighlightStyle: (style: HighlightStyle) => void | ||
} | ||
|
||
function TabButton<TabType extends string>({ | ||
tab, | ||
title, | ||
isActive, | ||
onTabChange, | ||
setHighlightStyle, | ||
}: TabButtonProps<TabType>): JSX.Element { | ||
const handleClick: MouseEventHandler<HTMLButtonElement> = (ev) => { | ||
onTabChange(tab) | ||
setHighlightStyle({ | ||
left: ev.currentTarget.offsetLeft, | ||
width: ev.currentTarget.offsetWidth, | ||
}) | ||
} | ||
|
||
return ( | ||
<button | ||
className={classNames( | ||
'seam-tab-button', | ||
isActive && 'seam-tab-button-active' | ||
)} | ||
onClick={handleClick} | ||
> | ||
<p className='seam-tab-button-label'>{title}</p> | ||
</button> | ||
) | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storybook adds a default padding to previews, this removes it.
I wonder how many other renders aren't perfectly accurate due to this...