Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
search-engine-ui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
INFO624 Search Engine Project
search-engine-ui
Commits
95888f50
Commit
95888f50
authored
Mar 25, 2023
by
cns82
Browse files
Options
Downloads
Patches
Plain Diff
remove auto page
parent
2497181b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
search-engine/src/component/search.js
+2
-38
2 additions, 38 deletions
search-engine/src/component/search.js
with
2 additions
and
38 deletions
search-engine/src/component/search.js
+
2
−
38
View file @
95888f50
...
@@ -9,7 +9,7 @@ import TextArea from 'devextreme-react/text-area';
...
@@ -9,7 +9,7 @@ import TextArea from 'devextreme-react/text-area';
const
PAGE_SIZE
=
25
const
PAGE_SIZE
=
25
function
search
(
query
,
startIdx
=
0
,
endIdx
=
PAGE_SIZE
+
1
)
{
function
search
(
query
,
startIdx
=
0
,
endIdx
=
PAGE_SIZE
)
{
const
config
=
{
const
config
=
{
method
:
'
get
'
,
method
:
'
get
'
,
url
:
'
/api/search?q=
'
+
query
+
"
&startIdx=
"
+
startIdx
+
"
&endIdx=
"
+
endIdx
url
:
'
/api/search?q=
'
+
query
+
"
&startIdx=
"
+
startIdx
+
"
&endIdx=
"
+
endIdx
...
@@ -37,11 +37,7 @@ let TextView = function (e) {
...
@@ -37,11 +37,7 @@ let TextView = function (e) {
let
SearchEngine
=
function
()
{
let
SearchEngine
=
function
()
{
const
[
queryResult
,
setQueryResult
]
=
useState
([]);
const
[
queryResult
,
setQueryResult
]
=
useState
([]);
const
[
query
,
setQuery
]
=
useState
(
""
);
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
);
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
);
const
[
prevPage
,
setPrevPage
]
=
useState
(
0
);
const
[
maxPage
,
setMaxPage
]
=
useState
(
0
);
const
[
submitted
,
setSubmitted
]
=
useState
(
false
)
const
parseESData
=
(
data
)
=>
{
const
parseESData
=
(
data
)
=>
{
...
@@ -67,15 +63,10 @@ let SearchEngine = function () {
...
@@ -67,15 +63,10 @@ let SearchEngine = function () {
const
handleSubmit
=
(
e
)
=>
{
const
handleSubmit
=
(
e
)
=>
{
e
.
preventDefault
();
e
.
preventDefault
();
setIsLoading
(
true
)
setIsLoading
(
true
)
setMaxPage
(
0
)
setPrevPage
(
0
)
console
.
log
(
e
)
setSubmitted
(
true
)
//e.component.pageIndex(0)
let
query
=
e
.
target
[
0
].
value
let
query
=
e
.
target
[
0
].
value
search
(
query
).
then
((
res
)
=>
{
search
(
query
).
then
((
res
)
=>
{
let
parsedRes
=
parseESData
(
res
.
data
)
let
parsedRes
=
parseESData
(
res
.
data
)
setQuery
(
query
)
setQueryResult
(
parsedRes
)
setQueryResult
(
parsedRes
)
setIsLoading
(
false
)
setIsLoading
(
false
)
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
...
@@ -84,32 +75,6 @@ let SearchEngine = function () {
...
@@ -84,32 +75,6 @@ let SearchEngine = function () {
})
})
}
}
const
handlePageChange
=
(
e
)
=>
{
if
(
submitted
)
{
e
.
component
.
pageIndex
(
0
)
setSubmitted
(
false
)
}
let
curPage
=
e
.
component
.
pageIndex
()
if
(
curPage
<
prevPage
){
setPrevPage
(
curPage
)
return
}
else
if
(
curPage
>
prevPage
&&
curPage
>
maxPage
){
setIsLoading
(
true
)
search
(
query
,
curPage
*
PAGE_SIZE
+
1
,
((
curPage
+
1
)
*
PAGE_SIZE
)
+
1
).
then
((
res
)
=>
{
let
parsedRes
=
parseESData
(
res
.
data
)
setQueryResult
(
queryResult
.
concat
(
parsedRes
))
setIsLoading
(
false
)
setMaxPage
(
curPage
)
}).
catch
((
error
)
=>
{
console
.
log
(
error
)
setIsLoading
(
false
)
})
setPrevPage
(
curPage
)
}
}
return
(
return
(
<
div
className
=
"
dx-fieldset
"
>
<
div
className
=
"
dx-fieldset
"
>
<
div
>
<
div
>
...
@@ -138,7 +103,6 @@ let SearchEngine = function () {
...
@@ -138,7 +103,6 @@ let SearchEngine = function () {
keyExpr
=
"
id
"
keyExpr
=
"
id
"
showBorders
=
{
false
}
showBorders
=
{
false
}
allowColumnResizing
=
{
true
}
allowColumnResizing
=
{
true
}
onContentReady
=
{
handlePageChange
}
>
>
<
MasterDetail
<
MasterDetail
enabled
=
{
true
}
enabled
=
{
true
}
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment