1- import React , { useState , useTransition , useRef } from "react" ;
1+ import React , { useState , useRef } from "react" ;
22import { CallOut } from "../../dist/CallOut" ;
33import { colorDecisionAndCorrespondingOptions } from "../../dist/fr/generatedFromCss/colorDecisionAndCorrespondingOptions" ;
44import type { ColorDecisionAndCorrespondingOption } from "../../src/scripts/build/cssToTs/colorDecisionAndCorrespondingOptions" ;
@@ -34,7 +34,8 @@ export function ColorHelper() {
3434 const updateFilter = ( ) =>
3535 setFilteredColorDecisionAndCorrespondingOption (
3636 filterColorDecisionAndCorrespondingOption ( {
37- search,
37+ search
38+ } ) ( {
3839 context,
3940 color,
4041 usage
@@ -43,18 +44,32 @@ export function ColorHelper() {
4344
4445 useDebounce ( ( ) => updateFilter ( ) , [ search ] ) ;
4546
46- {
47- const [ , startTransition ] = useTransition ( ) ;
48-
49- useEffectOnValueChange ( ( ) => {
50- startTransition ( ( ) => updateFilter ( ) ) ;
51- } , [ context , color , usage ] ) ;
52- }
47+ useEffectOnValueChange ( ( ) => {
48+ updateFilter ( ) ;
49+ } , [ context , color , usage ] ) ;
5350
5451 const { css } = useStyles ( ) ;
5552
5653 const evtSearchAction = useConst ( ( ) => Evt . create < "scroll to" > ( ) ) ;
5754
55+ const [ filteredContextes , setFilteredContextes ] = useState ( contextes ) ;
56+
57+ useEffectOnValueChange ( ( ) => {
58+ const f = filterColorDecisionAndCorrespondingOption ( { search } ) ;
59+
60+ setFilteredContextes (
61+ contextes . filter ( context => f ( { context, color, usage } ) . length !== 0 )
62+ ) ;
63+ } , [ search , context , color , usage ] ) ;
64+
65+ const [ filteredColors , setFilteredColors ] = useState ( colors ) ;
66+
67+ useEffectOnValueChange ( ( ) => {
68+ const f = filterColorDecisionAndCorrespondingOption ( { search } ) ;
69+
70+ setFilteredColors ( colors . filter ( color => f ( { context, color, usage } ) . length !== 0 ) ) ;
71+ } , [ search , context , color , usage ] ) ;
72+
5873 return (
5974 < MuiDsfrThemeProvider >
6075 < div >
@@ -78,37 +93,26 @@ export function ColorHelper() {
7893 evtAction = { evtSearchAction }
7994 onSearchChange = { search => setSearch ( search ) }
8095 search = { search }
81- contextes = { contextes . filter (
82- context =>
83- filterColorDecisionAndCorrespondingOption ( {
84- search,
85- context,
86- color,
87- usage
88- } ) . length !== 0
89- ) }
96+ contextes = { filteredContextes }
9097 context = { context }
9198 onContextChange = { setContext }
92- colors = { colors . filter (
93- color =>
94- filterColorDecisionAndCorrespondingOption ( {
95- search,
96- context,
97- color,
98- usage
99- } ) . length !== 0
100- ) }
99+ colors = { filteredColors }
101100 color = { color }
102101 onColorChange = { setColor }
103- usages = { usages . filter (
102+ usages = {
103+ [ ]
104+ /*
105+ usages.filter(
104106 usage =>
105107 filterColorDecisionAndCorrespondingOption({
106108 search,
107109 context,
108110 color,
109111 usage
110112 }).length !== 0
111- ) }
113+ )
114+ */
115+ }
112116 usage = { usage }
113117 onUsageChange = { setUsage }
114118 />
@@ -241,29 +245,34 @@ const { filterColorDecisionAndCorrespondingOption } = (() => {
241245 }
242246 ) ;
243247
244- function filterColorDecisionAndCorrespondingOption ( params : {
245- search : string ;
246- context : SearchProps [ "context" ] | undefined ;
247- color : SearchProps [ "color" ] | undefined ;
248- usage : SearchProps [ "usage" ] | undefined ;
249- } ) {
250- const { search, context, color, usage } = params ;
248+ function filterColorDecisionAndCorrespondingOption ( params : { search : string } ) {
249+ const { search } = params ;
251250
252- return fzf
251+ const filteredColorDecisionAndCorrespondingOptions = fzf
253252 . find ( search )
254253 . map (
255254 ( { item : colorDecisionAndCorrespondingOption } ) =>
256255 colorDecisionAndCorrespondingOption
257- )
258- . filter ( ( { parsedColorDecisionName } ) =>
259- context === undefined ? true : parsedColorDecisionName . context === context
260- )
261- . filter ( ( { parsedColorDecisionName } ) =>
262- color === undefined ? true : parsedColorDecisionName . colorName === color
263- )
264- . filter ( ( { parsedColorDecisionName } ) =>
265- usage === undefined ? true : parsedColorDecisionName . usage === usage
266256 ) ;
257+
258+ return ( params : {
259+ context : SearchProps [ "context" ] | undefined ;
260+ color : SearchProps [ "color" ] | undefined ;
261+ usage : SearchProps [ "usage" ] | undefined ;
262+ } ) => {
263+ const { context, color, usage } = params ;
264+
265+ return filteredColorDecisionAndCorrespondingOptions
266+ . filter ( ( { parsedColorDecisionName } ) =>
267+ context === undefined ? true : parsedColorDecisionName . context === context
268+ )
269+ . filter ( ( { parsedColorDecisionName } ) =>
270+ color === undefined ? true : parsedColorDecisionName . colorName === color
271+ )
272+ . filter ( ( { parsedColorDecisionName } ) =>
273+ usage === undefined ? true : parsedColorDecisionName . usage === usage
274+ ) ;
275+ } ;
267276 }
268277
269278 return { filterColorDecisionAndCorrespondingOption } ;
0 commit comments