|
1 | 1 | import { render } from "preact"; |
2 | | -import { useSignal, useSignalEffect } from "@preact/signals"; |
| 2 | +import { useSignal } from "@preact/signals"; |
3 | 3 | import { EmptyState } from "./components/EmptyState"; |
4 | 4 | import { Header } from "./components/Header"; |
5 | 5 | import { SettingsPanel } from "./components/SettingsPanel"; |
6 | | -import { Settings } from "./types"; |
7 | 6 | import { GraphVisualization } from "./components/Graph"; |
8 | 7 | import { updatesStore } from "./models/UpdatesModel"; |
9 | 8 | import { UpdatesContainer } from "./components/UpdatesContainer"; |
10 | | -import { connectionStore, sendMessage } from "./models/ConnectionModel"; |
| 9 | +import { connectionStore } from "./models/ConnectionModel"; |
| 10 | +import { settingsStore } from "./models/SettingsModel"; |
11 | 11 |
|
12 | 12 | function SignalsDevToolsPanel() { |
13 | | - const showSettings = useSignal(false); |
14 | 13 | const activeTab = useSignal<"updates" | "graph">("updates"); |
15 | 14 |
|
16 | | - // TODO: settings model |
17 | | - const settings = useSignal<Settings>({ |
18 | | - enabled: true, |
19 | | - grouped: true, |
20 | | - maxUpdatesPerSecond: 60, |
21 | | - filterPatterns: [], |
22 | | - }); |
23 | | - |
24 | | - const toggleSettings = () => { |
25 | | - showSettings.value = !showSettings.value; |
26 | | - }; |
27 | | - |
28 | | - const applySettings = (newSettings: Settings) => { |
29 | | - settings.value = newSettings; |
30 | | - sendMessage({ |
31 | | - type: "CONFIGURE_DEBUG", |
32 | | - payload: newSettings, |
33 | | - }); |
34 | | - showSettings.value = false; |
35 | | - }; |
36 | | - |
37 | | - useSignalEffect(() => { |
38 | | - const handleMessage = (event: MessageEvent) => { |
39 | | - // Only accept messages from the same origin (devtools context) |
40 | | - if (event.origin !== window.location.origin) return; |
41 | | - |
42 | | - const { type, payload } = event.data; |
43 | | - |
44 | | - switch (type) { |
45 | | - case "SIGNALS_CONFIG": |
46 | | - settings.value = payload.settings; |
47 | | - break; |
48 | | - } |
49 | | - }; |
50 | | - |
51 | | - window.addEventListener("message", handleMessage); |
52 | | - return () => window.removeEventListener("message", handleMessage); |
53 | | - }); |
54 | | - |
55 | 15 | return ( |
56 | 16 | <div id="app"> |
57 | | - <Header onToggleSettings={toggleSettings} /> |
| 17 | + <Header onToggleSettings={settingsStore.toggleSettings} /> |
58 | 18 |
|
59 | 19 | <SettingsPanel |
60 | | - isVisible={showSettings} |
61 | | - settings={settings} |
62 | | - onApply={applySettings} |
63 | | - onCancel={() => (showSettings.value = false)} |
| 20 | + isVisible={settingsStore.showSettings} |
| 21 | + onApply={settingsStore.applySettings} |
| 22 | + onCancel={settingsStore.hideSettings} |
64 | 23 | /> |
65 | 24 |
|
66 | 25 | <main className="main-content"> |
|
0 commit comments