From c0bbae50c42f44b3e6232b3ea07c70bf65bf4ce0 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 11 Jan 2021 00:50:44 -0800 Subject: [PATCH] fix: Search results not updated when changing filters --- app/scenes/Search/Search.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/scenes/Search/Search.js b/app/scenes/Search/Search.js index 876b56aa..6a5cf8a5 100644 --- a/app/scenes/Search/Search.js +++ b/app/scenes/Search/Search.js @@ -1,6 +1,6 @@ // @flow import ArrowKeyNavigation from "boundless-arrow-key-navigation"; -import { debounce } from "lodash"; +import { debounce, isEqual } from "lodash"; import { observable, action } from "mobx"; import { observer, inject } from "mobx-react"; import { PlusIcon } from "outline-icons"; @@ -52,6 +52,7 @@ type Props = { class Search extends React.Component { firstDocument: ?React.Component; lastQuery: string = ""; + lastParams: Object; @observable query: string = decodeURIComponent(this.props.match.params.term || ""); @@ -194,25 +195,28 @@ class Search extends React.Component { @action fetchResults = async () => { if (this.query) { + const params = { + offset: this.offset, + limit: DEFAULT_PAGINATION_LIMIT, + dateFilter: this.dateFilter, + includeArchived: this.includeArchived, + includeDrafts: true, + collectionId: this.collectionId, + userId: this.userId, + }; + // we just requested this thing – no need to try again - if (this.lastQuery === this.query) { + if (this.lastQuery === this.query && isEqual(params, this.lastParams)) { this.isLoading = false; return; } this.isLoading = true; this.lastQuery = this.query; + this.lastParams = params; try { - const results = await this.props.documents.search(this.query, { - offset: this.offset, - limit: DEFAULT_PAGINATION_LIMIT, - dateFilter: this.dateFilter, - includeArchived: this.includeArchived, - includeDrafts: true, - collectionId: this.collectionId, - userId: this.userId, - }); + const results = await this.props.documents.search(this.query, params); this.pinToTop = true;