Skip to content
Snippets Groups Projects
Commit 2497181b authored by cns82's avatar cns82
Browse files

force page to 1 when new query is called

parent af80962c
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,7 @@ let SearchEngine = function () { ...@@ -41,6 +41,7 @@ let SearchEngine = function () {
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [prevPage, setPrevPage] = useState(0); const [prevPage, setPrevPage] = useState(0);
const [maxPage, setMaxPage] = useState(0); const [maxPage, setMaxPage] = useState(0);
const [submitted, setSubmitted] = useState(false)
const parseESData = (data) => { const parseESData = (data) => {
...@@ -66,6 +67,11 @@ let SearchEngine = function () { ...@@ -66,6 +67,11 @@ 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)
...@@ -79,6 +85,11 @@ let SearchEngine = function () { ...@@ -79,6 +85,11 @@ let SearchEngine = function () {
} }
const handlePageChange = (e) => { const handlePageChange = (e) => {
if (submitted) {
e.component.pageIndex(0)
setSubmitted(false)
}
let curPage = e.component.pageIndex() let curPage = e.component.pageIndex()
if (curPage < prevPage){ if (curPage < prevPage){
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment