@@ -13,8 +13,6 @@ import SokResultater from './sok-innhold/SokResultater';
13
13
import { Environment } from 'store/reducers/environment-duck' ;
14
14
import Cookies from 'js-cookie' ;
15
15
import 'komponenter/header/header-regular/common/sok/Sok.scss' ;
16
- import { useCookies } from 'react-cookie' ;
17
- import { decoratorContextCookie , decoratorLanguageCookie } from '../../../Header' ;
18
16
19
17
interface Props {
20
18
id : string ;
@@ -30,26 +28,23 @@ const MAX_HITS_TO_DISPLAY = 5;
30
28
const stateSelector = ( state : AppState ) => ( {
31
29
environment : state . environment ,
32
30
language : state . language . language ,
31
+ audience : state . arbeidsflate . status ,
33
32
} ) ;
34
33
35
34
const setSubmitTrackerCookie = ( ) => {
36
35
Cookies . set ( 'nav-search-use' , Date . now ( ) . toString ( ) , { expires : 30 , domain : '.nav.no' } ) ;
37
36
} ;
38
37
39
38
const Sok = ( props : Props ) => {
40
- const { environment, language } = useSelector ( stateSelector ) ;
39
+ const { environment, language, audience } = useSelector ( stateSelector ) ;
41
40
const [ loading , setLoading ] = useState < boolean > ( false ) ;
42
41
const [ result , setResult ] = useState < Sokeresultat | undefined > ( ) ;
43
42
const [ error , setError ] = useState < string | undefined > ( ) ;
44
- const [ cookies ] = useCookies ( ) ;
45
43
const { searchInput, setSearchInput, searchHitsCallback } = props ;
46
44
const klassenavn = cls ( 'sok-input' , {
47
45
engelsk : language === Locale . ENGELSK ,
48
46
} ) ;
49
47
50
- const audience = cookies [ decoratorContextCookie ] ;
51
- const preferredLanguage = cookies [ decoratorLanguageCookie ] ;
52
-
53
48
useEffect ( ( ) => {
54
49
if ( ! props . isOpen ) {
55
50
clearInput ( ) ;
@@ -113,7 +108,7 @@ const Sok = (props: Props) => {
113
108
fetchSearchDebounced ( {
114
109
value,
115
110
audience,
116
- preferredLanguage ,
111
+ language ,
117
112
environment,
118
113
setLoading,
119
114
setError,
@@ -154,15 +149,15 @@ const Sok = (props: Props) => {
154
149
interface FetchResult {
155
150
value : string ;
156
151
audience : string ;
157
- preferredLanguage : string ;
152
+ language : Locale ;
158
153
environment : Environment ;
159
154
setLoading : ( value : boolean ) => void ;
160
155
setError : ( value ?: string ) => void ;
161
156
setResult : ( value ?: any ) => void ;
162
157
}
163
158
164
159
const fetchSearch = ( props : FetchResult ) => {
165
- const { environment, value, audience, preferredLanguage } = props ;
160
+ const { environment, value, audience, language } = props ;
166
161
const { setLoading, setError, setResult } = props ;
167
162
const { APP_URL } = environment ;
168
163
const url = `${ APP_URL } /api/sok` ;
@@ -184,7 +179,7 @@ const fetchSearch = (props: FetchResult) => {
184
179
185
180
const facet = validAudiences [ audience ] || '0' ;
186
181
187
- fetch ( `${ url } ?ord=${ encodeURIComponent ( value ) } &f=${ facet } &preferredLanguage=${ preferredLanguage } ` )
182
+ fetch ( `${ url } ?ord=${ encodeURIComponent ( value ) } &f=${ facet } &preferredLanguage=${ language } ` )
188
183
. then ( ( response ) => {
189
184
if ( response . ok ) {
190
185
return response ;
0 commit comments