Skip to content

Commit

Permalink
Update QueryPage.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KWMORALE committed Apr 17, 2020
1 parent fbb3c1d commit d4cc2d5
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/mqueryfront/src/QueryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,10 @@ class QueryPage extends Component {
job: [],
});
this.loadJob();
this.loadMatches();
}

callbackResultsActivePage = (pageNumber) => {
this.setState({activePage: pageNumber},
() => {this.loadMatches()})

}


loadJob() {
const LIMIT = 50;
const LIMIT = 20;

if (!this.state.qhash) {
return;
Expand All @@ -105,7 +97,7 @@ class QueryPage extends Component {
"/matches/" +
this.state.qhash +
"?offset=" +
0 +
1 +
"&limit=" +
LIMIT
)
Expand All @@ -117,18 +109,22 @@ class QueryPage extends Component {
response.data.job.status
) !== -1
) {
if (response.data.job.files_processed >= response.data.job.total_files) {
if (
response.data.job.files_processed >=
response.data.job.total_files
) {
newShouldRequest = false;
}
}

this.setState({
job: response.data.job,
matches: response.data.matches,
});

if (newShouldRequest) {
let nextTimeout =
response.data.matches.length >= LIMIT ? 50 : 1000;
response.data.job.files_matched >= LIMIT ? 20 : 1000;
this.timeout = setTimeout(
() => this.loadJob(),
nextTimeout
Expand All @@ -142,9 +138,15 @@ class QueryPage extends Component {
});
}

callbackResultsActivePage = (pageNumber) => {
this.setState({ activePage: pageNumber }, () => {
this.loadMatches();
});
};

loadMatches() {
const LIMIT = 20;
let OFFSET = (this.state.activePage - 1) * 20 + 1
let OFFSET = (this.state.activePage - 1) * 20 + 1;
axios
.get(
API_URL +
Expand All @@ -159,8 +161,7 @@ class QueryPage extends Component {
this.setState({
matches: response.data.matches,
});

})
});
}

updateQueryError(newError, rawYara) {
Expand Down Expand Up @@ -199,7 +200,7 @@ class QueryPage extends Component {
queryError={this.state.queryError}
/>
);

var queryResults = (
<div>
<button
Expand All @@ -214,7 +215,7 @@ class QueryPage extends Component {
qhash={this.state.qhash}
job={this.state.job}
matches={this.state.matches}
parentCallback = {this.callbackResultsActivePage}
parentCallback={this.callbackResultsActivePage}
/>
</div>
);
Expand Down

0 comments on commit d4cc2d5

Please sign in to comment.