Make results a reactive var

This commit is contained in:
John R. Supplee 2021-01-24 15:38:44 +02:00
parent 9b6288e49c
commit 91ef8ca1ae
2 changed files with 22 additions and 9 deletions

View file

@ -35,7 +35,7 @@ template(name="globalSearch")
h1
= resultsHeading.get
a.fa.fa-link(title="{{_ 'link-to-search' }}" href="{{ getSearchHref }}")
each card in results
each card in results.get
+resultCard(card)
else
.global-search-instructions

View file

@ -45,6 +45,7 @@ BlazeComponent.extendComponent({
this.myLists = new ReactiveVar([]);
this.myLabelNames = new ReactiveVar([]);
this.myBoardNames = new ReactiveVar([]);
this.results = new ReactiveVar([]);
this.queryParams = null;
this.parsingErrors = [];
this.resultsCount = 0;
@ -85,6 +86,7 @@ BlazeComponent.extendComponent({
resetSearch() {
this.searching.set(false);
this.results.set([]);
this.hasResults.set(false);
this.hasQueryErrors.set(false);
this.resultsHeading.set('');
@ -94,7 +96,7 @@ BlazeComponent.extendComponent({
this.queryErrors = null;
},
results() {
getResults() {
// eslint-disable-next-line no-console
// console.log('getting results');
if (this.queryParams) {
@ -102,6 +104,9 @@ BlazeComponent.extendComponent({
userId: Meteor.userId(),
sessionId: SessionData.getSessionId(),
});
// eslint-disable-next-line no-console
console.log('session data:', sessionData);
const cards = Cards.find({ _id: { $in: sessionData.cards } });
this.queryErrors = sessionData.errorMessages;
// eslint-disable-next-line no-console
@ -120,11 +125,11 @@ BlazeComponent.extendComponent({
this.totalHits = sessionData.totalHits;
this.resultsCount = cards.count();
this.resultsHeading.set(this.getResultsHeading());
return cards;
this.results.set(cards);
}
}
this.resultsCount = 0;
return [];
return null;
},
errorMessages() {
@ -141,6 +146,9 @@ BlazeComponent.extendComponent({
searchAllBoards(query) {
query = query.trim();
// eslint-disable-next-line no-console
console.log('query:', query);
this.query.set(query);
this.resetSearch();
@ -149,9 +157,6 @@ BlazeComponent.extendComponent({
return;
}
// eslint-disable-next-line no-console
// console.log('query:', query);
this.searching.set(true);
if (!this.colorMap) {
@ -195,7 +200,7 @@ BlazeComponent.extendComponent({
});
// eslint-disable-next-line no-console
console.log('operatorMap:', operatorMap);
// console.log('operatorMap:', operatorMap);
const params = {
boards: [],
swimlanes: [],
@ -308,10 +313,17 @@ BlazeComponent.extendComponent({
params.text = text;
// eslint-disable-next-line no-console
// console.log('params:', params);
console.log('params:', params);
this.queryParams = params;
if (this.parsingErrors.length) {
this.searching.set(false);
this.queryErrors = this.errorMessages();
this.hasQueryErrors.set(true);
return;
}
this.autorun(() => {
const handle = subManager.subscribe(
'globalSearch',
@ -323,6 +335,7 @@ BlazeComponent.extendComponent({
// eslint-disable-next-line no-console
// console.log('ready:', handle.ready());
if (handle.ready()) {
this.getResults();
this.searching.set(false);
this.hasResults.set(true);
}