@@ -13,6 +13,8 @@ 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' ;
16
18
17
19
interface Props {
18
20
id : string ;
@@ -37,12 +39,16 @@ const Sok = (props: Props) => {
37
39
const [ loading , setLoading ] = useState < boolean > ( false ) ;
38
40
const [ result , setResult ] = useState < Sokeresultat | undefined > ( ) ;
39
41
const [ error , setError ] = useState < string | undefined > ( ) ;
42
+ const [ cookies ] = useCookies ( ) ;
40
43
const { searchInput, setSearchInput } = props ;
41
44
const numberOfResults = 5 ;
42
45
const klassenavn = cls ( 'sok-input' , {
43
46
engelsk : language === Locale . ENGELSK ,
44
47
} ) ;
45
48
49
+ const audience = cookies [ decoratorContextCookie ] ;
50
+ const preferredLanguage = cookies [ decoratorLanguageCookie ] ;
51
+
46
52
useEffect ( ( ) => {
47
53
if ( ! props . isOpen ) {
48
54
clearInput ( ) ;
@@ -67,7 +73,7 @@ const Sok = (props: Props) => {
67
73
68
74
const getSearchUrl = ( ) => {
69
75
const { XP_BASE_URL } = environment ;
70
- const url = `${ XP_BASE_URL } /sok?ord=${ searchInput } ` ;
76
+ const url = `${ XP_BASE_URL } /nytt- sok?ord=${ searchInput } ` ;
71
77
return genererUrl ( XP_BASE_URL , url ) ;
72
78
} ;
73
79
@@ -99,6 +105,8 @@ const Sok = (props: Props) => {
99
105
setLoading ( true ) ;
100
106
fetchSearchDebounced ( {
101
107
value,
108
+ audience,
109
+ preferredLanguage,
102
110
environment,
103
111
setLoading,
104
112
setError,
@@ -137,14 +145,16 @@ const Sok = (props: Props) => {
137
145
/* Abstraction for debounce */
138
146
interface FetchResult {
139
147
value : string ;
148
+ audience : string ;
149
+ preferredLanguage : string ;
140
150
environment : Environment ;
141
151
setLoading : ( value : boolean ) => void ;
142
152
setError : ( value ?: string ) => void ;
143
153
setResult : ( value ?: any ) => void ;
144
154
}
145
155
146
156
const fetchSearch = ( props : FetchResult ) => {
147
- const { environment, value } = props ;
157
+ const { environment, value, audience , preferredLanguage } = props ;
148
158
const { setLoading, setError, setResult } = props ;
149
159
const { APP_URL } = environment ;
150
160
const url = `${ APP_URL } /api/sok` ;
@@ -157,7 +167,7 @@ const fetchSearch = (props: FetchResult) => {
157
167
label : value ,
158
168
action : 'søk-dynamisk' ,
159
169
} ) ;
160
- fetch ( `${ url } ?ord=${ encodeURIComponent ( value ) } ` )
170
+ fetch ( `${ url } ?ord=${ encodeURIComponent ( value ) } &audience= ${ audience } &preferredLanguage= ${ preferredLanguage } ` )
161
171
. then ( ( response ) => {
162
172
if ( response . ok ) {
163
173
return response ;
0 commit comments