1
1
import React , { useState } from 'react' ;
2
2
import { Button , Label , Radio , RadioGroup , UNSAFE_Combobox } from '@navikt/ds-react' ;
3
3
import { ChevronDownIcon , XMarkIcon } from '@navikt/aksel-icons' ;
4
- import { ContentSearchParams } from '../../../../../../common/contentSearch' ;
5
4
import { classNames } from '../../../../../utils/classNames' ;
6
- import { useAppState } from '../../../../../state/useAppState' ;
7
5
import { CmsCategoryListItem } from '../../../../../../common/cms-documents/category' ;
8
- import { persistSearchParams } from '../params-initial-state' ;
6
+ import { useAppState } from '../../../../../context/app-state/useAppState' ;
7
+ import { useSearchState } from '../../../../../context/search-state/useSearchState' ;
9
8
10
9
import style from './SearchSettings.module.css' ;
11
10
12
- type Props = {
13
- searchParams : ContentSearchParams ;
14
- setSearchParams : ( params : ContentSearchParams ) => void ;
15
- reset : ( ) => void ;
16
- } ;
17
-
18
- export const SearchSettings = ( { searchParams, setSearchParams, reset } : Props ) => {
11
+ export const SearchSettings = ( ) => {
19
12
const [ isOpen , setIsOpen ] = useState ( false ) ;
20
13
21
14
const { appContext } = useAppState ( ) ;
22
- const { rootCategories, basePath } = appContext ;
15
+ const { rootCategories } = appContext ;
23
16
17
+ const { searchParams, updateSearchParams, resetSearchParams } = useSearchState ( ) ;
24
18
const { sort, categoryKeys, type, isCustom } = searchParams ;
25
19
26
20
const { titlesToKeys, keysToTitles } = createKeysTitlesMaps ( rootCategories ) ;
27
21
const categoryKeysSelected = new Set < string > ( categoryKeys ) ;
28
22
const categoryTitlesSelected = [ ...categoryKeysSelected ] . map ( ( key ) => keysToTitles [ key ] ) ;
29
23
const categoryTitlesAll = Object . keys ( titlesToKeys ) ;
30
24
31
- const updateSearchParams = ( params : Partial < ContentSearchParams > ) => {
32
- const newParams : ContentSearchParams = { ...searchParams , ...params , isCustom : true } ;
33
- persistSearchParams ( newParams , basePath ) ;
34
- setSearchParams ( newParams ) ;
35
- } ;
36
-
37
25
return (
38
26
< div className = { style . container } >
39
27
< div className = { style . topRow } >
@@ -44,7 +32,7 @@ export const SearchSettings = ({ searchParams, setSearchParams, reset }: Props)
44
32
size = { 'xsmall' }
45
33
variant = { 'tertiary' }
46
34
className = { style . toggle }
47
- onClick = { reset }
35
+ onClick = { resetSearchParams }
48
36
>
49
37
{ 'Nullstill' }
50
38
< XMarkIcon />
0 commit comments