Skip to content

Commit ae91f45

Browse files
Feature/throttle updates and responsive bug (#241) (#243)
* Fixing throttle updates and resposnive issue * Updating package and changelog with locales * Small refactor * Updating changelog
1 parent 87c03d0 commit ae91f45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+92919
-92895
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# 5.0.8
2+
3+
### @hakit/components
4+
5+
- BUGFIX - Breakpoints - A previous release caused the breakpoint logic to break, there was also another related bug where if breakpoints were provided to the ThemeProvider, it would cause a recursive update as there was a mis-match between the internal and input objects - fixes [issue](https://github.com/shannonhochkins/ha-component-kit/issues/239)
6+
- MediaPlayerCard, ControlSliderCircular, ClimateControls, RangeSlider - all now update with the trailing edge first as these also had a similar problem to the useEntity hook mentioned below.
7+
8+
9+
### @hakit/core
10+
- useEntity - issue with throttle controls acting like a delay, it will now taking the trailing/leading edge and initial updates will be immediate, default throttle time dropped from 150ms to 25ms, other components will also see a speed up in updates in the UI with this change, thanks for reporting @maumi - fixes [issue](https://github.com/shannonhochkins/ha-component-kit/issues/242)
11+
- useWeather, useLogs - also updated with incorrect throttle options
12+
113
# 5.0.7
214

315
### @hakit/components

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/components/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@hakit/components",
33
"type": "module",
4-
"version": "5.0.7",
4+
"version": "5.0.8",
55
"private": false,
66
"keywords": [
77
"react",
@@ -69,7 +69,7 @@
6969
"@emotion/react": ">=11.x.x",
7070
"@emotion/styled": ">=11.x",
7171
"@fullcalendar/react": ">=6.x.x",
72-
"@hakit/core": "^5.0.7",
72+
"@hakit/core": "^5.0.8",
7373
"@mui/material": "^6.3.0",
7474
"@use-gesture/react": ">=10.x",
7575
"autolinker": ">=4.x",

packages/components/src/Cards/MediaPlayerCard/index.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,16 @@ function InternalMediaPlayerCard({
278278
calculatePercentageViewed(media_duration, media_position);
279279
}, [media_position, calculatePercentageViewed, media_duration]);
280280

281-
const debounceUpdateClock = useThrottledCallback((value: number) => {
282-
updateClock(value);
283-
}, 20);
281+
const debounceUpdateClock = useThrottledCallback(
282+
(value: number) => {
283+
updateClock(value);
284+
},
285+
20,
286+
{
287+
trailing: true,
288+
leading: true,
289+
},
290+
);
284291

285292
// noinspection JSVoidFunctionReturnValueUsed
286293
const bindProgress = useGesture({

packages/components/src/Shared/ControlSliderCircular/index.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,29 @@ function InternalControlSliderCircular({
448448
[dual, localHigh, localLow, max, min],
449449
);
450450

451-
const triggerOnChangeApplied = useDebouncedCallback((updatedValue: number, type: ActiveSlider) => {
452-
if (typeof onChangeApplied !== "function") return;
453-
onChangeApplied(updatedValue, type);
454-
}, 100);
455-
456-
const triggerOnChange = useThrottledCallback((updatedValue: number, type: ActiveSlider) => {
457-
if (typeof onChange !== "function") return;
458-
onChange(updatedValue, type);
459-
}, 20);
451+
const triggerOnChangeApplied = useDebouncedCallback(
452+
(updatedValue: number, type: ActiveSlider) => {
453+
if (typeof onChangeApplied !== "function") return;
454+
onChangeApplied(updatedValue, type);
455+
},
456+
100,
457+
{
458+
trailing: true,
459+
leading: true,
460+
},
461+
);
462+
463+
const triggerOnChange = useThrottledCallback(
464+
(updatedValue: number, type: ActiveSlider) => {
465+
if (typeof onChange !== "function") return;
466+
onChange(updatedValue, type);
467+
},
468+
20,
469+
{
470+
trailing: true,
471+
leading: true,
472+
},
473+
);
460474

461475
const bind = useGesture(
462476
{

packages/components/src/Shared/Entity/Climate/ClimateControls/ClimateControlSlider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ export function ClimateControlSlider({ entity: _entity, targetTempStep, showCurr
177177
[_targetTemperature, entity],
178178
);
179179

180-
const _debouncedCallService = useDebouncedCallback((target: Target) => _callService(target), 1000);
180+
const _debouncedCallService = useDebouncedCallback((target: Target) => _callService(target), 1000, {
181+
trailing: true,
182+
leading: true,
183+
});
181184

182185
const _handleButton = useCallback(
183186
(target: Target, step: number) => {

packages/components/src/Shared/Entity/Climate/ClimateControls/ClimateHumiditySlider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ export function ClimateHumiditySlider({ entity: _entity, targetTempStep, showCur
5555
[entity.service],
5656
);
5757

58-
const _debouncedCallService = useDebouncedCallback((target: number) => _callService(target), 1000);
58+
const _debouncedCallService = useDebouncedCallback((target: number) => _callService(target), 1000, {
59+
leading: true,
60+
trailing: true,
61+
});
5962

6063
const _valueChanged = useCallback(
6164
(value: number) => {

packages/components/src/Shared/RangeSlider/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,19 @@ function InternalRangeSlider({
230230

231231
const callType = debounceType === "debounce" ? useDebouncedCallback : useThrottledCallback;
232232

233-
const debouncedOnChange = callType((event: React.ChangeEvent<HTMLInputElement>) => {
234-
if (typeof onChangeComplete === "function") {
235-
onChangeComplete(event.target.valueAsNumber, event);
236-
}
237-
setActive(false);
238-
}, debounceThrottleValue);
233+
const debouncedOnChange = callType(
234+
(event: React.ChangeEvent<HTMLInputElement>) => {
235+
if (typeof onChangeComplete === "function") {
236+
onChangeComplete(event.target.valueAsNumber, event);
237+
}
238+
setActive(false);
239+
},
240+
debounceThrottleValue,
241+
{
242+
leading: true,
243+
trailing: true,
244+
},
245+
);
239246

240247
return (
241248
<RangeSliderParent

packages/components/src/ThemeProvider/ThemeControls.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ export function ThemeControls() {
3535
const [dark, setDark] = useState(darkMode);
3636
const [c, setContrastThreshold] = useState(contrastThreshold);
3737

38-
const debouncedOnChange = useDebouncedCallback((_theme: ThemeStore["theme"]) => {
39-
setTheme(_theme);
40-
}, 50);
38+
const debouncedOnChange = useDebouncedCallback(
39+
(_theme: ThemeStore["theme"]) => {
40+
setTheme(_theme);
41+
},
42+
50,
43+
{
44+
trailing: true,
45+
leading: true,
46+
},
47+
);
4148

4249
useEffect(() => {
4350
debouncedOnChange({

packages/components/src/ThemeProvider/constants.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,4 @@ export const DEFAULT_THEME_OPTIONS = {
1414
saturation: 60,
1515
lightness: 54,
1616
contrastThreshold: 65,
17-
breakpoints: {
18-
xxs: 600,
19-
xs: 900,
20-
sm: 1200,
21-
md: 1536,
22-
lg: 1700,
23-
},
2417
} as const;

0 commit comments

Comments
 (0)