1- import React , { useState } from "react" ;
1+ import React , { useState , useTransition } from "react" ;
22import { CallOut } from "../../dist/CallOut" ;
33import { colorDecisionAndCorrespondingOption } from "../../dist/fr/generatedFromCss/colorDecisionAndCorrespondingOptions" ;
44import type { ColorDecisionAndCorrespondingOption } from "../../src/scripts/build/cssToTs/colorDecisionAndCorrespondingOptions" ;
@@ -12,6 +12,7 @@ import { Evt } from "evt";
1212import { useStyles } from "./makeStyles" ;
1313import { ColorDecisionCard } from "./ColorDecisionCard" ;
1414import type { Props as SearchProps } from "./Search" ;
15+ import { useEffectOnValueChange } from "powerhooks/useEffectOnValueChange" ;
1516
1617const colors = Array . from (
1718 new Set (
@@ -69,27 +70,33 @@ export function ColorHelper() {
6970 const [ color , setColor ] = useState < SearchProps [ "color" ] > ( undefined ) ;
7071 const [ usage , setUsage ] = useState < SearchProps [ "usage" ] > ( undefined ) ;
7172
72- useDebounce ( {
73- "query" : search + ( context ?? "" ) + ( color ?? "" ) + ( usage ?? "" ) ,
74- "onDebounced" : ( ) =>
75- setFilteredColorDecisionAndCorrespondingOption (
76- fzf
77- . find ( search )
78- . map (
79- ( { item : colorDecisionAndCorrespondingOption } ) =>
80- colorDecisionAndCorrespondingOption
81- )
82- . filter ( ( { parsedColorDecisionName } ) =>
83- context === undefined ? true : parsedColorDecisionName . context === context
84- )
85- . filter ( ( { parsedColorDecisionName } ) =>
86- color === undefined ? true : parsedColorDecisionName . colorName === color
87- )
88- . filter ( ( { parsedColorDecisionName } ) =>
89- usage === undefined ? true : parsedColorDecisionName . usage === usage
90- )
91- )
92- } ) ;
73+ const [ , startTransition ] = useTransition ( ) ;
74+
75+ const updateSearch = ( ) => {
76+ setFilteredColorDecisionAndCorrespondingOption (
77+ fzf
78+ . find ( search )
79+ . map (
80+ ( { item : colorDecisionAndCorrespondingOption } ) =>
81+ colorDecisionAndCorrespondingOption
82+ )
83+ . filter ( ( { parsedColorDecisionName } ) =>
84+ context === undefined ? true : parsedColorDecisionName . context === context
85+ )
86+ . filter ( ( { parsedColorDecisionName } ) =>
87+ color === undefined ? true : parsedColorDecisionName . colorName === color
88+ )
89+ . filter ( ( { parsedColorDecisionName } ) =>
90+ usage === undefined ? true : parsedColorDecisionName . usage === usage
91+ )
92+ ) ;
93+ } ;
94+
95+ useEffectOnValueChange ( ( ) => {
96+ startTransition ( ( ) => updateSearch ( ) ) ;
97+ } , [ context , color , usage ] ) ;
98+
99+ useDebounce ( updateSearch , [ search ] ) ;
93100
94101 const { css } = useStyles ( ) ;
95102
0 commit comments