-
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
Replace seamapi package with seam package #641
Conversation
"@tanstack/react-query": "^5.27.5", | ||
"classnames": "^2.3.2", | ||
"luxon": "^3.3.0", | ||
"queue": "^7.0.0", | ||
"radash": "^12.1.0", |
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.
as we only use shake
from this dep and as it is not typesafe, can we add a utility instead?
function filterUndefinedValues<T extends object>(input: T): {[K in keyof T as T[K] extends undefined ? never : K]: T[K]} {
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined)) as never
}
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.
Yes, noted here: #641 (comment)
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.
as it is not typesafe
Dang, I thought / hoped it was typesafe
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.
Merging this into the next version branch. Will do a followup PR to swap the dep since this one is so large and otherwise ready to go.
"@tanstack/react-query": "^5.27.5", | ||
"classnames": "^2.3.2", | ||
"luxon": "^3.3.0", | ||
"queue": "^7.0.0", | ||
"radash": "^12.1.0", |
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.
I added this dependency out of frustration for missing some simple utilities. Implementing shake
instead of adding this is an alternative.
}, | ||
onSuccess: () => { | ||
onSuccess: (data) => { | ||
queryClient.setQueryData( |
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.
Note that query invalidation is imperfect and a separate issue is tracking it here: #639
{accessCode.starts_at != null && ( | ||
<div> | ||
<div className='seam-label'>{t.start}</div> | ||
<div className='seam-date'>{formatDate(accessCode.starts_at)}</div> | ||
<div className='seam-time'>{formatTime(accessCode.starts_at)}</div> | ||
</div> | ||
)} | ||
{accessCode.ends_at != null && ( | ||
<div> | ||
<div className='seam-label'>{t.end}</div> | ||
<div className='seam-date'>{formatDate(accessCode.ends_at)}</div> | ||
<div className='seam-time'>{formatTime(accessCode.ends_at)}</div> | ||
</div> | ||
)} |
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.
This is a case of the types fixing a bug :) There are a few other cases like this.
if (device.can_program_online_access_codes == null) { | ||
return null | ||
} |
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.
Added some check on flags where it made sense for this PR, but I thin there is more we can do #643
const handleResponseError = (error: SeamHttpApiError): void => { | ||
if (isSeamHttpInvalidInputError(error)) { | ||
const errors = shake({ | ||
code: error.getValidationErrorMessages('code')[0], | ||
name: error.getValidationErrorMessages('name')[0], | ||
}) | ||
|
||
return | ||
if (Object.keys(errors).length === 0) { | ||
setResponseErrors({ | ||
unknown: error.message, | ||
}) | ||
} |
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.
New SDK feature for validation messages.
NonNullable<Required<Pick<Device['properties'], 'locked'>>> | ||
} | ||
|
||
export const isLockDevice = (device: Device): device is LockDevice => |
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.
These type guards are now application specific. In this case, Seam Components is defining how create logical device types optimized for its use case. See https://github.com/seamapi/react/blob/seam-http/src/lib/seam/noise-sensors/noise-sensor-device.ts and https://github.com/seamapi/react/blob/seam-http/src/lib/seam/thermostats/thermostat-device.ts
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.
Functions here are used for optimistic updates and some input UX.
...device, | ||
properties: { | ||
...properties, | ||
current_climate_setting: { |
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.
Optimistic updates for all thermostat hooks was expanded like this.
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.
New types fix some edge cases here.
src/lib/seam/use-seam-client.ts
Outdated
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.
Using the new client here.
Gathering changes here: #640
I've added comments to the PR to focus on interesting changes. Most of the rest is just fixing type errors or normalizing the hooks.