@@ -15,8 +15,7 @@ import {
15
15
} from '@wordpress/blocks' ;
16
16
import { createHigherOrderComponent , useInstanceId } from '@wordpress/compose' ;
17
17
import { addFilter } from '@wordpress/hooks' ;
18
- import { useMemo , useEffect } from '@wordpress/element' ;
19
- import { useDispatch } from '@wordpress/data' ;
18
+ import { useMemo } from '@wordpress/element' ;
20
19
21
20
/**
22
21
* Internal dependencies
@@ -34,11 +33,9 @@ import {
34
33
} from '../components/duotone/utils' ;
35
34
import { getBlockCSSSelector } from '../components/global-styles/get-block-css-selector' ;
36
35
import { scopeSelector } from '../components/global-styles/utils' ;
37
- import { useBlockSettings } from './utils' ;
36
+ import { useBlockSettings , useStyleOverride } from './utils' ;
38
37
import { default as StylesFiltersPanel } from '../components/global-styles/filters-panel' ;
39
38
import { useBlockEditingMode } from '../components/block-editing-mode' ;
40
- import { store as blockEditorStore } from '../store' ;
41
- import { unlock } from '../lock-unlock' ;
42
39
43
40
const EMPTY_ARRAY = [ ] ;
44
41
@@ -274,38 +271,28 @@ function DuotoneStyles( {
274
271
275
272
const isValidFilter = Array . isArray ( colors ) || colors === 'unset' ;
276
273
277
- const { setStyleOverride, deleteStyleOverride } = unlock (
278
- useDispatch ( blockEditorStore )
274
+ useStyleOverride (
275
+ isValidFilter
276
+ ? {
277
+ css :
278
+ colors !== 'unset'
279
+ ? getDuotoneStylesheet ( selector , filterId )
280
+ : getDuotoneUnsetStylesheet ( selector ) ,
281
+ __unstableType : 'presets' ,
282
+ }
283
+ : undefined
284
+ ) ;
285
+ useStyleOverride (
286
+ isValidFilter
287
+ ? {
288
+ assets :
289
+ colors !== 'unset'
290
+ ? getDuotoneFilter ( filterId , colors )
291
+ : '' ,
292
+ __unstableType : 'svgs' ,
293
+ }
294
+ : undefined
279
295
) ;
280
-
281
- useEffect ( ( ) => {
282
- if ( ! isValidFilter ) return ;
283
-
284
- setStyleOverride ( filterId , {
285
- css :
286
- colors !== 'unset'
287
- ? getDuotoneStylesheet ( selector , filterId )
288
- : getDuotoneUnsetStylesheet ( selector ) ,
289
- __unstableType : 'presets' ,
290
- } ) ;
291
- setStyleOverride ( `duotone-${ filterId } ` , {
292
- assets :
293
- colors !== 'unset' ? getDuotoneFilter ( filterId , colors ) : '' ,
294
- __unstableType : 'svgs' ,
295
- } ) ;
296
-
297
- return ( ) => {
298
- deleteStyleOverride ( filterId ) ;
299
- deleteStyleOverride ( `duotone-${ filterId } ` ) ;
300
- } ;
301
- } , [
302
- isValidFilter ,
303
- colors ,
304
- selector ,
305
- filterId ,
306
- setStyleOverride ,
307
- deleteStyleOverride ,
308
- ] ) ;
309
296
310
297
return null ;
311
298
}
0 commit comments