Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
digibib
deichman
Commits
17d0440d
Commit
17d0440d
authored
May 12, 2021
by
deb355529
Browse files
DEICH-5813
: deichman.no: added option to add items to "huskeliste", also did a cleanup
parent
29bfba43
Changes
1
Show whitespace changes
Inline
Side-by-side
deichman.no/components/SearchResults/SearchResults.js
View file @
17d0440d
import
React
,
{
Component
}
from
"
react
"
;
import
React
from
"
react
"
;
import
PropTypes
from
"
prop-types
"
;
import
autoBind
from
"
auto-bind
"
;
import
classNames
from
"
classnames
"
;
import
Router
,
{
withRouter
}
from
"
next/router
"
;
...
...
@@ -14,20 +13,28 @@ import { Container, Block, ShowMore, Loader } from "@digibib/deichman-ui";
import
"
./styles.css
"
;
class
SearchResults
extends
Component
{
constructor
()
{
super
();
autoBind
(
this
);
}
const
SearchResults
=
props
=>
{
const
{
query
,
initialRender
,
searchQuery
,
results
,
listMode
,
favourites
,
isSearching
,
error
,
onFavourite
,
tracker
,
router
}
=
props
;
handleNextPage
()
{
const
{
query
,
router
}
=
this
.
props
;
const
handleNextPage
=
()
=>
{
const
{
pathname
=
"
/
"
,
asPath
=
"
/
"
}
=
router
;
const
newQueries
=
{
...
query
,
page
:
parseInt
(
query
.
page
||
1
,
10
)
+
1
};
this
.
props
.
tracker
.
loadMore
(
newQueries
.
page
,
this
.
props
.
searchQuery
);
props
.
tracker
.
loadMore
(
newQueries
.
page
,
props
.
searchQuery
);
// Delete searchQuery (should not appear in url as a query param, part of route)
delete
newQueries
.
searchQuery
;
...
...
@@ -41,21 +48,7 @@ class SearchResults extends Component {
query
:
newQueries
}
);
}
render
()
{
const
{
query
,
initialRender
,
searchQuery
,
results
,
listMode
,
favourites
,
isSearching
,
error
,
onFavourite
,
tracker
}
=
this
.
props
;
};
const
{
hits
=
[]
}
=
results
;
const
noHits
=
hits
.
length
<
1
&&
!
isSearching
;
...
...
@@ -89,7 +82,7 @@ class SearchResults extends Component {
// If there's an error
if
(
error
!==
null
)
{
return
<
FullScreen
>
{
error
!==
null
&&
<
p
>
En
feil
har
oppstått
<
/p>}</
FullScreen
>
;
return
<
FullScreen
>
{
<
p
>
En
feil
har
oppstått
<
/p>}</
FullScreen
>
;
}
const
searchQuerySegments
=
getSearchQuerySegments
(
searchQuery
);
...
...
@@ -117,6 +110,7 @@ class SearchResults extends Component {
totalCount
=
{
results
.
totalHits
}
favourites
=
{
favourites
}
onFavourite
=
{
onFavourite
}
showFavorite
/>
<
/Block
>
...
...
@@ -124,7 +118,7 @@ class SearchResults extends Component {
{
canFetchMore
&&
(
<
ShowMore
text
=
"
Hent flere resultater
"
onClick
=
{
this
.
handleNextPage
}
onClick
=
{
handleNextPage
}
disabled
=
{
isSearching
}
/
>
)}
...
...
@@ -132,8 +126,7 @@ class SearchResults extends Component {
<
/Container
>
<
/section
>
);
}
}
};
SearchResults
.
defaultProps
=
{
query
:
{},
...
...
@@ -159,7 +152,7 @@ SearchResults.propTypes = {
export
default
withRouter
(
SearchResults
);
//---- Utils below ----
//
---- Utils below ----
function
getSearchQuerySegments
(
searchQuery
)
{
const
fieldExpression
=
RegExp
(
'
([^:
\\
s]+):
\\
s*"([^"]+)"
'
,
"
g
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment