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