Skip to content

Commit

Permalink
Merge pull request #213 from ia3andy/comp
Browse files Browse the repository at this point in the history
Fix bug wc loading
  • Loading branch information
marko-bekhta authored Apr 4, 2024
2 parents f75feb9 + 7d2ce5b commit f33f07a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/main/resources/web/app/qs-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class QsForm extends LitElement {
}
const controller = new AbortController();
this._abortController = controller;
this.dispatchEvent(new CustomEvent(QS_START_EVENT));
this.dispatchEvent(new CustomEvent(QS_START_EVENT, { detail: { page: this._page } }));
const data = this._readQueryInputs();
if (this.localSearch) {
this._localSearch();
Expand All @@ -123,15 +123,14 @@ export class QsForm extends LitElement {

this._jsonFetch(controller, 'GET', data, this._page > 0 ? this.initialTimeout : this.moreTimeout)
.then((r: any) => {
let event = QS_RESULT_EVENT;
if (this._page > 0) {
this._currentHitCount += r.hits.length;
} else {
this._currentHitCount = r.hits.length;
}
const total = r.total?.lowerBound;
const hasMoreHits = r.hits.length > 0 && total > this._currentHitCount;
this.dispatchEvent(new CustomEvent(event, {detail: {...r, page: this._page, hasMoreHits}}));
this.dispatchEvent(new CustomEvent(QS_RESULT_EVENT, {detail: {...r, search: data, page: this._page, hasMoreHits}}));
this.dispatchEvent(new CustomEvent(QS_END_EVENT));
}).catch(e => {
console.error('Could not run search: ' + e);
Expand Down Expand Up @@ -211,13 +210,14 @@ export class QsForm extends LitElement {
}

private _localSearch(): any {
let hits = LocalSearch.search(this._readQueryInputs());
let search = this._readQueryInputs();
let hits = LocalSearch.search(search);
if(!!hits) {
const result = {
hits,
total: hits.length
}
this.dispatchEvent(new CustomEvent(QS_RESULT_EVENT, {detail: {...result, page: 0, hasMoreHits: false}}));
this.dispatchEvent(new CustomEvent(QS_RESULT_EVENT, {detail: {...result, search, page: 0, hasMoreHits: false}}));
}
this.dispatchEvent(new CustomEvent(QS_END_EVENT));
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/web/app/qs-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ export class QsTarget extends LitElement {
this._result.hasMoreHits = e.detail.hasMoreHits;
}

private _loadingStart = () => {
private _loadingStart = (e:CustomEvent) => {
this._loading = true;
if(e.detail.page === 0) {
this._result = undefined;
}
}

private _loadingEnd = () => {
Expand Down

0 comments on commit f33f07a

Please sign in to comment.