Skip to content

Commit 463e739

Browse files
authored
feat: refactor store using zustand (#171)
1 parent b1cb5d4 commit 463e739

51 files changed

Lines changed: 437 additions & 605 deletions

Some content is hidden

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

biome.json

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,7 @@
8383
"fix": "none",
8484
"options": {}
8585
},
86-
"useExhaustiveDependencies": {
87-
"level": "error",
88-
"options": {
89-
"hooks": [
90-
{
91-
"name": "useApiWebSocket",
92-
"closureIndex": 0,
93-
"dependenciesIndex": 1
94-
},
95-
{
96-
"name": "useAppDispatch",
97-
"closureIndex": 0,
98-
"dependenciesIndex": 1
99-
},
100-
{
101-
"name": "useAppSelector",
102-
"closureIndex": 0,
103-
"dependenciesIndex": 1
104-
},
105-
{
106-
"name": "useAppStore",
107-
"closureIndex": 0,
108-
"dependenciesIndex": 1
109-
}
110-
]
111-
}
112-
}
86+
"useExhaustiveDependencies": "error"
11387
},
11488
"performance": {
11589
"noBarrelFile": "error",

package-lock.json

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

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zigbee2mqtt-windfront",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"license": "GPL-3.0-or-later",
55
"type": "module",
66
"main": "index.js",
@@ -22,7 +22,7 @@
2222
"build": "vite build",
2323
"preview": "vite preview",
2424
"start": "vite dev",
25-
"start:envs": "VITE_Z2M_API_URLS=localhost:5173/api,bogus.local:8080/api VITE_Z2M_API_NAMES=one,two npm start",
25+
"start:envs": "VITE_Z2M_API_URLS=localhost:5173/api,localhost:8080/api,bogus.local:8080/api VITE_Z2M_API_NAMES=dev,main,bogus npm start",
2626
"test": "vitest run",
2727
"test:cov": "vitest run --coverage",
2828
"typecheck": "tsc --noEmit",
@@ -38,7 +38,6 @@
3838
"@fortawesome/fontawesome-svg-core": "^7.0.0",
3939
"@fortawesome/free-solid-svg-icons": "^7.0.0",
4040
"@fortawesome/react-fontawesome": "^0.2.3",
41-
"@reduxjs/toolkit": "^2.8.2",
4241
"@storybook/addon-a11y": "^9.1.2",
4342
"@storybook/addon-docs": "^9.1.2",
4443
"@storybook/react-vite": "^9.1.2",
@@ -64,7 +63,6 @@
6463
"react-dom": "^19.1.1",
6564
"react-i18next": "^15.6.1",
6665
"react-image": "^4.1.0",
67-
"react-redux": "^9.2.0",
6866
"react-router": "^7.8.0",
6967
"react-use-websocket": "^4.13.0",
7068
"reagraph": "^4.29.0",
@@ -77,7 +75,8 @@
7775
"vite-plugin-compression2": "^2.2.0",
7876
"vitest": "^3.1.2",
7977
"ws": "^8.18.3",
80-
"zigbee2mqtt": "github:Koenkk/zigbee2mqtt#dev-types"
78+
"zigbee2mqtt": "github:Koenkk/zigbee2mqtt#dev-types",
79+
"zustand": "^5.0.7"
8180
},
8281
"sideEffects": [
8382
"*.css"

src/ErrorBoundary.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Component, type PropsWithChildren } from "react";
1+
import { Component, memo, type PropsWithChildren } from "react";
22
import { NEW_GITHUB_ISSUE_URL } from "./consts.js";
3-
import store from "./store.js";
3+
import { useAppStore } from "./store.js";
44
import { downloadAsZip } from "./utils.js";
55

66
type ErrorBoundaryState =
@@ -21,6 +21,18 @@ const INITIAL_STATE: ErrorBoundaryState = {
2121

2222
type ErrorBoundaryProps = PropsWithChildren;
2323

24+
const DownloadStateButton = memo(() => (
25+
<button
26+
type="button"
27+
className="btn btn-primary btn-square animate-pulse text-3xl"
28+
onClick={async () => {
29+
await downloadAsZip(useAppStore.getState() as unknown as Record<string, unknown>, "state.json");
30+
}}
31+
>
32+
33+
</button>
34+
));
35+
2436
/** Based on https://github.com/bvaughn/react-error-boundary */
2537
export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
2638
constructor(props: ErrorBoundaryProps) {
@@ -70,15 +82,7 @@ export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundarySt
7082
<div>Save this file</div>
7183
<div className="text-xs font-semibold opacity-60">For use in next step</div>
7284
</div>
73-
<button
74-
type="button"
75-
className="btn btn-primary btn-square animate-pulse text-3xl"
76-
onClick={async () => {
77-
await downloadAsZip(store.getState() as unknown as Record<string, unknown>, "state.json");
78-
}}
79-
>
80-
81-
</button>
85+
<DownloadStateButton />
8286
</li>
8387
<li className="list-row">
8488
<div />

0 commit comments

Comments
 (0)