fix: Search results not updated when changing filters

This commit is contained in:
Tom Moor 2021-01-11 00:50:44 -08:00
parent ac082e4a5f
commit c0bbae50c4

View File

@ -1,6 +1,6 @@
// @flow // @flow
import ArrowKeyNavigation from "boundless-arrow-key-navigation"; import ArrowKeyNavigation from "boundless-arrow-key-navigation";
import { debounce } from "lodash"; import { debounce, isEqual } from "lodash";
import { observable, action } from "mobx"; import { observable, action } from "mobx";
import { observer, inject } from "mobx-react"; import { observer, inject } from "mobx-react";
import { PlusIcon } from "outline-icons"; import { PlusIcon } from "outline-icons";
@ -52,6 +52,7 @@ type Props = {
class Search extends React.Component<Props> { class Search extends React.Component<Props> {
firstDocument: ?React.Component<any>; firstDocument: ?React.Component<any>;
lastQuery: string = ""; lastQuery: string = "";
lastParams: Object;
@observable @observable
query: string = decodeURIComponent(this.props.match.params.term || ""); query: string = decodeURIComponent(this.props.match.params.term || "");
@ -194,25 +195,28 @@ class Search extends React.Component<Props> {
@action @action
fetchResults = async () => { fetchResults = async () => {
if (this.query) { 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 // 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; this.isLoading = false;
return; return;
} }
this.isLoading = true; this.isLoading = true;
this.lastQuery = this.query; this.lastQuery = this.query;
this.lastParams = params;
try { try {
const results = await this.props.documents.search(this.query, { const results = await this.props.documents.search(this.query, params);
offset: this.offset,
limit: DEFAULT_PAGINATION_LIMIT,
dateFilter: this.dateFilter,
includeArchived: this.includeArchived,
includeDrafts: true,
collectionId: this.collectionId,
userId: this.userId,
});
this.pinToTop = true; this.pinToTop = true;