Skip to content

Commit 9c173a9

Browse files
committed
Pirker på ting
1 parent 7d55b30 commit 9c173a9

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

src/components/left-section/search/search-input/SearchInput.tsx

+1-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Props = {
1111
};
1212

1313
export const SearchInput = ({ className }: Props) => {
14-
const { setSearchResult, searchParams, updateSearchParams, runSearch } = useSearchState();
14+
const { searchParams, updateSearchParams, runSearch } = useSearchState();
1515

1616
const inputRef = useRef<HTMLInputElement>(null);
1717

@@ -27,13 +27,6 @@ export const SearchInput = ({ className }: Props) => {
2727
return;
2828
}
2929

30-
setSearchResult({
31-
hits: [],
32-
params: searchParams,
33-
total: 0,
34-
status: 'loading',
35-
});
36-
3730
runSearch(searchParams);
3831
}}
3932
>

src/components/left-section/search/search-input/search-settings/SearchSettings.module.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
flex-direction: column;
3737
gap: 0.5rem;
3838

39-
background-color: var(--a-gray-200);
39+
background-color: var(--a-blue-50);
4040
border-radius: var(--a-border-radius-medium);
4141
margin-bottom: 0.5rem;
4242
padding: 0 0.5rem;

src/components/left-section/search/search-result/SearchResult.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useRef } from 'react';
22
import { classNames } from '../../../../utils/classNames';
33
import { Alert, Button, Heading } from '@navikt/ds-react';
44
import { SearchResultHit } from './search-hit/SearchResultHit';
@@ -9,6 +9,7 @@ import { Paginator } from '../../../common/paginator/Paginator';
99
import style from './SearchResult.module.css';
1010

1111
export const SearchResult = () => {
12+
const ref = useRef<HTMLDivElement>(null);
1213
const { searchResult, setSearchResultIsOpen, searchParams, runSearch } = useSearchState();
1314

1415
const { hits, total, status, params } = searchResult;
@@ -17,11 +18,14 @@ export const SearchResult = () => {
1718
const numPages = Math.ceil(total / size);
1819
const currentPage = Math.floor(from / size) + 1;
1920

20-
const onPageChange = (page: number) => runSearch({ ...searchParams, from: size * (page - 1) });
21+
const onPageChange = (page: number) => {
22+
runSearch({ ...searchParams, from: size * (page - 1) });
23+
ref.current?.scrollTo({ top: 0 });
24+
};
2125

2226
return (
2327
<>
24-
<div className={classNames(style.result)}>
28+
<div className={classNames(style.result)} ref={ref}>
2529
{status === 'loading' ? (
2630
<ContentLoader size={'3xlarge'} text={'Laster søketreff...'} />
2731
) : status === 'error' ? (

src/context/search-state/SearchStateProvider.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ export const SearchStateProvider = ({ children }: Props) => {
3434
setSearchSettingsIsOpen(false);
3535
};
3636

37-
const runSearch = (params: ContentSearchParams) =>
37+
const runSearch = (params: ContentSearchParams) => {
38+
setSearchResult({
39+
hits: [],
40+
params,
41+
total: 0,
42+
status: 'loading',
43+
});
44+
3845
fetchSearch(params).then((result) => {
3946
setSearchResult(
4047
result || {
@@ -45,6 +52,7 @@ export const SearchStateProvider = ({ children }: Props) => {
4552
}
4653
);
4754
});
55+
};
4856

4957
useEffect(() => {
5058
setSearchResultIsOpen(searchResult.status !== 'empty');

0 commit comments

Comments
 (0)