Skip to content
Snippets Groups Projects
Commit 95888f50 authored by cns82's avatar cns82
Browse files

remove auto page

parent 2497181b
Branches
No related tags found
No related merge requests found
...@@ -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}
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment