1- import { useState , useEffect } from "preact/hooks " ;
1+ import { Signal , useSignal , useSignalEffect } from "@ preact/signals " ;
22import { Button } from "./Button" ;
33import { Settings } from "../types" ;
44
55interface SettingsPanelProps {
6- isVisible : boolean ;
7- settings : Settings ;
6+ isVisible : Signal < boolean > ;
7+ settings : Signal < Settings > ;
88 onApply : ( settings : Settings ) => void ;
99 onCancel : ( ) => void ;
1010}
@@ -15,17 +15,19 @@ export function SettingsPanel({
1515 onApply,
1616 onCancel,
1717} : SettingsPanelProps ) {
18- const [ localSettings , setLocalSettings ] = useState < Settings > ( settings ) ;
18+ const localSettings = useSignal < Settings > ( settings . value ) ;
1919
20- useEffect ( ( ) => {
21- setLocalSettings ( settings ) ;
22- } , [ settings ] ) ;
20+ useSignalEffect ( ( ) => {
21+ localSettings . value = settings . value ;
22+ } ) ;
2323
2424 const handleApply = ( ) => {
25- onApply ( localSettings ) ;
25+ onApply ( localSettings . value ) ;
2626 } ;
2727
28- if ( ! isVisible ) return null ;
28+ if ( ! isVisible . value ) {
29+ return null ;
30+ }
2931
3032 return (
3133 < div className = "settings-panel" >
@@ -36,10 +38,10 @@ export function SettingsPanel({
3638 < label >
3739 < input
3840 type = "checkbox"
39- checked = { localSettings . enabled }
41+ checked = { localSettings . value . enabled }
4042 onChange = { e =>
41- setLocalSettings ( {
42- ...localSettings ,
43+ ( localSettings . value = {
44+ ...localSettings . value ,
4345 enabled : ( e . target as HTMLInputElement ) . checked ,
4446 } )
4547 }
@@ -52,10 +54,10 @@ export function SettingsPanel({
5254 < label >
5355 < input
5456 type = "checkbox"
55- checked = { localSettings . grouped }
57+ checked = { localSettings . value . grouped }
5658 onChange = { e =>
57- setLocalSettings ( {
58- ...localSettings ,
59+ ( localSettings . value = {
60+ ...localSettings . value ,
5961 grouped : ( e . target as HTMLInputElement ) . checked ,
6062 } )
6163 }
@@ -69,12 +71,12 @@ export function SettingsPanel({
6971 < input
7072 type = "number"
7173 id = "maxUpdatesInput"
72- value = { localSettings . maxUpdatesPerSecond }
74+ value = { localSettings . value . maxUpdatesPerSecond }
7375 min = "1"
7476 max = "1000"
7577 onChange = { e =>
76- setLocalSettings ( {
77- ...localSettings ,
78+ ( localSettings . value = {
79+ ...localSettings . value ,
7880 maxUpdatesPerSecond :
7981 parseInt ( ( e . target as HTMLInputElement ) . value ) || 60 ,
8082 } )
@@ -89,10 +91,10 @@ export function SettingsPanel({
8991 < textarea
9092 id = "filterPatternsInput"
9193 placeholder = "user.* .*State$ global"
92- value = { localSettings . filterPatterns . join ( "\n" ) }
94+ value = { localSettings . value . filterPatterns . join ( "\n" ) }
9395 onChange = { e =>
94- setLocalSettings ( {
95- ...localSettings ,
96+ ( localSettings . value = {
97+ ...localSettings . value ,
9698 filterPatterns : ( e . target as HTMLTextAreaElement ) . value
9799 . split ( "\n" )
98100 . map ( pattern => pattern . trim ( ) )
0 commit comments