11"use client" ;
22
33import { PlusIcon , XIcon } from "lucide-react" ;
4- import { useCallback , useEffect , useRef , useState } from "react" ;
4+ import { useEffect , useRef , useState } from "react" ;
55
66import { hexToHsv , hsvToHex , type HsvColor } from "../../lib/color" ;
77import { ColorHueSlider , ColorSaturationValuePlane } from "../ui/color-picker" ;
@@ -21,13 +21,10 @@ function ProviderCustomColorPanel(props: {
2121 const currentColor = hsvToHex ( hsv . h , hsv . s , hsv . v ) ;
2222 const [ hexDraft , setHexDraft ] = useState < string | null > ( null ) ;
2323
24- const commitHsv = useCallback (
25- ( nextHsv : HsvColor ) => {
26- setHsv ( nextHsv ) ;
27- onCommit ( hsvToHex ( nextHsv . h , nextHsv . s , nextHsv . v ) ) ;
28- } ,
29- [ onCommit ] ,
30- ) ;
24+ const commitHsv = ( nextHsv : HsvColor ) => {
25+ setHsv ( nextHsv ) ;
26+ onCommit ( hsvToHex ( nextHsv . h , nextHsv . s , nextHsv . v ) ) ;
27+ } ;
3128
3229 return (
3330 < div className = "w-56 bg-popover" >
@@ -161,36 +158,33 @@ export function ProviderAccentColorPicker(props: {
161158 } ;
162159 } , [ ] ) ;
163160
164- const commitAccentColor = useCallback (
165- ( value : string ) => {
166- const normalizedValue = normalizeProviderAccentColor ( value ) ?? "" ;
167- setOptimisticValue ( normalizedValue ) ;
168-
169- if ( commitDelayMs <= 0 ) {
170- pendingCommitRef . current = null ;
171- if ( commitTimeoutRef . current !== null ) {
172- clearTimeout ( commitTimeoutRef . current ) ;
173- commitTimeoutRef . current = null ;
174- }
175- onCommit ( normalizedValue ) ;
176- return ;
177- }
161+ const commitAccentColor = ( value : string ) => {
162+ const normalizedValue = normalizeProviderAccentColor ( value ) ?? "" ;
163+ setOptimisticValue ( normalizedValue ) ;
178164
179- pendingCommitRef . current = normalizedValue ;
165+ if ( commitDelayMs <= 0 ) {
166+ pendingCommitRef . current = null ;
180167 if ( commitTimeoutRef . current !== null ) {
181168 clearTimeout ( commitTimeoutRef . current ) ;
182- }
183- commitTimeoutRef . current = setTimeout ( ( ) => {
184169 commitTimeoutRef . current = null ;
185- const pendingCommit = pendingCommitRef . current ;
186- pendingCommitRef . current = null ;
187- if ( pendingCommit !== null ) {
188- onCommitRef . current ( pendingCommit ) ;
189- }
190- } , commitDelayMs ) ;
191- } ,
192- [ commitDelayMs , onCommit ] ,
193- ) ;
170+ }
171+ onCommit ( normalizedValue ) ;
172+ return ;
173+ }
174+
175+ pendingCommitRef . current = normalizedValue ;
176+ if ( commitTimeoutRef . current !== null ) {
177+ clearTimeout ( commitTimeoutRef . current ) ;
178+ }
179+ commitTimeoutRef . current = setTimeout ( ( ) => {
180+ commitTimeoutRef . current = null ;
181+ const pendingCommit = pendingCommitRef . current ;
182+ pendingCommitRef . current = null ;
183+ if ( pendingCommit !== null ) {
184+ onCommitRef . current ( pendingCommit ) ;
185+ }
186+ } , commitDelayMs ) ;
187+ } ;
194188
195189 const normalized = normalizeProviderAccentColor ( optimisticValue ) ;
196190 const picker = (
0 commit comments