Skip to content

Commit 1bd42f2

Browse files
Fixing storybook
1 parent 1df3ddd commit 1bd42f2

File tree

8 files changed

+69
-6
lines changed

8 files changed

+69
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 5.1.3
2+
- Release failed, bumping again, add a console error for template rendering errors.
3+
14
# 5.1.2
25

36
### @hakit/components

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.1.2",
4+
"version": "5.1.3",
55
"private": false,
66
"keywords": [
77
"react",
@@ -70,7 +70,7 @@
7070
"@emotion/react": ">=11.x.x",
7171
"@emotion/styled": ">=11.x",
7272
"@fullcalendar/react": ">=6.x.x",
73-
"@hakit/core": "^5.1.2",
73+
"@hakit/core": "^5.1.3",
7474
"@mui/material": "^6.3.0",
7575
"@use-gesture/react": ">=10.x",
7676
"autolinker": ">=4.x",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hakit/core",
3-
"version": "5.1.2",
3+
"version": "5.1.3",
44
"private": false,
55
"type": "module",
66
"keywords": [
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { HassConnect, useStore } from "@hakit/core";
2+
import { ThemeProvider } from "@hakit/components";
3+
export function App() {
4+
return (
5+
<HassConnect hassUrl="http://homeassistant.local:8123" options={{
6+
renderError: (error) => (
7+
<div style={{ color: 'red', padding: '1rem', backgroundColor: '#fdd' }}>
8+
<h2>Error</h2>
9+
{error}
10+
<p>Please check your connection or authentication details.</p>
11+
</div>
12+
),
13+
}}>
14+
<ThemeProvider />
15+
<SomeComponent />
16+
</HassConnect>
17+
);
18+
}
19+
20+
function SomeComponent() {
21+
const connection = useStore((state) => state.connection);
22+
23+
return (
24+
<div>
25+
<h1>HassConnect Status</h1>
26+
<p>Status: {connection ? "Connected" : "Disconnected"}</p>
27+
</div>
28+
);
29+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { HassConnect, useStore } from "@hakit/core";
2+
import { ThemeProvider } from "@hakit/components";
3+
export function App() {
4+
return (
5+
<HassConnect hassUrl="http://homeassistant.local:8123" options={{
6+
locale: 'en', // Specify the desired locale
7+
}}>
8+
<ThemeProvider />
9+
<SomeComponent />
10+
</HassConnect>
11+
);
12+
}
13+
14+
function SomeComponent() {
15+
const connection = useStore((state) => state.connection);
16+
17+
return (
18+
<div>
19+
<h1>HassConnect Status</h1>
20+
<p>Status: {connection ? "Connected" : "Disconnected"}</p>
21+
</div>
22+
);
23+
}

packages/core/src/hooks/useTemplate/examples/disable.code.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { useTemplate, HassConnect } from "@hakit/core";
22
import { templateCodeToProcess } from "./constants";
3+
import { useState } from "react";
34

45
function RenderCustomTemplate() {
6+
7+
const [enabled, setEnabled] = useState(false);
58
const template = useTemplate({
6-
enabled: false,
9+
enabled,
710
template: templateCodeToProcess,
811
variables: { entity_id: "light.fake_light_1" },
912
});
1013

11-
return <>Template result: {template ?? "not-enabled"}</>;
14+
return <>
15+
Template result: {template ?? "not-enabled"}
16+
<button onClick={() => setEnabled(!enabled)}>{enabled ? "Disable" : "Enable"}</button>
17+
</>;
1218
}
1319

1420
export function App() {

packages/core/src/hooks/useTemplate/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const useTemplate = (params: TemplateParams) => {
6262

6363
const handleResponse = (response: RenderTemplateResult | RenderTemplateError) => {
6464
if ("error" in response) {
65+
console.error("Error processing template:", response.error);
6566
// We show the latest error, or a warning if there are no errors
6667
setTemplate(response.error);
6768
return;
@@ -72,6 +73,7 @@ export const useTemplate = (params: TemplateParams) => {
7273
};
7374

7475
const handleError = (err: RenderTemplateError) => {
76+
console.error("Error processing template:", err);
7577
setTemplate(err?.error || "Could not process template request.");
7678
};
7779

@@ -84,6 +86,7 @@ export const useTemplate = (params: TemplateParams) => {
8486
unsubscribeRef.current = unsub;
8587
})
8688
.catch((e: RenderTemplateError) => {
89+
console.error("Error subscribing to template:", e);
8790
handleError(e);
8891
});
8992

packages/core/src/hooks/useTemplate/useTemplate.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ function SubscribeTemplateExample() {
3434
<Alert type="info" title={`Template result: ${template ?? "loading"}`} />
3535
<Alert type="warning" title="Here's the source code for the above template example:" cssStyles={`margin-top: 2rem;`} />
3636
<Source dark code={basicExample} />
37-
<h3>Disable the template</h3>
3837
<Alert
3938
type="info"
4039
title="You can disable the template by setting the enable property to false which will conditionally run the hook subscription"

0 commit comments

Comments
 (0)